-
Notifications
You must be signed in to change notification settings - Fork 0
/
BSB_update.sh
executable file
·216 lines (194 loc) · 8.66 KB
/
BSB_update.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/sh
#set -e
echo "Start downloading ODBL compatible RNC maps of the world"
HOMEDIR=$HOME/Documents/Maps/tmp/
BSBDIR=$HOME/Documents/Maps/BSB/
mkdir $HOMEDIR 2>/dev/null
cd "$HOMEDIR"
#cp ../*.txt . 2>/dev/null
echo "Brazil (BR) is of compatible license (PD) http://www.mar.mil.br/dhn/chm/cartas/cartas.html"
if [ ! -e ../BR.txt ]; then
touch ../BR.txt
curl -# -G -f http://www.mar.mil.br/dhn/chm/cartas/download/cartasbsb/cartas_eletronicas_Internet.htm -o "BR_chart_list.html" 2>/dev/null
cat BR_chart_list.html | grep zip | tr '"' '\n' | grep zip >> ../BR.txt
curl -# -G -f http://www.mar.mil.br/dhn/chm/cartas/download/cartasbsb/ -o "BR_chart_list.html" 2>/dev/null
cat BR_chart_list.html | grep zip | tr '"' '\n' | grep zip >> ../BR.txt
curl -# -G -f http://www.mar.mil.br/dhn/chm/cartas/download/cartasbsb/cartas_rios.htm -o "BR_chart_list.html" 2>/dev/null
cat BR_chart_list.html | grep zip | tr '"' '\n' | grep zip >> ../BR.txt
curl -# -G -f http://www.mar.mil.br/dhn/chm/cartas/car_portos.html -o "BR_chart_list.html" 2>/dev/null
cat BR_chart_list.html | grep zip | tr '"' '\n' | grep zip >> ../BR.txt
cat BR_chart_list.html | grep zip | tr '"' '\n' | sed -e '/.html/s//.zip/' | grep zip >> ../BR.txt
curl -# -G -f http://www.mar.mil.br/dhn/chm/box-cartas-raster/raster_disponiveis.html -o "BR_chart_list.html" 2>/dev/null
cat BR_chart_list.html | grep zip | tr '"' '\n' | grep zip >> ../BR.txt
cat BR_chart_list.html | grep zip | tr '"' '\n' | sed -e '/.html/s//.zip/' | grep zip >> ../BR.txt
cat ../BR.txt | tr 'cartasbsb/' '\n' | tr 'cartas/' '\n' | tr ' ' '\n' | grep -v geotif | grep zip | uniq > tmp
cat tmp | sort | uniq > ../BR.txt
fi
for i in `cat ../BR.txt`; do echo "Working with BR $i"
curl -# -G -f -C - http://www.mar.mil.br/dhn/chm/cartas/download/cartasbsb/$i -o "BR$i"
if [ -e BR$i ]; then
unzip -Co BR$i \*.BSB -d .
unzip -Co BR$i \*.KAP -d .
bsb=`find $HOMEDIR -iname \*BSB`
echo Chart name: `cat $bsb | grep "CHT/NA" | tr ',' '\n' | sed '/CHT\/NA=/s///' | head -n 1`
echo "Have $i"
count=`find $HOMEDIR | grep KAP | wc -l | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///'`
if [ "$count" != "0" ]; then
echo "$count KAP files exist, removing line"
cat ../BR.txt | grep -v -o ^$i > tmp
cat tmp > ../BR.txt
rm tmp
rm BR$i 2>/dev/null
fi
fi
for f in `find . -type d`; do cd "$HOMEDIR/$f"
mv *BSB $BSBDIR/BR 2>/dev/null
mv *KAP $BSBDIR/BR 2>/dev/null
cd "$HOMEDIR"
done
for j in *; do
if [ -d $j ]; then
rm -rf $j
fi
done
if [ `cat ../BR.txt | wc -l` -lt 1 ]; then
rm ../BR.txt
fi
done
rm BR_chart_list.html 2>/dev/null
echo "Argentina (AR) is of compatible license (PD) http://www.hidro.gob.ar/Nautica/Raster.asp"
#cp ../AR*html . 2>/dev/null
if [ ! -e ../AR.txt ]; then
curl -# -G -f -C - http://www.hidro.gob.ar/Nautica/Raster.asp -o "AR_chart_list_page0.html" 2>/dev/null
for i in `seq 1 10`; do curl -# -G -f -C - http://www.hidro.gob.ar/Nautica/CNRaster.asp?r=$i -o "AR_chart_list_page$i.html" 2>/dev/null ; done
# cp AR*html .. 2>/dev/null
cat AR*html | tr '"' '\n' | grep BSB/ | sed '/BSB\//s///' | sed '/\//s/\n//' | grep zip | sort | uniq > ../AR.txt
rm -rf AR*html 2>/dev/null
fi
for i in `cat ../AR.txt` ; do echo "Working with AR $i"
curl -# -G -f -C - http://www.hidro.gob.ar/cartas/BSB/$i -o "AR$i" 2>/dev/null
if [ -e AR$i ]; then
unzip -Co AR$i \*.BSB -d .
unzip -Co AR$i \*.KAP -d .
# sleep 1.5
bsb=`find $HOMEDIR -iname \*BSB`
echo Chart name: `cat $bsb | grep "CHT/NA" | tr ',' '\n' | sed '/CHT\/NA=/s///' | head -n 1`
echo "Have $i"
count=`find $HOMEDIR | grep KAP | wc -l | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///'`
if [ "$count" != "0" ]; then
echo "$count KAP files exist, removing line"
cat ../AR.txt | grep -v -o ^$i > tmp
cat tmp > ../AR.txt
rm tmp
rm AR$i 2>/dev/null
fi
fi
for f in `find . -type d`; do cd "$HOMEDIR/$f"
mv *BSB $BSBDIR/AR 2>/dev/null
mv *KAP $BSBDIR/AR 2>/dev/null
cd "$HOMEDIR"
done
if [ `cat ../AR.txt | wc -l` -lt 1 ]; then
rm ../AR.txt
fi
done
echo "USA (US) is of compatible license (PD) http://www.charts.noaa.gov/RNCs"
if [ ! -e ../US.txt ]; then
# curl -# -G -f https://www.charts.noaa.gov/RNCs/RNCs.shtml -o "US_Chart_List.html" 2>/dev/null
wget --no-check-certificate -o "US_Chart_list.html" https://www.charts.noaa.gov/RNCs/RNCs.shtml 2>/dev/null
mv RNCs.shtml US_Chart_List.html
touch US1.txt US2.txt US3.txt
cat US_Chart_List.html | sed '/<a href=\"/s///' | sed '/\">/s// /' | sed '/<\/a>/s///' | grep zip | grep -o "^[a-zA-Z0-9]*_[a-zA-Z0-9]*.zip" | sort > US1.txt
cat US_Chart_List.html | sed '/<a href=\"/s///' | sed '/\">/s// /' | sed '/<\/a>/s///' | grep zip | grep -o "^[a-zA-Z0-9]*.zip" | sort > US2.txt
cat US_Chart_List.html | sed '/<a href=\"/s///' | sed '/\">/s// /' | sed '/<\/a>/s///' | grep zip | grep -o "^[0-9]*.zip" | sort > US3.txt
cat US1.txt US2.txt US3.txt | sort -g | uniq > ../US.txt
rm US1.txt US2.txt US3.txt 2>/dev/null
# cat ../US.txt | grep -v Patch > tmp
# cat tmp > ../US.txt
# cat ../US.txt | grep -v Base > tmp
# cat tmp > ../US.txt
# cat ../US.txt | grep -v All > tmp
# cat tmp > ../US.txt
# cat ../US.txt | grep -v All_RNCs > tmp
# cat tmp > ../US.txt
rm tmp 2>/dev/null
rm *html 2>/dev/null
echo "US.txt has $(cat ../US.txt | wc -l) files to download"
fi
for i in `cat ../US.txt`; do echo "Working with US $i"
# curl -# -G -f -C - http://www.charts.noaa.gov/RNCs/$i -o "US$i"
wget --no-check-certificate -o "US$i" https://www.charts.noaa.gov/RNCs/$i
if [ -e US$i ]; then
unzip -Co US$i \*.BSB -d .
unzip -Co US$i \*.KAP -d .
bsb=`find $HOMEDIR -iname \*BSB`
echo Chart name: `cat $bsb | grep "CHT/NA" | tr ',' '\n' | sed '/CHT\/NA=/s///' | head -n 1`
echo "Have $i"
count=`find $HOMEDIR | grep KAP | wc -l | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///'`
if [ "$count" != "0" ]; then
echo "$count KAP files exist, removing line"
cat ../US.txt | grep -v -o ^$i > tmp
cat tmp > ../US.txt
rm tmp 2>/dev/null
rm US$i 2>/dev/null
rm -rf BSB_ROOT 2>/dev/null
fi
fi
for f in `find . -type d`; do cd "$HOMEDIR/$f"
mv *BSB $BSBDIR/US 2>/dev/null
mv *KAP $BSBDIR/US 2>/dev/null
cd "$HOMEDIR"
done
if [ `cat ../US.txt -lt 1` ]; then
rm ../US.txt
fi
done
rmdir BSB_ROOT 2>/dev/null
rm US_Chart_List.html 2>/dev/null
echo "New Zealand (NZ) is of compatible license (CC-BY) http://www.linz.govt.nz/hydro/charts/digital-charts/nzmariner"
if [ ! -e ../NZ.txt ]; then
curl -# -G -f http://www.linz.govt.nz/hydro/charts/digital-charts/nzmariner -o "NZ_charts.html" 2>/dev/null
# cat NZ_charts.html | grep zip | tr '"' '\n' | tr '\"' '\n' | grep zip > ../NZ.txt
echo "BSB_BASE.zip" > ../NZ.txt
echo "BSB_UPDATE.zip" >> ../NZ.txt
rm NZ_charts.html 2>/dev/null
fi
for i in `cat ../NZ.txt`; do echo "Working with NZ $i"
# curl -# -G -f -C - http://www.linz.govt.nz/sites/default/files/docs/hydro/charts/digital/nzmariner/$i -o "NZ$i"
if [ -e NZ$i ]; then
# unzip -Co NZ$i \*.BSB -d .
# unzip -Co NZ$i \*.KAP -d .
bsb=`find $HOMEDIR -iname \*BSB`
echo Chart name: `cat $bsb | grep "CHT/NA" | tr ',' '\n' | sed '/CHT\/NA=/s///' | head -n 1`
echo "Have $i"
count=`find $HOMEDIR | grep KAP | wc -l | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///' | sed '/^ /s///'`
if [ "$count" != "0" ]; then
echo "$count KAP files exist, removing line"
cat ../NZ.txt | grep -v -o ^$i > tmp
cat tmp > ../NZ.txt
rm tmp
rm NZ$i 2>/dev/null
fi
fi
for f in `find . -type d`; do cd "$HOMEDIR/$f"
mv *BSB $BSBDIR/NZ 2>/dev/null
mv *KAP $BSBDIR/NZ 2>/dev/null
cd "$HOMEDIR"
done
if [ `cat ../NZ.txt | wc -l` -lt 1 ]; then
rm ../NZ.txt
fi
done
echo "Chile (CL) http://www.shoa.cl/pagnueva/comelec.html unknown package format"
echo "Canada (CA) http://www.charts.gc.ca/charts-cartes/digital-electronique/index-eng.asp are commercial"
echo "Colombia (CO) http://www.cioh.org.co/derrotero/index.php?option=com_wrapper&view=wrapper&Itemid=62 are commercial"
echo "Equador (EC) http://rossi.christian.free.fr/nautical_free.html#EC are commercial"
echo "Mexico (MX) http://digaohm.semar.gob.mx/derrotero/derroteroDigital.html are commercial"
echo "Panama (PA) http://www.pancanal.com/eng/ are commercial"
echo "Peru (PE) https://www.dhn.mil.pe/app/menu/servicios/cartografia/WebECDIS/ are commercial"
echo "Uruguay (UY) http://www.sohma.armada.mil.uy/cartas-nauticas.htm are commercial"
echo "Venezuela (VE) http://www.dhn.mil.ve are commercial"
#cp *.txt .. 2>/dev/null
rm -rf *
echo "See http://rossi.christian.free.fr/nautical_free.html for more"
echo "Done!"