From bbe0dafb93312462a176f2c646b01f9a5b844fa7 Mon Sep 17 00:00:00 2001 From: Eris Belew Date: Sat, 20 Aug 2016 12:22:58 -0700 Subject: [PATCH 1/2] download.sh: Trap interrupt; Add sudo prompt info; Remove wget requirement Add interrupt handler so entire script exits if user hits ctrl-c on sub-command Add info before prompting for password using sudo Remove wget requirement since OSX does not have wget in default system Add `-C -` to curl package download to continue or skip existing packages --- tools/download.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/download.sh b/tools/download.sh index c705678e13..aed1980d10 100755 --- a/tools/download.sh +++ b/tools/download.sh @@ -1,5 +1,12 @@ #!/usr/bin/env bash +# Let's quit on interrupt of subcommands +trap ' + trap - INT # restore default INT handler + echo "Interrupted" + kill -s INT "$$" +' INT + # 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() { @@ -50,8 +57,9 @@ info=$(get_info $version) read asset package <<< $(echo $info | sed 's/[,"]//g' | awk '{ print $2; print $4 }') # Downloads asset to file -curl -s -i -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 +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 @@ -60,6 +68,7 @@ case "$OSTYPE" in # Install dependencies case "$ID" in centos) + echo "Installing libicu, libunwind, and $package with sudo" sudo yum install -y libicu libunwind sudo yum install "./$package" ;; @@ -72,6 +81,7 @@ case "$OSTYPE" in icupackage=libicu55 ;; esac + echo "Installing $libicupackage, libunwind8, and $package with sudo" sudo apt-get install -y libunwind8 $icupackage sudo dpkg -i "./$package" ;; @@ -79,6 +89,7 @@ case "$OSTYPE" in esac ;; darwin*) + echo "Installing $package with sudo" sudo installer -pkg ./$package -target / ;; esac From 6a2911faa2838d9734cba9b460892ee5b0ce1618 Mon Sep 17 00:00:00 2001 From: Eris Belew Date: Sun, 21 Aug 2016 11:27:49 -0700 Subject: [PATCH 2/2] Remove wget installation; Move curl installation after version check --- tools/download.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/download.sh b/tools/download.sh index aed1980d10..fb3e6831e6 100755 --- a/tools/download.sh +++ b/tools/download.sh @@ -20,11 +20,13 @@ case "$OSTYPE" in # Install curl and wget to download package case "$ID" in centos*) - sudo yum install -y curl wget + if [[ -z $(command -v curl) ]]; then + echo "curl not found, installing..." + sudo yum install -y curl + fi version=rpm ;; ubuntu) - sudo apt-get install -y curl wget case "$VERSION_ID" in 14.04) version=ubuntu1.14.04.1_amd64.deb @@ -36,6 +38,10 @@ case "$OSTYPE" in echo "Ubuntu $VERSION_ID is not supported!" >&2 exit 2 esac + if [[ -z $(command -v curl) ]]; then + echo "curl not found, installing..." + sudo apt-get install -y curl + fi ;; *) echo "$NAME is not supported!" >&2 @@ -68,7 +74,7 @@ case "$OSTYPE" in # Install dependencies case "$ID" in centos) - echo "Installing libicu, libunwind, and $package with sudo" + echo "Installing libicu, libunwind, and $package with sudo ..." sudo yum install -y libicu libunwind sudo yum install "./$package" ;; @@ -81,7 +87,7 @@ case "$OSTYPE" in icupackage=libicu55 ;; esac - echo "Installing $libicupackage, libunwind8, and $package with sudo" + echo "Installing $libicupackage, libunwind8, and $package with sudo ..." sudo apt-get install -y libunwind8 $icupackage sudo dpkg -i "./$package" ;; @@ -89,7 +95,7 @@ case "$OSTYPE" in esac ;; darwin*) - echo "Installing $package with sudo" + echo "Installing $package with sudo ..." sudo installer -pkg ./$package -target / ;; esac