2005-02-15 14:32:55 +00:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
|
|
|
find . -name "*.nix" | while read fn; do
|
|
|
|
|
|
|
|
grep -E '^ *url = ' "$fn" | while read line; do
|
|
|
|
|
|
|
|
if oldURL=$(echo "$line" | sed 's^url = \(.*\);^\1^'); then
|
|
|
|
|
2006-10-12 16:59:15 +01:00
|
|
|
if ! echo "$oldURL" | grep -q -E "www.cs.uu.nl|nix.cs.uu.nl|.stratego-language.org|java.sun.com|ut2004|linuxq3a|RealPlayer|Adbe|belastingdienst|microsoft|armijn/.nix|sun.com|archive.eclipse.org"; then
|
2005-02-15 14:32:55 +00:00
|
|
|
base=$(basename $oldURL)
|
2006-01-30 16:20:35 +00:00
|
|
|
newURL="http://nix.cs.uu.nl/dist/tarballs/$base"
|
|
|
|
newPath="/data/webserver/dist/tarballs/$base"
|
2005-02-15 14:32:55 +00:00
|
|
|
echo "$fn: $oldURL -> $newURL"
|
|
|
|
|
2006-10-12 16:59:15 +01:00
|
|
|
isSafe=1
|
2006-01-30 16:20:35 +00:00
|
|
|
|
2006-10-12 16:59:15 +01:00
|
|
|
if test -e "$newPath"; then
|
|
|
|
hash=$(fgrep -A 1 "$oldURL" "$fn" | grep md5 | sed 's^.*md5 = \"\(.*\)\";.*^\1^')
|
2007-05-15 14:33:14 +01:00
|
|
|
hashType=md5
|
|
|
|
if test -z "$hash"; then
|
|
|
|
hash=$(fgrep -A 1 "$oldURL" "$fn" | grep sha256 | sed 's^.*sha256 = \"\(.*\)\";.*^\1^')
|
|
|
|
hashType="sha256 --base32"
|
|
|
|
if test -z "$hash"; then
|
|
|
|
echo "WARNING: cannot figure out the hash for $oldURL"
|
|
|
|
isSafe=
|
|
|
|
fi
|
|
|
|
fi
|
2006-10-12 16:59:15 +01:00
|
|
|
echo "HASH = $hash"
|
2007-05-15 14:33:14 +01:00
|
|
|
if ! test "$(nix-hash --type $hashType --flat "$newPath")" = "$hash"; then
|
2006-10-12 16:59:15 +01:00
|
|
|
echo "WARNING: $newPath exists and differs!"
|
|
|
|
isSafe=
|
|
|
|
fi
|
|
|
|
fi
|
2006-10-12 14:50:54 +01:00
|
|
|
|
2006-10-12 16:59:15 +01:00
|
|
|
if test -n "$doMove" -a -n "$isSafe"; then
|
2006-01-30 16:20:35 +00:00
|
|
|
|
2006-10-12 16:59:15 +01:00
|
|
|
if ! test -e "$newPath"; then
|
|
|
|
curl --disable-epsv --fail --location --max-redirs 20 "$oldURL" > "$newPath".tmp
|
|
|
|
mv -f "$newPath".tmp "$newPath"
|
2006-10-12 14:50:54 +01:00
|
|
|
fi
|
2006-01-30 16:20:35 +00:00
|
|
|
|
2006-10-12 16:59:15 +01:00
|
|
|
sed "s^$oldURL^$newURL^" < "$fn" > "$fn".tmp
|
|
|
|
mv -f "$fn".tmp "$fn"
|
|
|
|
|
2006-10-12 14:50:54 +01:00
|
|
|
fi
|
2005-02-15 14:32:55 +00:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
done
|