Created
February 19, 2023 14:50
-
-
Save SamadiPour/bf79d1f9ee353b5caad326a7bb68d02d to your computer and use it in GitHub Desktop.
Download the most recent release from GitHub using the checksum - only for releases that have a sha256 file in their release section.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
url="https://github.com/<owner>/<repo>/releases/latest/download/<file_name_with_extension>" | |
current_file="<filename>.<extension>" | |
if [ -f "$current_file" ]; then | |
new_checksum=$(curl -L "$url.sha256" | cut -d " " -f 1) | |
current_checksum=$(shasum -a 256 "$current_file" | cut -d " " -f 1) | |
# Compare the two checksums | |
if [ "$new_checksum" != "$current_checksum" ]; then | |
curl -L "$url" -o "$current_file.temp" | |
# Replace the current file with the new file only if the new one is valid | |
if [ "$(shasum -a 256 "$current_file.temp" | cut -d " " -f 1)" == "$new_checksum" ]; then | |
mv "$current_file.temp" "$current_file" | |
echo "Domains file updated successfully." | |
else | |
rm "$current_file.temp" | |
echo "Domains file is invalid." | |
fi | |
else | |
echo "Domains file is already up to date." | |
fi | |
else | |
curl -L "$url" -o "$current_file" | |
echo "Domains file downloaded successfully." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment