diff options
Diffstat (limited to 'download.sh')
-rwxr-xr-x | download.sh | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/download.sh b/download.sh index 2631ec7..d3ac068 100755 --- a/download.sh +++ b/download.sh @@ -17,18 +17,40 @@ fi if [[ "$list" =~ "velo" ]]; then url_nonu="http://openmtbmap.org/?s2member_file_download=odbl/nonunicode/english" + url_u="http://openmtbmap.org/?s2member_file_download=odbl/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_u="http://openmtbmap.org/?s2member_file_download=odbl/english" url="http://ftp5.gwdg.de/pub/misc/openstreetmap/openmtbmap/odbl" fi +if [ -f "cookies.jar" ]; then + if test `find "cookies.jar" -mmin +120`; then + do_auth=1 + else + do_auth=0 + fi +else + do_auth=1 +fi -if [ ! -f "cookies.jar" ]; then +if [ $do_auth -ne 0 ]; 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; } +else + echo "Re-using old authentication cookies" fi +function check { + local fail=$1 + local name="$2" + + [ $fail -ne 0 ] && return $fail + size=$(du -sm "downloads/$name" | awk '{ print $1 }') + [ $size -lt 2 ] && return 1 + return 0 +} mkdir -p downloads for name in $(cat $list); do @@ -37,27 +59,42 @@ for name in $(cat $list); do # 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 + check "$?" "$name" + fail=$? + + if [ $fail -ne 0 ]; then + echo curl -L --cookie cookies.jar "$url_u/$name" -o "downloads/$name" #&> /dev/null + check "$?" "$name" + fail=$? + fail_nonu=1 fi if [ $fail -ne 0 ]; then + exit 1; rm -f downloads/$name fail=0 curl -o downloads/$name $url/$name &> /dev/null + check "$?" "$name" + + if [ $? -ne 0 ]; then + curl -o downloads/$name $url/asia/$name &> /dev/null + check "$?" "$name" + fi + if [ $? -ne 0 ]; then + curl -o downloads/$name $url/africa/$name &> /dev/null + check "$?" "$name" + fi + 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" + [ $fail -eq 0 ] && echo "Unicode version (local language!): $name" + elif [ -n "$fail_nonu" ]; then + echo "Non-unicode english version downloaded: $name" + else + echo "Unicode english version downloaded: $name" fi done |