about summary refs log tree commit diff
path: root/maintainers/scripts/evacuate-urls.sh
blob: c830a7531758600b013d493a65639c7dd05fa0bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#! /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

            if ! echo "$oldURL" | grep -q -E ".cs.uu.nl|.stratego-language.org|java.sun.com|ut2004|linuxq3a|RealPlayer"; then
                base=$(basename $oldURL)
                newURL="http://catamaran.labs.cs.uu.nl/dist/tarballs/$base"
                newPath="/mnt/scratchy/eelco/public_html/tarballs/$base"
                echo "$fn: $oldURL -> $newURL"

                if ! test -e "$newPath"; then
                    curl --fail --location --max-redirs 20 "$oldURL" > "$newPath".tmp
                    mv -f "$newPath".tmp "$newPath"
                fi

                sed "s^$oldURL^$newURL^" < "$fn" > "$fn".tmp
                mv -f "$fn".tmp "$fn"
            fi
            
        fi
    
    done

done