Skip to content

Commit

Permalink
fix: install script
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Oct 3, 2021
1 parent cbfbc2c commit b5d6e7f
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
#!/bin/sh

set -e

downloadFolder="${HOME}/Downloads"
Expand All @@ -14,6 +15,9 @@ get_arch() {
"i386" | "i486" | "i586")
echo "386"
;;
"aarch64" | "arm64" | "arm")
echo "arm64"
;;
*)
echo ${NIL}
;;
Expand All @@ -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
exit 0

0 comments on commit b5d6e7f

Please sign in to comment.