1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-11-23 21:54:45 +02:00

Updated install.sh

This commit is contained in:
Tim Voronov
2020-04-20 13:10:59 -04:00
parent 84e74a0552
commit aaa7228f3a

View File

@@ -1,14 +1,21 @@
#!/bin/bash #!/bin/bash
# Copyright Ferret Author(s) 2019 defaultLocation="/usr/local/bin"
defaultVersion="latest"
location=${LAB_LOCATION:-$defaultLocation}
version=${LAB_VERSION:-$defaultVersion}
echo "Installing location $location"
# Copyright MontFerret Team 2020
version=$(curl -sI https://github.com/MontFerret/ferret/releases/latest | grep location | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r') version=$(curl -sI https://github.com/MontFerret/ferret/releases/latest | grep location | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
if [ ! $version ]; then if [ ! $version ]; then
echo "Failed while attempting to install ferret-cli. Please manually install:" echo "Failed while attempting to install ferret-cli. Please manually install:"
echo "" echo ""
echo "1. Open your web browser and go to https://github.com/MontFerret/ferret/releases" 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 "2. Download the latest release for your platform."
echo "3. chmod +x ./ferret" echo "3. chmod +x ./ferret"
echo "4. mv ./ferret /usr/local/bin" echo "4. mv ./ferret $location"
exit 1 exit 1
fi fi
@@ -18,8 +25,8 @@ hasCli() {
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
echo echo
echo "You already have the ferret!" echo "You already have the ferret!"
export n=3 export n=5
echo "Overwriting in $n seconds.. Press Control+C to cancel." echo "Overwriting in $n seconds... Press Control+C to cancel."
echo echo
sleep $n sleep $n
fi fi
@@ -84,14 +91,14 @@ getPackage() {
;; ;;
esac esac
if [ "$arch" == "" ]; then if [ "$arch" = "" ]; then
echo "${$arch} is not supported. Exiting" echo "$arch is not supported. Exiting"
exit 1 exit 1
fi fi
suffix=$platform$arch suffix=$platform$arch
targetDir="/tmp/ferret$suffix" targetDir="/tmp/ferret$suffix"
if [ "$userid" != "0" ]; then if [ "$userid" != "0" ]; then
targetDir="$(pwd)/ferret$suffix" targetDir="$(pwd)/ferret$suffix"
fi fi
@@ -106,13 +113,38 @@ getPackage() {
rm $targetFile rm $targetFile
fi fi
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
baseUrl=https://github.com/MontFerret/ferret/releases/download/$version baseUrl=https://github.com/MontFerret/ferret/releases/download/$version
url=$baseUrl/ferret$suffix.tar.gz url=$baseUrl/ferret$suffix.tar.gz
echo "Downloading package $url as $targetFile" echo "Downloading package $url as $targetFile"
curl -sSL $url | tar xz -C $targetDir curl -sSL $url | tar xz -C $targetDir
if [ "$?" = "0" ]; then if [ "$?" != "0" ]; then
echo "Failed to download file"
exit 1
fi
# checkHash # checkHash
@@ -120,21 +152,20 @@ getPackage() {
echo "Download complete." echo "Download complete."
echo echo
echo "Attempting to move $targetFile to /usr/local/bin" echo "Attempting to move $targetFile to $location"
mv $targetFile /usr/local/bin/ferret mv $targetFile "$location/ferret"
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
echo "New version of ferret installed to /usr/local/bin" echo "New version of ferret installed to $location"
fi fi
if [ -d $targetDir ]; then if [ -d $targetDir ]; then
rm -rf $targetDir rm -rf $targetDir
fi fi
ferret --version "$location/ferret" --version
fi
} }
hasCli hasCli
getPackage getPackage