2016-03-17 19:49:48 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2016-08-20 21:22:58 +02:00
|
|
|
# Let's quit on interrupt of subcommands
|
|
|
|
trap '
|
|
|
|
trap - INT # restore default INT handler
|
|
|
|
echo "Interrupted"
|
|
|
|
kill -s INT "$$"
|
|
|
|
' INT
|
|
|
|
|
2016-09-03 01:32:06 +02:00
|
|
|
get_url() {
|
2016-09-15 22:52:53 +02:00
|
|
|
release=v6.0.0-alpha.10
|
2016-09-03 01:32:06 +02:00
|
|
|
echo "https://github.com/PowerShell/PowerShell/releases/download/$release/$1"
|
2016-05-19 20:31:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get OS specific asset ID and package name
|
2016-04-14 00:03:41 +02:00
|
|
|
case "$OSTYPE" in
|
|
|
|
linux*)
|
2016-07-18 19:48:13 +02:00
|
|
|
source /etc/os-release
|
2016-04-14 00:36:15 +02:00
|
|
|
# Install curl and wget to download package
|
2016-07-18 19:48:13 +02:00
|
|
|
case "$ID" in
|
|
|
|
centos*)
|
2016-09-02 23:44:19 +02:00
|
|
|
if ! hash curl 2>/dev/null; then
|
2016-08-21 20:27:49 +02:00
|
|
|
echo "curl not found, installing..."
|
|
|
|
sudo yum install -y curl
|
|
|
|
fi
|
2016-09-02 23:44:19 +02:00
|
|
|
|
2016-09-15 22:52:53 +02:00
|
|
|
package=powershell-6.0.0_alpha.10-1.el7.centos.x86_64.rpm
|
2016-07-18 19:48:13 +02:00
|
|
|
;;
|
|
|
|
ubuntu)
|
2016-09-02 23:44:19 +02:00
|
|
|
if ! hash curl 2>/dev/null; then
|
|
|
|
echo "curl not found, installing..."
|
|
|
|
sudo apt-get install -y curl
|
|
|
|
fi
|
|
|
|
|
2016-08-16 03:35:40 +02:00
|
|
|
case "$VERSION_ID" in
|
|
|
|
14.04)
|
2016-09-15 22:52:53 +02:00
|
|
|
package=powershell_6.0.0-alpha.10-1ubuntu1.14.04.1_amd64.deb
|
2016-08-16 03:35:40 +02:00
|
|
|
;;
|
|
|
|
16.04)
|
2016-09-15 22:52:53 +02:00
|
|
|
package=powershell_6.0.0-alpha.10-1ubuntu1.16.04.1_amd64.deb
|
2016-08-16 03:35:40 +02:00
|
|
|
;;
|
|
|
|
*)
|
2016-08-19 20:18:00 +02:00
|
|
|
echo "Ubuntu $VERSION_ID is not supported!" >&2
|
|
|
|
exit 2
|
2016-08-16 03:35:40 +02:00
|
|
|
esac
|
2016-07-18 19:48:13 +02:00
|
|
|
;;
|
|
|
|
*)
|
2016-08-19 20:18:00 +02:00
|
|
|
echo "$NAME is not supported!" >&2
|
|
|
|
exit 2
|
2016-07-18 19:48:13 +02:00
|
|
|
esac
|
2016-04-14 00:03:41 +02:00
|
|
|
;;
|
|
|
|
darwin*)
|
2016-09-02 23:44:19 +02:00
|
|
|
# We don't check for curl as macOS should have a system version
|
2016-09-15 22:52:53 +02:00
|
|
|
package=powershell-6.0.0-alpha.10.pkg
|
2016-04-14 00:03:41 +02:00
|
|
|
;;
|
|
|
|
*)
|
2016-08-19 20:18:00 +02:00
|
|
|
echo "$OSTYPE is not supported!" >&2
|
|
|
|
exit 2
|
2016-04-14 00:03:41 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2016-09-03 01:32:06 +02:00
|
|
|
curl -L -o "$package" $(get_url "$package")
|
2016-04-14 00:03:41 +02:00
|
|
|
|
2016-09-03 00:19:53 +02:00
|
|
|
if [[ ! -r "$package" ]]; then
|
|
|
|
echo "ERROR: $package failed to download! Aborting..." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-04-14 00:03:41 +02:00
|
|
|
# Installs PowerShell package
|
|
|
|
case "$OSTYPE" in
|
|
|
|
linux*)
|
2016-07-18 19:48:13 +02:00
|
|
|
source /etc/os-release
|
2016-04-14 00:36:15 +02:00
|
|
|
# Install dependencies
|
2016-09-20 01:34:12 +02:00
|
|
|
echo "Installing PowerShell with sudo..."
|
2016-07-18 19:48:13 +02:00
|
|
|
case "$ID" in
|
|
|
|
centos)
|
2016-09-20 01:34:12 +02:00
|
|
|
# yum automatically resolves dependencies for local packages
|
2016-07-18 19:48:13 +02:00
|
|
|
sudo yum install "./$package"
|
|
|
|
;;
|
|
|
|
ubuntu)
|
2016-09-20 01:34:12 +02:00
|
|
|
# dpkg does not automatically resolve dependencies, but spouts ugly errors
|
|
|
|
sudo dpkg -i "./$package" &> /dev/null
|
|
|
|
# Resolve dependencies
|
|
|
|
sudo apt-get install -f
|
2016-07-18 19:48:13 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
esac
|
2016-04-14 00:03:41 +02:00
|
|
|
;;
|
|
|
|
darwin*)
|
2016-09-20 23:26:07 +02:00
|
|
|
patched=0
|
2016-09-02 23:48:32 +02: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
|
2016-09-20 23:26:07 +02:00
|
|
|
elif ! brew install curl --with-openssl; then
|
|
|
|
echo "ERROR: curl failed to build against OpenSSL; SSL functions will not work..." >&2
|
|
|
|
# Still not fatal
|
|
|
|
else
|
|
|
|
# OpenSSL installation succeeded; remember to patch System.Net.Http after PowerShell installation
|
|
|
|
patched=1
|
2016-09-02 23:48:32 +02:00
|
|
|
fi
|
|
|
|
fi
|
2016-09-20 23:26:07 +02:00
|
|
|
|
2016-09-02 23:48:32 +02:00
|
|
|
else
|
|
|
|
echo "ERROR: brew not found! OpenSSL may not be available..." >&2
|
|
|
|
# Don't abort because it is not fatal
|
|
|
|
fi
|
|
|
|
|
2016-08-21 20:27:49 +02:00
|
|
|
echo "Installing $package with sudo ..."
|
2016-09-02 23:47:07 +02:00
|
|
|
sudo installer -pkg "./$package" -target /
|
2016-09-20 23:26:07 +02:00
|
|
|
if [[ $patched -eq 1 ]]; then
|
|
|
|
echo "Patching System.Net.Http for libcurl and OpenSSL..."
|
|
|
|
find /usr/local/microsoft/powershell -name System.Net.Http.Native.dylib | xargs sudo install_name_tool -change /usr/lib/libcurl.4.dylib /usr/local/opt/curl/lib/libcurl.4.dylib
|
|
|
|
fi
|
2016-04-14 00:03:41 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2016-08-17 20:54:48 +02:00
|
|
|
powershell -noprofile -c '"Congratulations! PowerShell is installed at $PSHOME"'
|
2016-08-19 20:18:00 +02:00
|
|
|
success=$?
|
2016-08-17 20:54:48 +02:00
|
|
|
|
2016-09-02 23:47:07 +02:00
|
|
|
if [[ "$success" != 0 ]]; then
|
|
|
|
echo "ERROR: PowerShell failed to install!" >&2
|
|
|
|
exit "$success"
|
2016-08-17 20:54:48 +02:00
|
|
|
fi
|