-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_geodatawww
executable file
·158 lines (143 loc) · 4.34 KB
/
setup_geodatawww
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
#!/bin/ksh
#TODO for loop performance
set -o errexit
set -o nounset
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/Bin
WWWROOT="/var/www/htdocs"
TMPDIR=$(mktemp -d)
uid=$(id -u)
publicip=$(ifconfig egress | grep inet |grep -v inet6 | cut -d ' ' -f2)
domainname=$(hostname | sed "s/$(hostname -s).//")
appdir=$(pwd)
if [[ $uid -ne 0 ]]; then
print $0 "you've got to run $0 as uid=0 \n"
exit 1
fi
if [ ! -d "$WWWROOT/geodata.$domainname" ]; then
mkdir "$WWWROOT/geodata.$domainname"
fi
cd "$WWWROOT/geodata.$domainname"
iso3166=
while [ -z $iso3166 ]
do
echo -n "Type the country code ISO 3166 "
read iso3166
iso3166=$(echo $iso3166 | tr '[:lower:]' '[:upper:]')
case $iso3166 in
"ES")
if [[ ! -d "$WWWROOT/geodata.$domainname/$iso3166" ]]; then
mkdir "$WWWROOT/geodata.$domainname/$iso3166"
fi
;;
*)
echo -n "Sorry for now only Spain is supported between LAT from 35 to 43 N\
\n and LONG from 0 to 3 E and from 0 to 9 W \n"
exit 1
;;
esac
done
ctrl=
while [ -z $ctrl ]
do
echo -n "Do you want to download SRTM data? "
read ctrl
case $ctrl in
[yY][eE][sS])
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent --user-agent="Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" https://srtm.kurviger.de/
mv srtm.kurvinger.de/* . && rm -rf srtm.kurvinger.de
cd SRTM1
find . -name "*.zip" | xargs -I {} mv {} .
find . -not -name "*.zip" | xargs -I {} rm -rf {}
cd SRTM3
find . -name "*.zip" | xargs -I {} mv {} .
find . -not -name "*.zip" | xargs -I {} rm -rf {}
cd ..
find . -type d -not -name SRTM1 -not -name SRTM3 -not -name . | xargs -I {} rm -rf {}
mkdir Landcover && cd Landcover
wget http://rmw.recordist.com/landcover/
cat index.html | grep -io '<a href=['"'"'"][^"'"'"']*['"'"'"]' | sed 's/<a href="/rmw.recordist.com\/landcover\//' | sed 's/"//' | awk -F, '$1 ~ "zip"' | xargs -I {} wget {}
;;
[nN][oO])
;;
*)
echo "please type yes or no \n"
exit 1
;;
esac
done
ctrl=
while [ -z $ctrl ]
do
echo -n "Do you want to select SRTM and Land cover data \
\nby country code? "
read ctrl
case $ctrl in
[yY][eE][sS])
if [ ! -d "$TMPDIR/SRTM3" ]; then
mkdir "$TMPDIR/SRTM3"
fi
if [ ! -d "$TMPDIR/Landcover" ]; then
mkdir "$TMPDIR/Landcover"
fi
filepath=
file=
nordwest=
nordeast=
cd "$WWWROOT/geodata.$domainname"
for filepath in */*; do
file=$(basename $filepath)
nordwest=$(echo $file | sed -e "/S/d" -e "/E/d")
if [[ ! -z $nordwest ]]; then
typeset -LZ lat=$(echo $nordwest | sed -e "s/.*N//g" -e "s/W.*//g")
typeset -LZ long=$(echo $nordwest | sed -e "s/.*W//g" -e "s/\..*//g")
if [[ $lat -ge 35 && $lat -le 43 && $long -ge 0 && $long -le 9 ]]; then
if [[ "$filepath" == SRTM3* ]]; then
cp $filepath "$TMPDIR/SRTM3"
else
cp $filepath "$TMPDIR/Landcover"
fi
fi
fi
nordeast=$(echo $file | sed -e "/S/d" -e "/W/d")
if [[ ! -z $nordeast ]]; then
typeset -LZ lat=$(echo $nordeast | sed -e "s/.*N//g" -e "s/E.*//g")
typeset -LZ long=$(echo $nordeast | sed -e "s/.*E//g" -e "s/\..*//g")
if [[ $lat -ge 35 && $lat -le 43 && $long -ge 0 && $long -le 3 ]]; then
if [[ "$filepath" == SRTM3* ]]; then
cp $filepath "$TMPDIR/SRTM3"
else
cp $filepath "$TMPDIR/Landcover"
fi
fi
fi
echo -n "."
done
cp -rf "$TMPDIR/"* "$WWWROOT/geodata.$domainname/$iso3166/"
tar -cvf "$WWWROOT/geodata.$domainname/geodata-$iso3166.tar" "$WWWROOT/geodata.$domainname/$iso3166/"
echo -n "you can download the archive containing the $iso3166 geographic data and informations \n"
;;
[nN][oO])
;;
*)
echo -n "please type yes or no"
exit 1
;;
esac
done
cd $appdir
sed -i "s/\/PUBLICIP\//$publicip/g" src/etc/httpd.conf.geodata.$domainname
if [[ -e "/etc/httpd.conf.geodata.$domainname" ]]; then
install -o root -g wheel -m 0640 -b "src/etc/httpd.conf.geodata.$domainname" /etc/
fi
if [[ -e "/etc/httpd.conf" ]]; then
if ! grep -q geodata "/etc/httpd.conf"; then
echo include \"/etc/httpd.conf.geodata.$domainname\" >> /etc/httpd.conf
rcctl restart httpd
fi
else
install -o root -g wheel -m 0640 -b src/etc/httpd.conf /etc/
install -o root -g wheel -m 0640 -b src/etc/httpd.conf.mime.types /etc/
rcctl enable httpd
fi
rcctl start httpd
fi