#! /bin/bash # cat list.html | cut -d '"' -f 6 > list.txt # Need to clean if [ -z "$1" ]; then echo "$0 " 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_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 [ $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 }') [ -z "$size" ] && return 1 [ "$size" -lt 2 ] && return 1 return 0 } 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 check "$?" "$name" fail=$? if [ $fail -ne 0 ]; then 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 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 fi [ $fail -ne 0 ] && echo "*** Failed ***: $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