Skip to content

Commit 77572d1

Browse files
committed
Improve 1k/install-pwsh.sh
1 parent b4f83f4 commit 77572d1

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

1k/install-pwsh.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,31 @@ mkdir -p $cacheDir
1212

1313
pwsh_ver=$1
1414
if [ "$pwsh_ver" = "" ] ; then
15-
pwsh_ver='7.4.2'
15+
pwsh_ver='7.4.4'
16+
fi
17+
18+
pwsh_min_ver=$2
19+
if [ "$pwsh_min_ver" = "" ] ; then
20+
pwsh_min_ver='7.3.0'
21+
fi
22+
23+
if [[ "$pwsh_ver" < "$pwsh_min_ver" ]] ; then
24+
pwsh_ver=$pwsh_min_ver
1625
fi
1726

1827
function check_pwsh {
19-
pwsh_ver=$1
28+
min_ver=$1
29+
preferred_ver=$2
2030
if command -v pwsh >/dev/null ; then
21-
pwsh_veri_a=$(pwsh --version)
22-
pwsh_veri_b="PowerShell $pwsh_ver"
23-
if [ "$pwsh_veri_b" = "$pwsh_veri_a" ] ; then
24-
echo axmol: $pwsh_veri_a already installed.
31+
verx=$(pwsh --version)
32+
very="PowerShell $min_ver"
33+
if ([ "$preferred_ver" != "$min_ver" ] && ([[ "$verx" > "$very" ]] || [ "$verx" = "$very" ])) \
34+
|| ([ "$preferred_ver" = "$min_ver" ] && [ "$verx" = "$very" ]) ; then
35+
echo "1kiss: $verx installed."
2536
exit 0
2637
fi
2738
fi
28-
echo "Installing PowerShell $pwsh_ver ..."
39+
echo "Installing PowerShell $preferred_ver ..."
2940
}
3041

3142
HOST_ARCH=$(uname -m)
@@ -34,7 +45,7 @@ if [ "$HOST_ARCH" = 'x86_64' ] ; then
3445
fi
3546

3647
if [ $HOST_OS = 'Darwin' ] ; then
37-
check_pwsh $pwsh_ver
48+
check_pwsh $pwsh_min_ver $preferred_ver
3849
pwsh_pkg="powershell-$pwsh_ver-osx-$HOST_ARCH.pkg"
3950
pwsh_pkg_out="$cacheDir/$pwsh_pkg"
4051
if [ ! -f "$pwsh_pkg_out" ] ; then
@@ -45,8 +56,8 @@ if [ $HOST_OS = 'Darwin' ] ; then
4556
sudo xattr -rd com.apple.quarantine "$pwsh_pkg_out"
4657
sudo installer -pkg "$pwsh_pkg_out" -target /
4758
elif [ $HOST_OS = 'Linux' ] ; then
48-
if which dpkg > /dev/null; then # Linux distro: deb (ubuntu)
49-
check_pwsh $pwsh_ver
59+
if command -v dpkg > /dev/null; then # Linux distro: deb (ubuntu)
60+
check_pwsh $pwsh_min_ver $preferred_ver
5061
pwsh_pkg="powershell_$pwsh_ver-1.deb_amd64.deb"
5162
pwsh_pkg_out="$cacheDir/$pwsh_pkg"
5263
if [ ! -f "$pwsh_pkg_out" ] ; then
@@ -55,10 +66,10 @@ elif [ $HOST_OS = 'Linux' ] ; then
5566
sudo_cmd=$(which sudo)
5667
$sudo_cmd dpkg -i "$pwsh_pkg_out"
5768
$sudo_cmd apt-get install -f
58-
elif which pacman > /dev/null; then # Linux distro: Arch
69+
elif command -v pacman > /dev/null; then # Linux distro: Arch
5970
# refer: https://ephos.github.io/posts/2018-9-17-Pwsh-ArchLinux
6071
# available pwsh version, refer to: https://aur.archlinux.org/packages/powershell-bin
61-
check_pwsh $pwsh_ver
72+
check_pwsh $pwsh_min_ver
6273
git clone https://aur.archlinux.org/powershell-bin.git $cacheDir/powershell-bin
6374
cd $cacheDir/powershell-bin
6475
makepkg -si --needed --noconfirm
@@ -69,10 +80,11 @@ else
6980
exit 1
7081
fi
7182

72-
if [ $? = 0 ] ; then
73-
echo "Install PowerShell $pwsh_ver done"
83+
if command -v pwsh >/dev/null ; then
84+
installed_pwsh_ver=$(pwsh --version)
85+
echo "Install PowerShell $installed_pwsh_ver succeed."
7486
else
75-
echo "Install PowerShell fail"
87+
echo "Install PowerShell fail, try again"
7688
if [ -f "$pwsh_pkg_out" ] ; then
7789
rm -f "$pwsh_pkg_out"
7890
fi

0 commit comments

Comments
 (0)