From b5d6e7f52fc6c21414b6a2de63b394082194d9ba Mon Sep 17 00:00:00 2001 From: Axetroy Date: Sun, 3 Oct 2021 21:30:30 +0800 Subject: [PATCH] fix: install script --- install.sh | 79 +++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/install.sh b/install.sh index 5d71e5e0..086f4f15 100644 --- a/install.sh +++ b/install.sh @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#!/bin/sh + set -e downloadFolder="${HOME}/Downloads" @@ -14,6 +15,9 @@ get_arch() { "i386" | "i486" | "i586") echo "386" ;; + "aarch64" | "arm64" | "arm") + echo "arm64" + ;; *) echo ${NIL} ;; @@ -24,49 +28,44 @@ get_os(){ echo $(uname -s | awk '{print tolower($0)}') } -main() { - local os=$(get_os) - local arch=$(get_arch) - local dest_file="${downloadFolder}/whatchanged_${os}_${arch}.tar.gz" - - if [[ $# -eq 0 ]]; then - asset_path=$( - command curl -sSf https://github.com/whatchanged-community/whatchanged/releases | - command grep -o "/whatchanged-community/whatchanged/releases/download/.*/whatchanged_${os}_${arch}\\.tar.gz" | - command head -n 1 - ) - if [[ ! "$asset_path" ]]; then exit 1; fi - asset_uri="https://github.com${asset_path}" - else - asset_uri="https://github.com/whatchanged-community/whatchanged/releases/download/${1}/whatchanged_${os}_${arch}\\.tar.gz" - fi +os=$(get_os) +arch=$(get_arch) +dest_file="${downloadFolder}/whatchanged_${os}_${arch}.tar.gz" - mkdir -p ${downloadFolder} +if [ $# -eq 0 ]; then + asset_path=$( + command curl -sSf https://github.com/whatchanged-community/whatchanged/releases | + command grep -o "/whatchanged-community/whatchanged/releases/download/.*/whatchanged_${os}_${arch}\\.tar.gz" | + command head -n 1 + ) + if [[ ! "$asset_path" ]]; then exit 1; fi + asset_uri="https://github.com${asset_path}" +else + asset_uri="https://github.com/whatchanged-community/whatchanged/releases/download/${1}/whatchanged_${os}_${arch}\\.tar.gz" +fi - echo "[1/3] Download ${asset_uri} to ${downloadFolder}" - rm -f ${dest_file} - # wget -P "${downloadFolder}" "${asset_uri}" - curl --location --output "${dest_file}" "${asset_uri}" +mkdir -p ${downloadFolder} - binDir=/usr/local/bin +echo "[1/3] Download ${asset_uri} to ${downloadFolder}" +rm -f ${dest_file} +curl --location --output "${dest_file}" "${asset_uri}" - echo "[2/3] Install whatchanged to the ${binDir}" - mkdir -p ${HOME}/bin - tar -xz -f ${dest_file} -C ${binDir} - exe=${binDir}/whatchanged - chmod +x ${exe} +binDir=/usr/local/bin - echo "[3/3] Set environment variables" - echo "whatchanged was installed successfully to ${exe}" - if command -v whatchanged --version >/dev/null; then - echo "Run 'whatchanged --help' to get started" - else - echo "Manually add the directory to your \$HOME/.bash_profile (or similar)" - echo " export PATH=${HOME}/bin:\$PATH" - echo "Run '$exe --help' to get started" - fi +echo "[2/3] Install whatchanged to the ${binDir}" +mkdir -p ${HOME}/bin +tar -xz -f ${dest_file} -C ${binDir} +exe=${binDir}/whatchanged +chmod +x ${exe} - exit 0 -} +echo "[3/3] Set environment variables" +echo "whatchanged was installed successfully to ${exe}" +if command -v whatchanged --version >/dev/null; then + echo "Run 'whatchanged --help' to get started" +else + echo "Manually add the directory to your \$HOME/.bash_profile (or similar)" + echo " export PATH=${HOME}/bin:\$PATH" + echo "Run '$exe --help' to get started" +fi -main \ No newline at end of file +exit 0 \ No newline at end of file