Skip to content

Instantly share code, notes, and snippets.

@SamadiPour
Created February 19, 2023 14:50
Show Gist options
  • Save SamadiPour/bf79d1f9ee353b5caad326a7bb68d02d to your computer and use it in GitHub Desktop.
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.
#!/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