Update installscript with retry

This commit is contained in:
zontreck 2024-08-31 02:17:33 -07:00
parent f177bb5b6a
commit a8a68e84bb

View file

@ -17,32 +17,60 @@ else
fi
# Test password to check if it's correct
echo -ne "$PASS" | sudo -S echo "Escalation successful" &>/dev/null
echo "$PASS" | sudo -S echo "Escalation successful" &>/dev/null
if [ $? -ne 0 ]; then
echo "Password incorrect. Exiting installer."
exit 1
fi
SUDO_CMD="echo -ne \"$PASS\" | sudo -S"
SUDO_CMD="echo $PASS | sudo -S"
fi
# Function to download a file with retry logic
download_with_retry() {
local url=$1
local output=$2
local max_retries=5
local attempt=1
while [ $attempt -le $max_retries ]; do
$SUDO_CMD wget "$url" -O "$output"
# Check if the download was successful and the file is not empty
if [ -s "$output" ]; then
echo "Downloaded $output successfully."
return 0
else
echo "Failed to download $output or file is empty. Retrying... ($attempt/$max_retries)"
# Delete the incomplete or zero-byte file if the download fails
$SUDO_CMD rm -f "$output"
attempt=$((attempt + 1))
fi
done
echo "Failed to download $output after $max_retries attempts. Exiting."
exit 1
}
# Download the tools and put them in place
$SUDO_CMD wget https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/nbt2snbt-linux-x64 -O /usr/bin/nbt2snbt
download_with_retry "https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/nbt2snbt-linux-x64" "/usr/bin/nbt2snbt"
$SUDO_CMD wget https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/pause-linux-x64 -O /usr/bin/pause
download_with_retry "https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/pause-linux-x64" "/usr/bin/pause"
$SUDO_CMD wget https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/snbt2nbt-linux-x64 -O /usr/bin/snbt2nbt
download_with_retry "https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/snbt2nbt-linux-x64" "/usr/bin/snbt2nbt"
$SUDO_CMD wget https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/dbikc-linux-x64 -O /usr/bin/dbikc
download_with_retry "https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/dbikc-linux-x64" "/usr/bin/dbikc"
$SUDO_CMD wget https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/uuidgen-linux-x64 -O /usr/bin/uuidgen
download_with_retry "https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/uuidgen-linux-x64" "/usr/bin/uuidgen"
$SUDO_CMD wget https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/sleep-linux-x64 -O /usr/bin/vsleep
download_with_retry "https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/sleep-linux-x64" "/usr/bin/vsleep"
$SUDO_CMD wget https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/mkfsreport-linux-x64 -O /usr/bin/mkfsreport
download_with_retry "https://ci.zontreck.com/job/Projects/job/Dart/job/SimpleHelperTools/job/main/lastSuccessfulBuild/artifact/dart/out/mkfsreport-linux-x64" "/usr/bin/mkfsreport"
# Set executable permissions
$SUDO_CMD chmod +x /usr/bin/{nbt2snbt,snbt2nbt,pause,mkfsreport,dbikc,vsleep}
$SUDO_CMD chmod +x /usr/bin/{nbt2snbt,snbt2nbt,pause,mkfsreport,dbikc,vsleep,uuidgen}
echo "Installation Completed"
vsleep 5