/
iiab-install-map-region
executable file
·79 lines (66 loc) · 4.34 KB
/
iiab-install-map-region
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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# e.g. USAGE: /usr/bin/iiab-install-map-region osm_oceania_z11-z14_2020.mbtiles
# Download a Map Pack (3 .mbtiles files, as nec) for IIAB 8.0 w/o Admin Console
# https://github.com/iiab/iiab/blob/master/roles/osm-vector-maps/README.md
# https://github.com/iiab/iiab/wiki/IIAB-Maps
REGION=osm_san_jose_z11-z14_2020.mbtiles # If called w/o parameter (30 MB)
if [ $# -ne 0 ]; then
REGION=$1 # Map Pack selected on page: http://box > "Install IIAB Maps"
fi # SCREENSHOT https://github.com/iiab/iiab/pull/2551#issuecomment-701649236
OSM_PLANET=osm-planet_z0-z10_2020.mbtiles # 2.0 GB
SAT_PLANET=satellite_z0-z9_2020.mbtiles # 1.2 GB
OSM_PREVIEW=planet_z0-z6_2020.mbtiles # 48 MB
SAT_PREVIEW=satellite_z0-z6_2020.mbtiles # 25 MB
WORKING_DIR=/library/working/maps
TILES_DIR=/library/www/osm-vector-maps/viewer/tiles
iiab_var_value() {
v1=$(grep "^$1:\s" /opt/iiab/iiab/vars/default_vars.yml 2> /dev/null | tail -1 | sed "s/^$1:\s\+//; s/#.*//; s/\s*$//; s/^\(['\"]\)\(.*\)\1$/\2/")
v2=$(grep "^$1:\s" /etc/iiab/local_vars.yml 2> /dev/null | tail -1 | sed "s/^$1:\s\+//; s/#.*//; s/\s*$//; s/^\(['\"]\)\(.*\)\1$/\2/")
[[ $v2 != "" ]] && echo $v2 || echo $v1 # [ "$v2" ] ALSO WORKS
}
install_mbtiles() {
if [ -f $TILES_DIR/$1 ] ; then
echo -e "ALREADY INSTALLED: $TILES_DIR/$1\n"
else
# grep -q '^maps_from_internet_archive:\s\+[tT]rue\b' /etc/iiab/local_vars.yml; loc_t=$?
# grep -q '^maps_from_internet_archive:\s\+[fF]alse\b' /etc/iiab/local_vars.yml; loc_f=$?
# grep -q '^maps_from_internet_archive:\s\+[tT]rue\b' /opt/iiab/iiab/vars/default_vars.yml; def_t=$?
# # 0 means TRUE 1 means FALSE 2 means ERROR e.g. FILE DOESN'T EXIST
# if [[ $loc_t = 0 || ($def_t = 0 && ! $loc_f = 0) ]]; then
# #if grep -q '^maps_from_internet_archive: True' /etc/iiab/local_vars.yml ; then
if [[ $(iiab_var_value maps_from_internet_archive) =~ ^[Tt]rue$ ]]; then # Or regex: ^True|true$
wget -c https://archive.org/download/$1/$1 -P $WORKING_DIR # 2022-04-30 WARNING: NOT ALL *2020*.mbtiles FILES ARE YET UPLOADED TO archive.org
else
#wget -c http://timmoody.com/iiab-files/maps/$1 -P $WORKING_DIR # Bluehost became extremely slow
wget -c https://usc1.contabostorage.com/6ce80ee7cd3b4baba0fbb26a424b0b29:iiab-maps/$1 -P $WORKING_DIR # Limited to ~80 Mbit/s, unlike rclone
fi
# FYI Bluehost (timmoody.com) erroneously 404's if full file is in
# $WORKING_DIR but not $TILES_DIR, causing wget error code 8. Whereas
# Archive.org correctly returns "416 Requested Range Not Satisfiable"
# with wget output "The file is already fully retrieved; nothing to do"
# w/ wget exit code 0 (used below). So we move it immediately 2 B Safe:
if [ $? -eq 0 ]; then
echo -e "MOVING $1 TO $TILES_DIR\n"
mv $WORKING_DIR/$1 $TILES_DIR
else
echo -e " ███████████████████████████████ DOWNLOAD ERROR ███████████████████████████████"
echo -e " ██ ██"
echo -e " ██ (1) Verify your Internet and try again? ██"
echo -e " ██ ██"
echo -e " ██ (2) Set 'maps_from_internet_archive: True' in /etc/iiab/local_vars.yml ? ██"
echo -e " ██ ██"
echo -e " ██████████████████████████████████████████████████████████████████████████████\n"
exit 1
fi
fi
}
# Download & Install 3 .mbtiles files (as nec!)
echo
install_mbtiles $REGION
install_mbtiles $OSM_PLANET
install_mbtiles $SAT_PLANET
echo -e "Deleting OSM & Satellite PREVIEW tiles (as nec!)\n"
rm -f $TILES_DIR/$OSM_PREVIEW
rm -f $TILES_DIR/$SAT_PREVIEW
# Put a json file (landing URL) which initializes the map view
iiab-maps-finish.py $REGION