Created
November 23, 2011 19:29
-
-
Save bfritz/1389644 to your computer and use it in GitHub Desktop.
download and extract mprime to calculate Mersenne primes (or stress test PC)
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/sh | |
set -e | |
EXECUTABLE=mprime | |
ARCH=$(getconf LONG_BIT) | |
get_url() { | |
echo "ftp://mersenne.org/gimps/$1" | |
} | |
download_to_tmp() { | |
URL=$(get_url "$1") | |
TMP=`mktemp -d` | |
( | |
cd $TMP \ | |
&& curl -O $(get_url "$1") | |
) | |
echo $TMP | |
} | |
verify_sha() { | |
if [ "$ARCH" == "64" ]; then | |
SHA256="6f09f0a507e608e493b659940e9751612c509409a29854b262c5af966637c2c1" | |
else | |
SHA256="e58faf7f2f3c18856cae5d03c5fead133748fd9d4f136c0e847ac6edfb41dc91" | |
fi | |
if [ "$SHA256" == $(shasum -a 256 "$1" | awk '{print $1}') ]; then | |
echo "SHA-256 checksum did not match." | |
return 1 | |
fi | |
} | |
extract() { | |
(cd "$1" && tar xfz "$2") | |
} | |
if [ "$ARCH" == "64" ]; then | |
FILE="mprime266-linux64.tar.gz" | |
else | |
FILE="mprime266.tar.gz" | |
fi | |
DIR=$(download_to_tmp $FILE) | |
verify_sha "$DIR/$FILE" \ | |
&& extract "$DIR" "$FILE" \ | |
&& echo "Run mprime with $DIR/$EXECUTABLE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment