Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 65 additions & 76 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

# Copyright Tim Voronov 2020
version=$(curl -sI https://github.com/go-waitfor/cli/releases/latest | grep Location | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
if [ ! $version ]; then
echo "Failed while attempting to install waitfor. Please manually install:"
echo ""
echo "1. Open your web browser and go to https://github.com/go-waitfor/cli/releases"
echo "2. Download the latest release for your platform."
echo "3. chmod +x ./waitfor"
echo "4. mv ./waitfor /usr/local/bin"
exit 1
if [ ! "$version" ]; then
echo "Unable to detect latest version, falling back to 'latest'"
version="latest"
fi

hasCli() {
has=$(which waitfor)

if [ "$?" = "0" ]; then
if which waitfor >/dev/null 2>&1; then
echo
echo "You already have waitfor!"
export n=3
Expand All @@ -24,16 +17,12 @@ hasCli() {
sleep $n
fi

hasCurl=$(which curl)

if [ "$?" = "1" ]; then
if ! which curl >/dev/null 2>&1; then
echo "You need curl to use this script."
exit 1
fi

hasTar=$(which tar)

if [ "$?" = "1" ]; then
if ! which tar >/dev/null 2>&1; then
echo "You need tar to use this script."
exit 1
fi
Expand All @@ -42,15 +31,12 @@ hasCli() {
checkHash(){
sha_cmd="sha256sum"

if [ ! -x "$(command -v $sha_cmd)" ]; then
if [ ! -x "$(command -v "$sha_cmd")" ]; then
sha_cmd="shasum -a 256"
fi

if [ -x "$(command -v $sha_cmd)" ]; then

(cd $targetDir && curl -sSL $baseUrl/waitfor_checksums.txt | $sha_cmd -c >/dev/null)
if [ "$?" != "0" ]; then
# rm $targetFile
if [ -x "$(command -v "$sha_cmd")" ]; then
if ! (cd "$targetDir" && curl -sSL "$baseUrl"/checksums.txt | "$sha_cmd" -c >/dev/null); then
echo "Binary checksum didn't match. Exiting"
exit 1
fi
Expand All @@ -64,30 +50,31 @@ getPackage() {
platform=""
case $uname in
"Darwin")
platform="_darwin"
;;
platform="_darwin"
;;
"Linux")
platform="_linux"
;;
platform="_linux"
;;
*)
echo "Platform $uname is not supported. Exiting"
exit 1
;;
esac

uname=$(uname -m)
uname_arch=$(uname -m)
arch=""
case $uname in
case $uname_arch in
"x86_64")
arch="_x86_64"
;;
esac
case $uname in
"aarch64")
arch="_arm64"
;;
esac

if [ "$arch" == "" ]; then
echo "${$arch} is not supported. Exiting"
arch="_amd64"
;;
"aarch64"|"arm64")
arch="_arm64"
;;
*)
echo "Architecture $uname_arch is not supported. Exiting"
exit 1
fi
;;
esac

suffix=$platform$arch
targetDir="/tmp/waitfor$suffix"
Expand All @@ -96,56 +83,58 @@ getPackage() {
targetDir="$(pwd)/waitfor$suffix"
fi

if [ ! -d $targetDir ]; then
mkdir $targetDir
if [ ! -d "$targetDir" ]; then
mkdir "$targetDir"
fi

targetFile="$targetDir/waitfor"

if [ -e $targetFile ]; then
rm $targetFile
if [ -e "$targetFile" ]; then
rm "$targetFile"
fi

baseUrl=https://github.com/go-waitfor/cli/releases/download/$version
if [ "$version" = "latest" ]; then
baseUrl=https://github.com/go-waitfor/cli/releases/latest/download
else
baseUrl=https://github.com/go-waitfor/cli/releases/download/$version
fi
url=$baseUrl/waitfor$suffix.tar.gz
echo "Downloading package $url as $targetFile"

curl -sSL $url | tar xz -C $targetDir

if [ "$?" = "0" ]; then
if ! curl -sSL "$url" | tar xz -C "$targetDir"; then
echo "Failed to download or extract package"
exit 1
fi

# checkHash
checkHash

chmod +x $targetFile
chmod +x "$targetFile"

echo "Download complete."

if [ "$userid" != "0" ]; then
echo
echo "========================================================="
echo "== As the script was run as a non-root user the =="
echo "== following commands may need to be run manually =="
echo "========================================================="
echo
echo " sudo cp $targetFile /usr/local/bin/waitfor"
echo " rm -rf $targetDir"
echo
else
echo
echo "Running as root - Attempting to move $targetFile to /usr/local/bin"

mv $targetFile /usr/local/bin/waitfor

if [ "$?" = "0" ]; then
echo "New version of waitfor installed to /usr/local/bin"
fi

if [ -d $targetDir ]; then
rm -rf $targetDir
fi

waitfor version
if [ "$userid" != "0" ]; then
echo
echo "========================================================="
echo "== As the script was run as a non-root user the =="
echo "== following commands may need to be run manually =="
echo "========================================================="
echo
echo " sudo cp \"$targetFile\" /usr/local/bin/waitfor"
echo " rm -rf \"$targetDir\""
echo
else
echo
echo "Running as root - Attempting to move \"$targetFile\" to /usr/local/bin"

if mv "$targetFile" /usr/local/bin/waitfor; then
echo "New version of waitfor installed to /usr/local/bin"
fi

if [ -d "$targetDir" ]; then
rm -rf "$targetDir"
fi

waitfor version
fi
}

Expand Down