Files
PowerShell/tools/download.sh
T

121 lines
3.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Let's quit on interrupt of subcommands
trap '
trap - INT # restore default INT handler
echo "Interrupted"
kill -s INT "$$"
' INT
2016-09-02 16:32:06 -07:00
get_url() {
release=v6.0.0-alpha.9
echo "https://github.com/PowerShell/PowerShell/releases/download/$release/$1"
2016-05-19 11:31:25 -07:00
}
# Get OS specific asset ID and package name
case "$OSTYPE" in
linux*)
2016-07-18 10:48:13 -07:00
source /etc/os-release
2016-04-13 15:36:15 -07:00
# Install curl and wget to download package
2016-07-18 10:48:13 -07:00
case "$ID" in
centos*)
2016-09-02 14:44:19 -07:00
if ! hash curl 2>/dev/null; then
echo "curl not found, installing..."
sudo yum install -y curl
fi
2016-09-02 14:44:19 -07:00
2016-09-02 16:32:06 -07:00
package=powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm
2016-07-18 10:48:13 -07:00
;;
ubuntu)
2016-09-02 14:44:19 -07:00
if ! hash curl 2>/dev/null; then
echo "curl not found, installing..."
sudo apt-get install -y curl
fi
case "$VERSION_ID" in
14.04)
2016-09-02 16:32:06 -07:00
package=powershell_6.0.0-alpha.9-1ubuntu1.14.04.1_amd64.deb
;;
16.04)
2016-09-02 16:32:06 -07:00
package=powershell_6.0.0-alpha.9-1ubuntu1.16.04.1_amd64.deb
;;
*)
2016-08-19 11:18:00 -07:00
echo "Ubuntu $VERSION_ID is not supported!" >&2
exit 2
esac
2016-07-18 10:48:13 -07:00
;;
*)
2016-08-19 11:18:00 -07:00
echo "$NAME is not supported!" >&2
exit 2
2016-07-18 10:48:13 -07:00
esac
;;
darwin*)
2016-09-02 14:44:19 -07:00
# We don't check for curl as macOS should have a system version
2016-09-02 16:32:06 -07:00
package=powershell-6.0.0-alpha.9.pkg
;;
*)
2016-08-19 11:18:00 -07:00
echo "$OSTYPE is not supported!" >&2
exit 2
;;
esac
2016-09-02 16:32:06 -07:00
curl -L -o "$package" $(get_url "$package")
2016-09-02 15:19:53 -07:00
if [[ ! -r "$package" ]]; then
echo "ERROR: $package failed to download! Aborting..." >&2
exit 1
fi
# Installs PowerShell package
case "$OSTYPE" in
linux*)
2016-07-18 10:48:13 -07:00
source /etc/os-release
2016-04-13 15:36:15 -07:00
# Install dependencies
2016-07-18 10:48:13 -07:00
case "$ID" in
centos)
echo "Installing libicu, libunwind, and $package with sudo ..."
2016-07-18 10:48:13 -07:00
sudo yum install -y libicu libunwind
sudo yum install "./$package"
;;
ubuntu)
case "$VERSION_ID" in
14.04)
2016-08-16 14:15:05 -07:00
icupackage=libicu52
;;
16.04)
2016-08-16 14:15:05 -07:00
icupackage=libicu55
;;
esac
echo "Installing $libicupackage, libunwind8, and $package with sudo ..."
2016-09-02 14:47:07 -07:00
sudo apt-get install -y libunwind8 "$icupackage"
2016-07-18 10:48:13 -07:00
sudo dpkg -i "./$package"
;;
*)
esac
;;
darwin*)
2016-09-02 14:48:32 -07:00
if hash brew 2>/dev/null; then
if [[ ! -d $(brew --prefix openssl) ]]; then
echo "Installing OpenSSL with brew..."
if ! brew install openssl; then
echo "ERROR: OpenSSL failed to install! Crypto functions will not work..." >&2
# Don't abort because it is not fatal
fi
fi
else
echo "ERROR: brew not found! OpenSSL may not be available..." >&2
# Don't abort because it is not fatal
fi
echo "Installing $package with sudo ..."
2016-09-02 14:47:07 -07:00
sudo installer -pkg "./$package" -target /
;;
esac
2016-08-17 11:54:48 -07:00
powershell -noprofile -c '"Congratulations! PowerShell is installed at $PSHOME"'
2016-08-19 11:18:00 -07:00
success=$?
2016-08-17 11:54:48 -07:00
2016-09-02 14:47:07 -07:00
if [[ "$success" != 0 ]]; then
echo "ERROR: PowerShell failed to install!" >&2
exit "$success"
2016-08-17 11:54:48 -07:00
fi