-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·181 lines (118 loc) · 5.35 KB
/
install.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
#!/bin/bash
OSM_MIRROR_CONF=/etc/default/openstreetmap-conf
function echo_step () {
echo -e "\e[92m\e[1m$1\e[0m"
}
function echo_error () {
echo -e "\e[91m\e[1m$1\e[0m"
}
#.......................................................................
precise=$(grep "Ubuntu 12.04" /etc/issue | wc -l)
if [ ! $precise -eq 1 ] ; then
echo_error "Unsupported operating system. Aborted."
exit 5
fi
#.......................................................................
echo_step "Configure instance..."
if [[ -z "$EXTENT" ]]; then
read -e -p "Enter extent (xmin,ymin,xmax,ymax): " -i "2.04,43.88,2.22,43.98" EXTENT
fi
cat << _EOF_ > $OSM_MIRROR_CONF
DB_NAME="gis"
DB_USER="gisuser"
DB_PASSWORD="corpus"
EXTENT="${EXTENT}"
_EOF_
source $OSM_MIRROR_CONF
#.......................................................................
echo_step "Upgrade operating system..."
apt-get update > /dev/null
apt-get install -y python-software-properties
apt-add-repository -y ppa:git-core/ppa
apt-add-repository -y ppa:ubuntugis/ppa
add-apt-repository -y ppa:kakrueger/openstreetmap
apt-get update > /dev/null
apt-get dist-upgrade -y
#.......................................................................
echo_step "Install necessary components..."
apt-get install -y git curl wget libgdal1 gdal-bin mapnik-utils unzip
locale-gen en_US en_US.UTF-8
locale-gen fr_FR fr_FR.UTF-8
dpkg-reconfigure locales
export DEBIAN_FRONTEND=noninteractive
apt-get install -y libapache2-mod-tile
#.......................................................................
if [ ! -f README.md ]; then
echo_step "Downloading installer source..."
git clone --recursive --depth=50 --branch=master https://github.com/makinacorpus/osm-mirror.git /tmp/osm-mirror
rm -f /tmp/osm-mirror/install.sh
shopt -s dotglob nullglob
cp -R /tmp/osm-mirror/* .
fi
#.......................................................................
echo_step "Configure database..."
sudo -n -u postgres -s -- psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASSWORD}';"
sudo -n -u postgres -s -- psql -c "CREATE DATABASE ${DB_NAME} OWNER ${DB_USER} ENCODING 'UTF8' TEMPLATE template0;"
sudo -n -u postgres -s -- psql -d ${DB_NAME} -c "CREATE EXTENSION postgis;"
sudo -n -u postgres -s -- psql -d ${DB_NAME} -c "GRANT ALL ON spatial_ref_sys, geometry_columns, raster_columns TO ${DB_USER};"
sudo -n -u postgres -s -- psql -d ${DB_NAME} -f /usr/share/postgresql/9.1/contrib/postgis-2.0/legacy.sql
cat << _EOF_ >> /etc/postgresql/9.1/main/pg_hba.conf
# Automatically added by OSM installation :
local ${DB_NAME} ${DB_USER} trust
host ${DB_NAME} ${DB_USER} 127.0.0.1/32 trust
_EOF_
echo_step "Restart service..."
/etc/init.d/postgresql restart
#.......................................................................
OSM_DATA=/usr/share/mapnik-osm-data/world_boundaries
if [ ! -f $OSM_DATA/10m-land.shp ]; then
echo_step "Load world boundaries data..."
# Copy ne_10m_populated_places to ne_10m_populated_places_fixed
rm -rf $OSM_DATA/ne_10m_populated_places_fixed.*
ogr2ogr $OSM_DATA/ne_10m_populated_places_fixed.shp $OSM_DATA/ne_10m_populated_places.shp
zipfile=/tmp/simplified-land-polygons-complete-3857.zip
curl -L -o "$zipfile" "http://data.openstreetmapdata.com/simplified-land-polygons-complete-3857.zip"
unzip -qqu $zipfile simplified-land-polygons-complete-3857/simplified_land_polygons.{shp,shx,prj,dbf,cpg} -d /tmp
rm $zipfile
mv /tmp/simplified-land-polygons-complete-3857/simplified_land_polygons.* $OSM_DATA/
zipfile=/tmp/land-polygons-split-3857.zip
curl -L -o "$zipfile" "http://data.openstreetmapdata.com/land-polygons-split-3857.zip"
unzip -qqu $zipfile -d /tmp
rm $zipfile
mv /tmp/land-polygons-split-3857/land_polygons.* $OSM_DATA/
zipfile=/tmp/coastline-good.zip
curl -L -o "$zipfile" "http://tilemill-data.s3.amazonaws.com/osm/coastline-good.zip"
unzip -qqu $zipfile -d /tmp
rm $zipfile
mv /tmp/coastline-good.* $OSM_DATA/
zipfile=/tmp/10m-land.zip
curl -L -o "$zipfile" "http://mapbox-geodata.s3.amazonaws.com/natural-earth-1.3.0/physical/10m-land.zip"
unzip -qqu $zipfile -d /tmp
rm $zipfile
mv /tmp/10m-land.* $OSM_DATA/
shapeindex --shape_files \
$OSM_DATA/simplified_land_polygons.shp \
$OSM_DATA/land_polygons.shp \
$OSM_DATA/coastline-good.shp \
$OSM_DATA/10m-land.shp \
$OSM_DATA/shoreline_300.shp \
$OSM_DATA/ne_10m_populated_places_fixed.shp
fi
#.......................................................................
echo_step "Deploy preview map..."
rm /var/www/index.html
cp -R preview/* /var/www/
#.......................................................................
echo_step "Setup monthly update in root crontab..."
croncmd="`pwd`/update-data.sh 2> /var/log/openstreetmap-errors"
cronjob="0 2 1 * * $croncmd"
( crontab -u root -l 2> /dev/null | grep -v "$croncmd" ; echo "$cronjob" ) | crontab -u root -
#.......................................................................
./update-data.sh
# Grant rights on OSM tables
/usr/bin/install-postgis-osm-user.sh ${DB_NAME} www-data 2> /dev/null
/usr/bin/install-postgis-osm-user.sh ${DB_NAME} gisuser 2> /dev/null
#.......................................................................
./update-conf.sh
#.......................................................................
echo_step "Install done."