2016-03-17 11:49:48 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2016-07-21 10:51:59 -07:00
|
|
|
GITHUB_TOKEN=a27573e27bea23fb05393ead69511b09e3b224be
|
2016-03-17 11:49:48 -07:00
|
|
|
|
2016-05-19 11:31:25 -07:00
|
|
|
# Authorizes with read-only access to GitHub API
|
|
|
|
|
curl_() {
|
|
|
|
|
curl -s -i -H "Authorization: token $GITHUB_TOKEN" "$@"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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() {
|
|
|
|
|
curl_ https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep -B 1 "name.*$1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Get OS specific asset ID and package name
|
2016-04-13 15:03:41 -07:00
|
|
|
case "$OSTYPE" in
|
|
|
|
|
linux*)
|
2016-07-18 10:48:13 -07:00
|
|
|
source /etc/os-release
|
|
|
|
|
echo $ID
|
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
|
2016-08-15 18:35:40 -07:00
|
|
|
version=rpm
|
2016-07-18 10:48:13 -07:00
|
|
|
;;
|
|
|
|
|
ubuntu)
|
|
|
|
|
sudo apt-get install -y curl wget
|
2016-08-15 18:35:40 -07:00
|
|
|
case "$VERSION_ID" in
|
|
|
|
|
14.04)
|
|
|
|
|
version=ubuntu.14.04-x64.deb
|
|
|
|
|
;;
|
|
|
|
|
16.04)
|
|
|
|
|
version=ubuntu.16.04-x64.deb
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
exit 2 >&2 "Ubuntu $VERSION_ID is not supported!"
|
|
|
|
|
esac
|
2016-07-18 10:48:13 -07:00
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
exit 2 >&2 "$NAME is not supported!"
|
|
|
|
|
esac
|
2016-04-13 15:03:41 -07:00
|
|
|
;;
|
|
|
|
|
darwin*)
|
2016-08-15 18:35:40 -07:00
|
|
|
version=pkg
|
2016-04-13 15:03:41 -07:00
|
|
|
;;
|
|
|
|
|
*)
|
2016-07-18 10:48:13 -07:00
|
|
|
exit 2 >&2 "$OSTYPE is not supported!"
|
2016-04-13 15:03:41 -07:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2016-08-15 18:35:40 -07:00
|
|
|
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
|
|
|
|
|
curl_ -H 'Accept: application/octet-stream' https://api.github.com/repos/PowerShell/PowerShell/releases/assets/$asset |
|
|
|
|
|
grep location | sed 's/location: //g' | wget -i - -O $package
|
2016-04-13 15:03:41 -07:00
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
sudo yum install -y libicu libunwind
|
|
|
|
|
sudo yum install "./$package"
|
|
|
|
|
;;
|
|
|
|
|
ubuntu)
|
2016-08-15 18:35:40 -07:00
|
|
|
case "$VERSION_ID" in
|
|
|
|
|
14.04)
|
|
|
|
|
$icupackage=libicu52
|
|
|
|
|
;;
|
|
|
|
|
16.04)
|
|
|
|
|
$icupackage=libicu55
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
sudo apt-get install -y libunwind8 $icupackage
|
2016-07-18 10:48:13 -07:00
|
|
|
sudo dpkg -i "./$package"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
esac
|
2016-04-13 15:03:41 -07:00
|
|
|
;;
|
|
|
|
|
darwin*)
|
|
|
|
|
sudo installer -pkg ./$package -target /
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
echo "Congratulations! PowerShell is now installed."
|