Files
PowerShell/tools/download.sh
T

103 lines
3.0 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-05-19 11:31:25 -07:00
# Retrieves asset ID and package name of asset ending in argument
# $info looks like: "id": 1698239, "name": "powershell_0.4.0-1_amd64.deb",
get_info() {
2016-08-18 00:05:08 -07:00
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep -B 1 "name.*$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*)
sudo yum install -y curl wget
version=rpm
2016-07-18 10:48:13 -07:00
;;
ubuntu)
sudo apt-get install -y curl wget
case "$VERSION_ID" in
14.04)
2016-08-16 14:15:05 -07:00
version=ubuntu1.14.04.1_amd64.deb
;;
16.04)
2016-08-16 14:15:05 -07:00
version=ubuntu1.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*)
version=pkg
;;
*)
2016-08-19 11:18:00 -07:00
echo "$OSTYPE is not supported!" >&2
exit 2
;;
esac
info=$(get_info $version)
2016-05-19 11:31:25 -07:00
# Parses $info for asset ID and package name
read asset package <<< $(echo $info | sed 's/[,"]//g' | awk '{ print $2; print $4 }')
# Downloads asset to file
packageuri=$(curl -s -i -H 'Accept: application/octet-stream' https://api.github.com/repos/PowerShell/PowerShell/releases/assets/$asset |
grep location | sed 's/location: //g')
curl -C - -s -o $package ${packageuri%$'\r'}
# 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"
sudo apt-get install -y libunwind8 $icupackage
2016-07-18 10:48:13 -07:00
sudo dpkg -i "./$package"
;;
*)
esac
;;
darwin*)
echo "Installing $package with sudo"
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-08-19 11:18:00 -07:00
if [[ $success != 0 ]]; then
echo "ERROR! PowerShell didn't install. Check script output" >&2
exit $success
2016-08-17 11:54:48 -07:00
fi