Implement downloadable timezone database
[geeqie.git] / scripts / zonedetect / create_timezone_database
1 #! /bin/sh
2
3 # This script will generate the timezone database file used to
4 # correct exif time and date for UTC offset and Daylight Saving Time.
5 #
6 # The Preferences/General tab of Geeqie gives the user the option to
7 # download the database from a defined location on geeqie.org.
8 #
9 # If the generated file differs from that on geeqie.org you should
10 # upload the new version. You will need write privileges to do this.
11 #
12 # Refer to https://github.com/BertoldVdb/ZoneDetect for the
13 # origin of files builder.cpp and zoneToAlpha.h
14
15 timezone_boundary_builder_default_release="2019a"
16
17 cd "$(dirname "$0")"
18 current_dir=$PWD
19
20 xdg-open https://github.com/evansiroky/timezone-boundary-builder/releases/
21
22 if [ -f timezone_boundary_builder_release.txt ]
23 then
24         timezone_boundary_builder_release=$(cat timezone_boundary_builder_release.txt)
25 else
26         timezone_boundary_builder_release=$timezone_boundary_builder_default_release
27 fi
28
29 timezone_boundary_builder_release=$(zenity --entry --entry-text="$timezone_boundary_builder_release" --title "Geeqie generate timezone database" --text="Which timezone boundary builder\nrelease should be used?\n" --width=350 --window-icon=$current_dir/../../geeqie.png)
30
31 if [ -n "$timezone_boundary_builder_release" ]
32 then
33         echo "$timezone_boundary_builder_release" > "timezone_boundary_builder_release.txt"
34 else
35         exit
36 fi
37
38 rm -rf naturalearth
39 rm -rf timezone
40 rm -rf geeqie_org
41 rm -f timezone21.bin
42
43 g++ builder.cpp -o builder -lshp
44
45 mkdir naturalearth
46 cd naturalearth
47 wget https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries_lakes.zip
48 if [ $? -ne 0 ]
49 then
50         zenity --error --text="Download of naturalearthdata failed" --title="Generate Geeqie timezone database" --width=300 --window-icon=$current_dir/../../geeqie.png
51         exit
52 fi
53
54 unzip ne_10m_admin_0_countries_lakes.zip
55 cd ..
56
57 mkdir timezone
58 cd timezone
59 wget https://github.com/evansiroky/timezone-boundary-builder/releases/download/$timezone_boundary_builder_release/timezones.shapefile.zip
60 if [ $? -ne 0 ]
61 then
62         zenity --error --text="Download of timezone-boundary-builder failed" --title="Generate Geeqie timezone database" --width=300 --window-icon=$current_dir/../../geeqie.png
63         exit
64 fi
65
66 unzip timezones.shapefile.zip
67 cd ..
68
69
70 ./builder T timezone/dist/combined-shapefile timezone21.bin 21 "Contains data from Natural Earth, placed in the Public Domain. Contains information from https://github.com/evansiroky/timezone-boundary-builder, which is made available here under the Open Database License (ODbL)."
71
72 mkdir geeqie_org
73 cd geeqie_org
74 wget http://www.geeqie.org/downloads/timezone21.bin
75 if [ $? -ne 0 ]
76 then
77         zenity --error --text="Download of timezone database from geeqie.org failed" --title="Generate Geeqie timezone database" --width=300 --window-icon=$current_dir/../../geeqie.png
78         exit
79 fi
80 cd ..
81
82 diff ./geeqie_org/timezone21.bin timezone21.bin
83
84 if [ $? != 0 ]
85 then 
86         zenity --info --title="Generate Geeqie timezone database" --text="Generated file differs from that on geeqie.org\n\nUpload timezone21.bin to:\ngeeqie.org/downloads/" --width=300 --window-icon=$current_dir/../../geeqie.png
87 else
88         zenity --info --title="Generate Geeqie timezone database" --text="Generated file is the same as on geeqie.org" --width=300 --window-icon=$current_dir/../../geeqie.png
89         rm timezone21.bin
90 fi
91
92 rm -f builder
93 rm -rf naturalearth
94 rm -rf timezone
95 rm -rf geeqie_org