summaryrefslogtreecommitdiffstats
path: root/download.sh
blob: 2631ec7607be068bf96d85d900d3558776bfa630 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /bin/bash

# cat list.html | cut -d '"' -f 6 > list.txt
# Need to clean

if [ -z "$1" ]; then
    echo "$0 <list_name>"
    exit -1
fi

list="$1"
listname="$(basename $list .txt)"
if [ ! -f "$list" ]; then
    echo "List "$list" is not found"
    exit -1
fi

if [[ "$list" =~ "velo" ]]; then
    url_nonu="http://openmtbmap.org/?s2member_file_download=odbl/nonunicode/english"
    url="http://ftp5.gwdg.de/pub/misc/openstreetmap/openmtbmap/odbl/velomap"
else
    url_nonu="http://openmtbmap.org/?s2member_file_download=odbl/nonunicode/english"
    url="http://ftp5.gwdg.de/pub/misc/openstreetmap/openmtbmap/odbl"
fi


if [ ! -f "cookies.jar" ]; then
    curl -d log="csa7fff" -d pwd="$(cat .pass)" -d rememberme="forever" --cookie-jar ./cookies.jar https://openmtbmap.org/wp-login.php &> /dev/null
    [ $? -ne 0 ] && { echo "Login failed"; exit 1; }
fi

 
mkdir -p downloads
for name in $(cat $list); do
    [ -f downloads/$name ] && continue
    
    # Try first non-unicode
    fail=0
    curl -L --cookie cookies.jar "$url_nonu/$name" -o "downloads/$name" &> /dev/null
    if [ $? -ne 0 ]; then
        fail=1
    else
        size=$(du -sm "downloads/$name"  | awk '{ print $1 }')
        [ $size -lt 2 ] && fail=1
    fi

    if [ $fail -ne 0 ]; then
        rm -f downloads/$name

        fail=0
        curl -o downloads/$name $url/$name &> /dev/null
        if [ $? -ne 0 ]; then
            fail=1
        else
            size=$(du -sm "downloads/$name"  | awk '{ print $1 }')
            [ $size -lt 2 ] && fail=1
        fi
        [ $fail -ne 0 ] && echo "*** Failed ***: $name"
        [ $fail -eq 0 ] && echo "Unicode version: $name"
    else 
        echo "Non-unicode version downloaded: $name"
    fi
done