44dbhost=" localhost"
55dbport=3306
66dbname=" geonames"
7- dir=$( cd " $( dirname " $0 " ) " && pwd )
7+ # dir=$( cd "$( dirname "$0" )" && pwd )
8+
9+ download_folder=" ` pwd` /download"
810
911logo () {
1012 echo " ================================================================================================"
@@ -14,7 +16,7 @@ logo() {
1416
1517usage () {
1618 logo
17- echo " Usage 1: " $0 " --download-data"
19+ echo " Usage 1: " $0 " --download-data [folder] "
1820 echo " In this mode the current GeoNames.org's dumps are downloaded to the local machine."
1921 echo
2022 echo " Usage 2: " $0 " -a <action> -u <user> -p <password> -h <host> -r <port> -n <dbname>"
@@ -39,23 +41,19 @@ usage() {
3941
4042download_geonames_data () {
4143 echo " Downloading GeoNames.org data..."
42- wget -c http://download.geonames.org/export/dump/allCountries.zip
43- wget -c http://download.geonames.org/export/dump/alternateNames.zip
44- wget -c http://download.geonames.org/export/dump/hierarchy.zip
45- wget -c http://download.geonames.org/export/dump/admin1CodesASCII.txt
46- wget -c http://download.geonames.org/export/dump/admin2Codes.txt
47- wget -c http://download.geonames.org/export/dump/featureCodes_en.txt
48- wget -c http://download.geonames.org/export/dump/timeZones.txt
49- wget -c http://download.geonames.org/export/dump/countryInfo.txt
50- wget -c -O allCountries_zip.zip http://download.geonames.org/export/zip/allCountries.zip
51- unzip allCountries.zip
52- unzip alternateNames.zip
53- unzip hierarchy.zip
54- unzip allCountries_zip.zip -d ./zip/
55- rm allCountries.zip
56- rm alternateNames.zip
57- rm hierarchy.zip
58- rm allCountries_zip.zip
44+ download_folder=" $1 "
45+ dumps=" allCountries.zip alternateNames.zip hierarchy.zip admin1CodesASCII.txt admin2Codes.txt featureCodes_en.txt timeZones.txt countryInfo.txt"
46+ zip_codes=" allCountries.zip"
47+ for dump in $dumps ; do
48+ wget -c -P " $download_folder " http://download.geonames.org/export/dump/$dump
49+ done
50+ for zip in $zip_codes ; do
51+ wget -c -P " $download_folder " -O " ${zip: 0: (-4)} _zip.zip" http://download.geonames.org/export/zip/$zip
52+ done
53+ unzip " *_zip.zip" -d ./zip
54+ rm * _zip.zip
55+ unzip " *.zip"
56+ rm * .zip
5957}
6058
6159if [ $# -lt 1 ]; then
6664logo
6765
6866# Deals operation mode 1 (Download data bundles from geonames.org)
69- if { [ $# == 1 ] && [ " $1 " == " --download-data" ]; } then
70- download_geonames_data
71- exit 0
67+ if { [ " $1 " == " --download-data" ]; } then
68+ if { [ " $2 " != " " ]; } then
69+ if [ ! -d " $2 " ]; then
70+ echo " Folder '$2 ' doesn't exists. Run mkdir..."
71+ mkdir " $2 "
72+ fi
73+ download_folder=" $2 "
74+ fi
75+ echo " download_folder=$download_folder "
76+ download_geonames_data " $download_folder "
7277fi
7378
7479# Deals with operation mode 2 (Database issues...)
0 commit comments