summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2019-02-06 21:24:48 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2019-02-07 00:01:11 -0800
commit1900a57e39da08b767549c9bf5f1f9f0066a5d64 (patch)
treed1562ca8d62289e6fa4326d9f5dd1c428229a9e1 /scripts
parentad333cf4a2bda1ff666f2fd0c21634d1d877a566 (diff)
Refactor scripts/download.sh
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/download.sh60
1 files changed, 31 insertions, 29 deletions
diff --git a/scripts/download.sh b/scripts/download.sh
index 3b1e4e5..049caae 100755
--- a/scripts/download.sh
+++ b/scripts/download.sh
@@ -1,39 +1,41 @@
#!/usr/bin/env bash
-
-get_latest_release_version() {
- curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
+# https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
+function get_latest_release {
+ curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
-
-download() {
- archive=gotop_${version}_${1}.tgz
- curl -LO https://github.com/cjbassi/gotop/releases/download/$version/$archive
- tar xf $archive
- rm $archive
+function download {
+ ARCHIVE=gotop_${RELEASE}_${1}.tgz
+ curl -LO https://github.com/cjbassi/gotop/releases/download/${RELEASE}/${ARCHIVE}
+ tar xf ${ARCHIVE}
+ rm ${ARCHIVE}
}
+function main {
+ ARCH=$(uname -sm)
+ RELEASE=$(get_latest_release 'cjbassi/gotop')
-arch=$(uname -sm)
-version=$(get_latest_release_version 'cjbassi/gotop')
+ case "${ARCH}" in
+ # order matters
+ Darwin\ *64) download darwin_amd64 ;;
+ Darwin\ *86) download darwin_386 ;;
+ Linux\ armv5*) download linux_arm5 ;;
+ Linux\ armv6*) download linux_arm6 ;;
+ Linux\ armv7*) download linux_arm7 ;;
+ Linux\ armv8*) download linux_arm8 ;;
+ Linux\ aarch64*) download linux_arm8 ;;
+ Linux\ *64) download linux_amd64 ;;
+ Linux\ *86) download linux_386 ;;
+ *)
+ echo "\
+ No binary found for your system.
+ Feel free to request that we prebuild one that works on your system."
+ exit 1
+ ;;
+ esac
+}
-case "$arch" in
- # order matters
- Darwin\ *64) download darwin_amd64 ;;
- Darwin\ *86) download darwin_386 ;;
- Linux\ armv5*) download linux_arm5 ;;
- Linux\ armv6*) download linux_arm6 ;;
- Linux\ armv7*) download linux_arm7 ;;
- Linux\ armv8*) download linux_arm8 ;;
- Linux\ aarch64*) download linux_arm8 ;;
- Linux\ *64) download linux_amd64 ;;
- Linux\ *86) download linux_386 ;;
- *)
- echo "\
-No binary found for your system.
-Feel free to request that we prebuild one that works on your system."
- exit 1
- ;;
-esac
+main