2023-08-30 12:40:27 +08:00
|
|
|
# Install powershell 7 on macOS, Ubuntu, ArchLinux
|
2023-08-30 08:34:33 +08:00
|
|
|
|
|
|
|
HOST_OS=$(uname)
|
|
|
|
|
|
|
|
myRoot=$(dirname "$0")
|
|
|
|
|
|
|
|
mkdir -p $myRoot/tmp
|
|
|
|
|
2023-08-30 12:40:27 +08:00
|
|
|
pwsh_ver='7.3.6'
|
2023-08-30 08:34:33 +08:00
|
|
|
|
2023-08-30 12:40:27 +08:00
|
|
|
if command -v pwsh >/dev/null ; then
|
|
|
|
pwsh_veri_a=$(pwsh --version)
|
|
|
|
pwsh_veri_b="PowerShell $pwsh_ver"
|
|
|
|
if [[ "$pwsh_veri_b" < "$pwsh_veri_a" || "$pwsh_veri_b" == "$pwsh_veri_a" ]] ; then
|
|
|
|
echo axmol: $pwsh_veri_a already installed.
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Installing PowerShell $pwsh_ver ..."
|
|
|
|
|
2023-08-31 12:38:53 +08:00
|
|
|
HOST_ARCH=$(uname -m)
|
2023-08-30 12:40:27 +08:00
|
|
|
if [ "$HOST_ARCH" = 'x86_64' ] ; then
|
2023-08-31 12:38:53 +08:00
|
|
|
HOST_ARCH=x64
|
2023-08-30 08:34:33 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $HOST_OS = 'Darwin' ] ; then
|
2023-08-30 12:40:27 +08:00
|
|
|
pwsh_pkg="powershell-$pwsh_ver-osx-$HOST_ARCH.pkg"
|
|
|
|
pwsh_pkg_out="$myRoot/tmp/$pwsh_pkg"
|
|
|
|
if [ ! -f "$pwsh_pkg_out" ] ; then
|
|
|
|
curl -L "https://github.com/PowerShell/PowerShell/releases/download/v$pwsh_ver/$pwsh_pkg_name" -o "$pwsh_pkg_out"
|
|
|
|
fi
|
|
|
|
sudo xattr -rd com.apple.quarantine "$pwsh_pkg_out"
|
|
|
|
sudo installer -pkg "$pwsh_pkg_out" -target /
|
2023-08-30 08:34:33 +08:00
|
|
|
elif [ $HOST_OS = 'Linux' ] ; then
|
2023-08-30 12:40:27 +08:00
|
|
|
if which dpkg > /dev/null; then # Linux distro: deb (ubuntu)
|
|
|
|
pwsh_pkg="powershell_$pwsh_ver-1.deb_amd64.deb"
|
|
|
|
pwsh_pkg_out="$myRoot/tmp/$pwsh_pkg"
|
|
|
|
if [ ! -f "$pwsh_pkg_out" ] ; then
|
|
|
|
curl -L "https://github.com/PowerShell/PowerShell/releases/download/v$pwsh_ver/$pwsh_pkg" -o "$pwsh_pkg_out"
|
|
|
|
fi
|
|
|
|
sudo dpkg -i "$pwsh_pkg_out"
|
|
|
|
sudo apt-get install -f
|
|
|
|
elif which pacman > /dev/null; then # Linux distro: Arch
|
|
|
|
# refer: https://ephos.github.io/posts/2018-9-17-Pwsh-ArchLinux
|
2023-08-30 15:35:29 +08:00
|
|
|
git clone https://aur.archlinux.org/powershell-bin.git $myRoot/tmp/powershell-bin
|
|
|
|
cd $myRoot/tmp/powershell-bin
|
2023-08-31 12:40:45 +08:00
|
|
|
makepkg -si --needed --noconfirm
|
2023-08-30 12:40:27 +08:00
|
|
|
cd -
|
|
|
|
fi
|
2023-08-30 08:34:33 +08:00
|
|
|
else
|
|
|
|
echo "Unsupported HOST OS: $HOST_OS"
|
2023-08-30 12:40:27 +08:00
|
|
|
exit 1
|
2023-08-30 08:34:33 +08:00
|
|
|
fi
|
2023-08-30 12:40:27 +08:00
|
|
|
|
|
|
|
echo "Installing PowerShell $pwsh_ver done"
|