-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.sh
66 lines (51 loc) · 2.82 KB
/
import.sh
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
64
65
66
#!bin/bash
if [ $# -ne 2 ]; then
echo "$0: usage: $0 <username> <password>"
exit 1
fi
username="$1"
password="$2"
DATA_DIRECTORY='tmp'
mkdir -p "$DATA_DIRECTORY"
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/allCountries.zip
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/alternateNamesV2.zip
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/adminCode5.zip
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/cities500.zip
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/hierarchy.zip
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/userTags.zip
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/admin1CodesASCII.txt
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/admin2Codes.txt
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/iso-languagecodes.txt
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/featureCodes_en.txt
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/timeZones.txt
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/countryInfo.txt
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/no-country.zip
wget --directory-prefix="$DATA_DIRECTORY" http://download.geonames.org/export/dump/shapes_all_low.zip
unzip "$DATA_DIRECTORY/allCountries.zip" -d "$DATA_DIRECTORY"
unzip "$DATA_DIRECTORY/alternateNamesV2.zip" -d "$DATA_DIRECTORY"
unzip "$DATA_DIRECTORY/adminCode5.zip" -d "$DATA_DIRECTORY"
unzip "$DATA_DIRECTORY/cities500.zip" -d "$DATA_DIRECTORY"
unzip "$DATA_DIRECTORY/hierarchy.zip" -d "$DATA_DIRECTORY"
unzip "$DATA_DIRECTORY/userTags.zip" -d "$DATA_DIRECTORY"
unzip "$DATA_DIRECTORY/no-country.zip" -d "$DATA_DIRECTORY"
unzip "$DATA_DIRECTORY/shapes_all_low.zip" -d "$DATA_DIRECTORY"
cat "$DATA_DIRECTORY/countryInfo.txt" | grep -v "^#" > "$DATA_DIRECTORY/countryInfo-n.txt"
MYSQLVERSION=$(mysql --version|awk '{ print $3 }'|awk -F\, '{ print $1 }')
if [[ "$MYSQLVERSION" = 8* ]]
then
sed -i -e 's/-180/-179.99999999999/g' "$DATA_DIRECTORY/shapes_all_low.txt"
fi
echo "Uploading data to geonames database"
mysql -u "$username" -p"$password" geonames --local-infile=1 < import.sql
echo "Applying indices"
mysql -u "$username" -p"$password" geonames < index.sql
echo "Applying foreign keys"
mysql -u "$username" -p"$password" geonames < foreign.sql
echo "Transforming into spatial data"
if [[ "$MYSQLVERSION" = 8* ]]
then
mysql -u "$username" -p"$password" geonames < import_spatial_mysql8.sql
else
mysql -u "$username" -p"$password" geonames < import_spatial_mysql5.sql
fi
rm -r "$DATA_DIRECTORY"