Last active
August 29, 2015 14:23
-
-
Save raindev/694ec67994aad001d2d9 to your computer and use it in GitHub Desktop.
Script for changing SHA-1 hashsum of a formula to SHA-256
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Usage: ./brew-rehash.sh formula-file.rb | |
| if [[ $1 == *".rb" ]]; then | |
| formula=$1 | |
| else | |
| formula="$1.rb" | |
| fi | |
| echo "Rehashing $1" | |
| url=$(cat $formula | grep -m1 "url ['\"]http" | sed "s/.* ['\"]//" | sed "s/['\"]$//") | |
| wget $url -O- > /tmp/formula | |
| if [ $? -ne 0 ]; then | |
| echo "Download of $1 failed from URL: $url" | |
| fi | |
| actual_sha1=$(shasum -a1 /tmp/formula | sed "s/ .*$//") | |
| expected_sha1=$(cat $formula | grep -m1 sha1 | sed "s/.* ['\"']//" | sed "s/['\"]$//") | |
| if [ "$actual_sha1" = "$expected_sha1" ]; then | |
| sha256=$(shasum -a256 /tmp/formula | sed "s/ .*$//") | |
| sed -i.bak "1,/sha1/s/sha1 [\"'].*[\"']/sha256 \"$sha256\"/" $formula | |
| rm *.bak | |
| else | |
| echo "SHA-1 for formula $1 do not match; URL: $url" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment