2019-04-23 04:49:02 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-04-20 19:10:59 +02:00
|
|
|
defaultLocation="/usr/local/bin"
|
|
|
|
defaultVersion="latest"
|
|
|
|
location=${LAB_LOCATION:-$defaultLocation}
|
|
|
|
version=${LAB_VERSION:-$defaultVersion}
|
|
|
|
|
|
|
|
echo "Installing location $location"
|
|
|
|
# Copyright MontFerret Team 2020
|
2020-04-06 23:38:50 +02:00
|
|
|
version=$(curl -sI https://github.com/MontFerret/ferret/releases/latest | grep location | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
|
2020-04-20 19:10:59 +02:00
|
|
|
|
2019-04-23 04:49:02 +02:00
|
|
|
if [ ! $version ]; then
|
|
|
|
echo "Failed while attempting to install ferret-cli. Please manually install:"
|
|
|
|
echo ""
|
|
|
|
echo "1. Open your web browser and go to https://github.com/MontFerret/ferret/releases"
|
|
|
|
echo "2. Download the latest release for your platform."
|
|
|
|
echo "3. chmod +x ./ferret"
|
2020-04-20 19:10:59 +02:00
|
|
|
echo "4. mv ./ferret $location"
|
2019-04-23 04:49:02 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
hasCli() {
|
|
|
|
has=$(which ferret)
|
|
|
|
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
echo
|
|
|
|
echo "You already have the ferret!"
|
2020-04-20 19:10:59 +02:00
|
|
|
export n=5
|
|
|
|
echo "Overwriting in $n seconds... Press Control+C to cancel."
|
2019-04-23 04:49:02 +02:00
|
|
|
echo
|
|
|
|
sleep $n
|
|
|
|
fi
|
|
|
|
|
|
|
|
hasCurl=$(which curl)
|
|
|
|
|
|
|
|
if [ "$?" = "1" ]; then
|
|
|
|
echo "You need curl to use this script."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
hasTar=$(which tar)
|
|
|
|
|
|
|
|
if [ "$?" = "1" ]; then
|
|
|
|
echo "You need tar to use this script."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkHash(){
|
|
|
|
sha_cmd="sha256sum"
|
|
|
|
|
|
|
|
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/ferret_checksums.txt | $sha_cmd -c >/dev/null)
|
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
# rm $targetFile
|
|
|
|
echo "Binary checksum didn't match. Exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
getPackage() {
|
|
|
|
uname=$(uname)
|
|
|
|
userid=$(id -u)
|
|
|
|
|
|
|
|
platform=""
|
|
|
|
case $uname in
|
|
|
|
"Darwin")
|
|
|
|
platform="_darwin"
|
|
|
|
;;
|
|
|
|
"Linux")
|
|
|
|
platform="_linux"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
uname=$(uname -m)
|
|
|
|
arch=""
|
|
|
|
case $uname in
|
|
|
|
"x86_64")
|
|
|
|
arch="_x86_64"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case $uname in
|
|
|
|
"aarch64")
|
|
|
|
arch="_arm64"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-04-20 19:10:59 +02:00
|
|
|
if [ "$arch" = "" ]; then
|
|
|
|
echo "$arch is not supported. Exiting"
|
2019-04-23 04:49:02 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
suffix=$platform$arch
|
|
|
|
targetDir="/tmp/ferret$suffix"
|
2020-04-20 19:10:59 +02:00
|
|
|
|
2019-04-23 04:49:02 +02:00
|
|
|
if [ "$userid" != "0" ]; then
|
|
|
|
targetDir="$(pwd)/ferret$suffix"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $targetDir ]; then
|
|
|
|
mkdir $targetDir
|
|
|
|
fi
|
|
|
|
|
|
|
|
targetFile="$targetDir/ferret"
|
|
|
|
|
|
|
|
if [ -e $targetFile ]; then
|
|
|
|
rm $targetFile
|
|
|
|
fi
|
|
|
|
|
2020-04-20 19:10:59 +02:00
|
|
|
echo
|
|
|
|
|
|
|
|
if [ $location = $defaultLocation ]; then
|
|
|
|
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 $location/ferret"
|
|
|
|
echo " rm -rf $targetDir"
|
|
|
|
echo
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $location ]; then
|
|
|
|
mkdir $location
|
|
|
|
fi
|
|
|
|
|
2019-04-23 04:49:02 +02:00
|
|
|
baseUrl=https://github.com/MontFerret/ferret/releases/download/$version
|
|
|
|
url=$baseUrl/ferret$suffix.tar.gz
|
|
|
|
echo "Downloading package $url as $targetFile"
|
|
|
|
|
|
|
|
curl -sSL $url | tar xz -C $targetDir
|
|
|
|
|
2020-04-20 19:10:59 +02:00
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
echo "Failed to download file"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-04-23 04:49:02 +02:00
|
|
|
|
|
|
|
# checkHash
|
|
|
|
|
|
|
|
chmod +x $targetFile
|
|
|
|
|
|
|
|
echo "Download complete."
|
2020-04-06 23:39:44 +02:00
|
|
|
echo
|
2020-04-20 19:10:59 +02:00
|
|
|
echo "Attempting to move $targetFile to $location"
|
2020-04-06 23:39:44 +02:00
|
|
|
|
2020-04-20 19:10:59 +02:00
|
|
|
mv $targetFile "$location/ferret"
|
2020-04-06 23:39:44 +02:00
|
|
|
|
|
|
|
if [ "$?" = "0" ]; then
|
2020-04-20 19:10:59 +02:00
|
|
|
echo "New version of ferret installed to $location"
|
2020-04-06 23:39:44 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d $targetDir ]; then
|
|
|
|
rm -rf $targetDir
|
|
|
|
fi
|
|
|
|
|
2020-04-20 19:10:59 +02:00
|
|
|
"$location/ferret" --version
|
2019-04-23 04:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hasCli
|
2020-04-20 19:10:59 +02:00
|
|
|
getPackage
|