opentileserver.sh


SUBMITTED BY: darkone1

DATE: Dec. 17, 2016, 10:13 a.m.

FORMAT: Text only

SIZE: 18.1 kB

HITS: 1116

  1. #Version: 0.3.15
  2. #For use on clean Ubuntu 14 only!!!
  3. #MapFig, Inc
  4. #Usage: ./opentileserver.sh [web|ssl] [bright|carto] [pbf_url]"
  5. #Example for Delaware
  6. # ./opentileserver.sh web carto http://download.geofabrik.de/north-america/us/delaware-latest.osm.pbf
  7. #To run in non-Latin language uncomment below
  8. #export LC_ALL=C
  9. WEB_MODE="${1}" #web,ssl
  10. OSM_STYLE="${2}" #bright, carto
  11. PBF_URL="${3}"; #get URL from first parameter, http://download.geofabrik.de/europe/germany-latest.osm.pbf
  12. OSM_STYLE_XML=''
  13. CND_FOLDER='https://www.mapfig.com/'
  14. #User for DB and rednerd
  15. OSM_USER='tile'; #system user for renderd and db
  16. OSM_USER_PASS='osm2015SgsjcK'; #CHANGE ME
  17. OSM_PG_PASS=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32);
  18. OSM_DB='gis'; #osm database name
  19. VHOST=$(hostname -f)
  20. #C_MEM is the sum of free memory and cached memory
  21. C_MEM=$(free -m | grep -i 'mem:' | sed 's/[ \t]\+/ /g' | cut -f4,7 -d' ' | tr ' ' '+' | bc)
  22. NP=$(grep -c 'model name' /proc/cpuinfo)
  23. osm2pgsql_OPTS="--slim -d ${OSM_DB} -C ${C_MEM} --number-processes ${NP} --hstore"
  24. #Check input parameters
  25. if [ -z "${PBF_URL}" -o \
  26. $(echo "${OSM_STYLE}" | grep -c '[briht|carto]') -eq 0 -o \
  27. $(echo "${WEB_MODE}" | grep -c '[web|ssl]') -eq 0 ]; then
  28. echo "Usage: $0 [web|ssl] [bright|carto] pbf_url"; exit 1;
  29. fi
  30. touch /root/auth.txt
  31. function style_osm_bright(){
  32. cd /usr/local/share/maps/style
  33. if [ ! -d 'osm-bright-master' ]; then
  34. wget https://github.com/mapbox/osm-bright/archive/master.zip
  35. unzip master.zip;
  36. mkdir -p osm-bright-master/shp
  37. rm master.zip
  38. fi
  39. for shp in 'land-polygons-split-3857' 'simplified-land-polygons-complete-3857'; do
  40. if [ ! -d "osm-bright-master/shp/${shp}" ]; then
  41. wget http://data.openstreetmapdata.com/${shp}.zip
  42. unzip ${shp}.zip;
  43. mv ${shp}/ osm-bright-master/shp/
  44. rm ${shp}.zip
  45. pushd osm-bright-master/shp/${shp}/
  46. shapeindex *.shp
  47. popd
  48. fi
  49. done
  50. if [ ! -d 'osm-bright-master/shp/ne_10m_populated_places' ]; then
  51. wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip
  52. unzip ne_10m_populated_places.zip
  53. mkdir -p osm-bright-master/shp/ne_10m_populated_places
  54. rm ne_10m_populated_places.zip
  55. mv ne_10m_populated_places.* osm-bright-master/shp/ne_10m_populated_places/
  56. fi
  57. #9 Configuring OSM Bright
  58. if [ $(grep -c '.zip' /usr/local/share/maps/style/osm-bright-master/osm-bright/osm-bright.osm2pgsql.mml) -ne 0 ]; then #if we have zip in mml
  59. cd /usr/local/share/maps/style/osm-bright-master
  60. cp osm-bright/osm-bright.osm2pgsql.mml osm-bright/osm-bright.osm2pgsql.mml.orig
  61. sed -i.save 's|.*simplified-land-polygons-complete-3857.zip",|"file":"/usr/local/share/maps/style/osm-bright-master/shp/simplified-land-polygons-complete-3857/simplified_land_polygons.shp",\n"type": "shape",|' osm-bright/osm-bright.osm2pgsql.mml
  62. sed -i.save 's|.*land-polygons-split-3857.zip"|"file":"/usr/local/share/maps/style/osm-bright-master/shp/land-polygons-split-3857/land_polygons.shp",\n"type":"shape"|' osm-bright/osm-bright.osm2pgsql.mml
  63. sed -i.save 's|.*10m-populated-places-simple.zip"|"file":"/usr/local/share/maps/style/osm-bright-master/shp/ne_10m_populated_places/ne_10m_populated_places.shp",\n"type": "shape"|' osm-bright/osm-bright.osm2pgsql.mml
  64. sed -i.save '/name":[ \t]*"ne_places"/a"srs": "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"' osm-bright/osm-bright.osm2pgsql.mml
  65. #Delete
  66. #"srs": "",
  67. # "srs_name": "",
  68. LINE_FROM=$(grep -n '"srs": "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"' osm-bright/osm-bright.osm2pgsql.mml | cut -f1 -d':')
  69. let LINE_FROM=LINE_FROM+1
  70. let LINE_TO=LINE_FROM+1
  71. sed -i.save "${LINE_FROM},${LINE_TO}d" osm-bright/osm-bright.osm2pgsql.mml
  72. fi
  73. #10 Compiling the stylesheet
  74. if [ ! -f /usr/local/share/maps/style/osm-bright-master/OSMBright/OSMBright.xml ]; then
  75. cd /usr/local/share/maps/style/osm-bright-master
  76. cp configure.py.sample configure.py
  77. sed -i.save 's|config\["path"\].*|config\["path"\] = path.expanduser("/usr/local/share/maps/style")|' configure.py
  78. sed -i.save "s|config\[\"postgis\"\]\[\"dbname\"\].*|config\[\"postgis\"\]\[\"dbname\"\]=\"${OSM_DB}\"|" configure.py
  79. ./configure.py
  80. ./make.py
  81. cd ../OSMBright/
  82. carto project.mml > OSMBright.xml
  83. fi
  84. OSM_STYLE_XML='/usr/local/share/maps/style/OSMBright/OSMBright.xml'
  85. }
  86. function style_osm_carto(){
  87. apt-get -y install ttf-dejavu fonts-droid ttf-unifont fonts-sipa-arundina fonts-sil-padauk fonts-khmeros ttf-indic-fonts-core fonts-taml-tscu ttf-kannada-fonts
  88. cd /usr/local/share/maps/style
  89. if [ ! -d openstreetmap-carto-master ]; then
  90. wget https://github.com/gravitystorm/openstreetmap-carto/archive/master.zip
  91. if [ $? -ne 0 ]; then echo "Error: Failed to download carto style"; exit 1; fi
  92. unzip master.zip
  93. if [ $? -ne 0 ]; then echo "Error: Failed to unzip carto style"; exit 1; fi
  94. rm master.zip
  95. fi
  96. cd openstreetmap-carto-master;
  97. if [ $(find data/ -type f -name "*.shp" | wc -l) -ne 6 ]; then
  98. ./get-shapefiles.sh
  99. rm data/*.zip data/world_boundaries-spherical.tgz
  100. fi
  101. if [ ! -f project.mml ]; then
  102. ./scripts/yaml2mml.py < project.yaml > project.mml
  103. fi
  104. carto project.mml > osm-carto.xml
  105. osm2pgsql_OPTS+=' --style /usr/local/share/maps/style/openstreetmap-carto-master/openstreetmap-carto.style'
  106. OSM_STYLE_XML='/usr/local/share/maps/style/openstreetmap-carto-master/osm-carto.xml'
  107. }
  108. function enable_osm_updates(){
  109. apt-get -y install osmosis
  110. if [ $? -ne 0 ]; then echo "Error: Apt failed ot install osmosis"; exit 1; fi
  111. export WORKDIR_OSM=/home/${OSM_USER}/.osmosis
  112. if [ $(grep -c 'WORKDIR_OSM' /etc/environment) -eq 0 ]; then
  113. echo 'export WORKDIR_OSM=/home/tile/.osmosis' >> /etc/environment
  114. mkdir -p $WORKDIR_OSM
  115. osmosis --read-replication-interval-init workingDirectory=${WORKDIR_OSM}
  116. fi
  117. #2. Generating state.txt
  118. if [ ! -f ${WORKDIR_OSM}/state.txt ]; then
  119. #NOTE: If you want hourly updates set stream=hourly
  120. STATE_URL="http://osm.personalwerk.de/replicate-sequences/?Y=$(date '+%Y')&m=$(date '+%m')&d=$(date '+%d')&H=$(date '+%H')&i=$(date '+%M')&s=$(date '+%S')&stream=day"
  121. wget -O${WORKDIR_OSM}/state.txt ${STATE_URL}
  122. if [ $? -ne 0 ]; then echo "Error: Failed to get Osmosis state.txt"; exit 1; fi
  123. fi
  124. #3. Fix configuration.txt
  125. #Get the URL from http://download.geofabrik.de/europe/germany.html
  126. #example PBF_URL='http://download.geofabrik.de/europe/germany-latest.osm.pbf'
  127. UPDATE_URL="$(echo ${PBF_URL} | sed 's/latest.osm.pbf/updates/')"
  128. sed -i.save "s|#\?baseUrl=.*|baseUrl=${UPDATE_URL}|" ${WORKDIR_OSM}/configuration.txt
  129. #4. Add step 4 to cron, to make it run every day
  130. if [ ! -f /etc/cron.daily/osm-update.sh ]; then
  131. echo >/etc/cron.daily/osm-update.sh <<CMD_EOF
  132. #!/bin/bash
  133. export WORKDIR_OSM=/home/${OSM_USER}/.osmosis
  134. export PGPASSWORD="${MAPFIG_PG_PASS}"
  135. osmosis --read-replication-interval workingDirectory=${WORKDIR_OSM} --simplify-change --write-xml-change /tmp/changes.osc.gz
  136. sudo -u postgres osm2pgsql --append ${osm2pgsql_OPTS} /tmp/changes.osc.gz
  137. CMD_EOF
  138. chmod +x /etc/cron.daily/osm-update.sh
  139. fi
  140. }
  141. #Steps
  142. #1 Update ATP and isntall needed packages
  143. apt-get clean
  144. apt-get update
  145. if [ $? -ne 0 ]; then echo "Error: Apt update failed"; exit 1; fi
  146. apt-get -y install libboost-all-dev subversion git-core tar unzip wget bzip2 \
  147. build-essential autoconf libtool libxml2-dev libgeos-dev \
  148. libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node \
  149. munin libprotobuf-c0-dev protobuf-c-compiler libfreetype6-dev \
  150. libpng12-dev libtiff4-dev libicu-dev libgdal-dev libcairo-dev \
  151. libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev \
  152. ttf-unifont fonts-arphic-ukai fonts-arphic-uming fonts-thai-tlwg \
  153. lua5.1 liblua5.1-dev libgeotiff-epsg node-carto \
  154. postgresql postgresql-contrib postgis postgresql-9.3-postgis-2.1 \
  155. php5 libapache2-mod-php5
  156. if [ $? -ne 0 ]; then echo "Error: Apt install failed"; exit 1; fi
  157. #3 Create system user
  158. if [ $(grep -c ${OSM_USER} /etc/passwd) -eq 0 ]; then #if we don't have the OSM user
  159. useradd -m ${OSM_USER}
  160. if [ $? -ne 0 ]; then echo "Error: Failed to add OSM user"; exit 1; fi
  161. echo ${OSM_USER}:${OSM_USER_PASS} | chpasswd
  162. if [ $? -ne 0 ]; then echo "Error: Fail to set OSM user pass";exit 1; fi
  163. fi
  164. cat >/etc/postgresql/9.3/main/pg_hba.conf <<CMD_EOF
  165. local all all trust
  166. host all all 127.0.0.1 255.255.255.255 md5
  167. host all all 0.0.0.0/0 md5
  168. host all all ::1/128 md5
  169. CMD_EOF
  170. service postgresql restart
  171. if [ $(psql -Upostgres -c "select usename from pg_user" | grep -m 1 -c ${OSM_USER}) -eq 0 ]; then
  172. psql -Upostgres -c "create user ${OSM_USER} with password '${OSM_PG_PASS}';"
  173. if [ $? -eq 1 ]; then echo "Error: Can't add osm user."; exit 1; fi
  174. else
  175. psql -Upostgres -c "alter user ${OSM_USER} with password '${OSM_PG_PASS}';"
  176. if [ $? -eq 1 ]; then echo "Error: Can't alter osm user."; exit 1; fi
  177. fi
  178. if [ $(psql -Upostgres -c "select datname from pg_database" | grep -m 1 -c ${OSM_DB}) -eq 0 ]; then
  179. psql -Upostgres -c "create database ${OSM_DB} owner=${OSM_USER};"
  180. if [ $? -eq 1 ]; then echo "Error: Can't add osm database."; exit 1; fi
  181. fi
  182. psql -Upostgres ${OSM_DB} <<EOF_CMD
  183. \c ${OSM_DB}
  184. CREATE EXTENSION hstore;
  185. CREATE EXTENSION postgis;
  186. ALTER TABLE geometry_columns OWNER TO ${OSM_USER};
  187. ALTER TABLE spatial_ref_sys OWNER TO ${OSM_USER};
  188. EOF_CMD
  189. if [ $? -ne 0 ]; then echo "Error: Postgre failed to create extension"; exit 1; fi
  190. #5 Installing osm2pgsql and mapnik
  191. #osm2pgsql has pg-9.3 dependency
  192. apt-get install -y osm2pgsql python-mapnik2 libmapnik2.2 mapnik-utils libmapnik2-dev
  193. #7 Install modtile and renderd
  194. mkdir -p ~/src
  195. if [ -z "$(which renderd)" ]; then #if mapnik is not installed
  196. cd ~/src
  197. git clone git://github.com/openstreetmap/mod_tile.git
  198. if [ ! -d mod_tile ]; then "Error: Failed to download mod_tile"; exit 1; fi
  199. cd mod_tile
  200. ./autogen.sh
  201. ./configure
  202. #install breaks if dir exists
  203. if [ -d /var/lib/mod_tile ]; then rm -r /var/lib/mod_tile; fi
  204. make
  205. make install
  206. make install-mod_tile
  207. ldconfig
  208. cp debian/renderd.init /etc/init.d/renderd
  209. #Update daemon config
  210. sed -i.save 's|^DAEMON=.*|DAEMON=/usr/local/bin/$NAME|' /etc/init.d/renderd
  211. sed -i.save 's|^DAEMON_ARGS=.*|DAEMON_ARGS="-c /usr/local/etc/renderd.conf"|' /etc/init.d/renderd
  212. sed -i.save "s|^RUNASUSER=.*|RUNASUSER=${OSM_USER}|" /etc/init.d/renderd
  213. chmod u+x /etc/init.d/renderd
  214. ln -sf /etc/init.d/renderd /etc/rc2.d/S20renderd
  215. mkdir -p /var/run/renderd
  216. chown ${OSM_USER}:${OSM_USER} /var/run/renderd
  217. cd ../
  218. rm -rf mod_tile
  219. fi
  220. #8 Stylesheet configuration
  221. mkdir -p /usr/local/share/maps/style
  222. case $OSM_STYLE in
  223. bright)
  224. style_osm_bright
  225. ;;
  226. carto)
  227. style_osm_carto
  228. ;;
  229. *)
  230. echo "Error: Unknown style"; exit 1;
  231. ;;
  232. esac
  233. #11 Setting up your webserver
  234. MAPNIK_PLUG=$(mapnik-config --input-plugins)
  235. #remove commented lines, because daemon produces warning!
  236. sed -i.save '/^;/d' /usr/local/etc/renderd.conf
  237. sed -i.save 's/;socketname/socketname/' /usr/local/etc/renderd.conf
  238. sed -i.save "s|^plugins_dir=.*|plugins_dir=${MAPNIK_PLUG}|" /usr/local/etc/renderd.conf
  239. sed -i.save 's|^font_dir=.*|font_dir=/usr/share/fonts/truetype/|' /usr/local/etc/renderd.conf
  240. sed -i.save "s|^XML=.*|XML=${OSM_STYLE_XML}|" /usr/local/etc/renderd.conf
  241. sed -i.save 's|^HOST=.*|HOST=localhost|' /usr/local/etc/renderd.conf
  242. mkdir -p /var/run/renderd
  243. chown ${OSM_USER}:${OSM_USER} /var/run/renderd
  244. mkdir -p /var/lib/mod_tile
  245. chown ${OSM_USER}:${OSM_USER} /var/lib/mod_tile
  246. #12 Configure mod_tile
  247. if [ ! -f /etc/apache2/conf-available/mod_tile.conf ]; then
  248. echo 'LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so' > /etc/apache2/conf-available/mod_tile.conf
  249. echo 'LoadTileConfigFile /usr/local/etc/renderd.conf
  250. ModTileRenderdSocketName /var/run/renderd/renderd.sock
  251. # Timeout before giving up for a tile to be rendered
  252. ModTileRequestTimeout 0
  253. # Timeout before giving up for a tile to be rendered that is otherwise missing
  254. ModTileMissingRequestTimeout 30' > /etc/apache2/sites-available/tile.conf
  255. sed -i.save "/ServerAdmin/aInclude /etc/apache2/sites-available/tile.conf" /etc/apache2/sites-available/000-default.conf
  256. a2enconf mod_tile
  257. service apache2 reload
  258. fi
  259. #Download html pages
  260. rm /var/www/html/index.html
  261. for p in openlayers-example leaflet-example index; do
  262. wget -P/var/www/html/ https://cdn.acugis.com/osm-assets/htmls/${p}.html
  263. done
  264. sed -i.save "s|localhost|$(hostname -I | tr -d ' ')|" /var/www/html/leaflet-example.html
  265. #Set Leaflet point of view
  266. LOC_NAME=$(echo ${PBF_URL##*/} | sed 's/\(.*\)-latest.*/\1/')
  267. cat >/tmp/latlong.php <<EOF
  268. <?php
  269. \$Address = urlencode(\$argv[1]);
  270. \$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".\$Address."&sensor=true";
  271. \$xml = simplexml_load_file(\$request_url) or die("url not loading");
  272. \$status = \$xml->status;
  273. if (\$status=="OK") {
  274. \$Lat = \$xml->result->geometry->location->lat;
  275. \$Lon = \$xml->result->geometry->location->lng;
  276. \$LatLng = "\$Lat,\$Lon";
  277. echo "\$LatLng";
  278. }
  279. ?>
  280. EOF
  281. echo "Updating lat,long for ${LOC_NAME} in Leaflet..."
  282. LOC_LATLONG=$(php /tmp/latlong.php "${LOC_NAME}")
  283. if [ -z "${LOC_LATLONG}" ]; then
  284. echo "Error: Lat/Long for ${LOC_NAME} not found";
  285. echo "Update manually in /var/www/html/leaflet-example.html"
  286. else
  287. echo "Lat/Long for ${LOC_NAME} set to ${LOC_LATLONG}"
  288. sed -i.save "s/\.setView(\[[0-9]\+\.[0-9]\+,[ \t]*-\?[0-9]\+\.[0-9]\+/.setView([${LOC_LATLONG}/" /var/www/html/leaflet-example.html
  289. sed -i.save "s/L\.marker(\[[0-9]\+\.[0-9]\+,[ \t]*-\?[0-9]\+\.[0-9]\+/L.marker([${LOC_LATLONG}/" /var/www/html/leaflet-example.html
  290. fi
  291. if [ "${WEB_MODE}" == 'ssl' ]; then
  292. mkdir -p /etc/apache2/ssl/
  293. #create SSL certificates
  294. if [ ! -f /etc/apache2/ssl/server.key -o ! -f /etc/apache2/ssl/server.crt ]; then
  295. SSL_PASS=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32);
  296. if [ $(grep -m 1 -c 'ssl pass' /root/auth.txt) -eq 0 ]; then
  297. echo "ssl pass: ${SSL_PASS}" >> /root/auth.txt
  298. fi
  299. cd /etc/apache2/ssl/
  300. openssl genrsa -des3 -passout pass:${SSL_PASS} -out server.key 1024
  301. openssl rsa -in server.key -passin pass:${SSL_PASS} -out server.key
  302. chmod 400 server.key
  303. openssl req -new -key server.key -days 3650 -out server.crt -passin pass:${SSL_PASS} -x509 -subj '/C=CA/ST=Frankfurt/L=Frankfurt/O=acuciva-de.com/CN=acuciva-de.com/emailAddress=info@acugis.com'
  304. chown apache:apache server.key server.crt
  305. fi
  306. cat >/etc/apache2/sites-available/000-default-ssl.conf <<CMD_EOF
  307. <IfModule mod_ssl.c>
  308. <VirtualHost _default_:443>
  309. ServerAdmin webmaster@localhost
  310. Include /etc/apache2/sites-available/tile.conf
  311. DocumentRoot /var/www/html
  312. #LogLevel info ssl:warn
  313. ErrorLog ${APACHE_LOG_DIR}/error.log
  314. CustomLog ${APACHE_LOG_DIR}/access.log combined
  315. SSLEngine on
  316. SSLCertificateFile /etc/apache2/ssl/server.crt
  317. SSLCertificateKeyFile /etc/apache2/ssl/server.key
  318. #SSLCertificateChainFile /etc/apache2/ssl/DigiCertCA.crt
  319. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  320. SSLOptions +StdEnvVars
  321. </FilesMatch>
  322. <Directory /usr/lib/cgi-bin>
  323. SSLOptions +StdEnvVars
  324. </Directory>
  325. BrowserMatch "MSIE [2-6]" \
  326. nokeepalive ssl-unclean-shutdown \
  327. downgrade-1.0 force-response-1.0
  328. # MSIE 7 and newer should be able to use keepalive
  329. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  330. </VirtualHost>
  331. </IfModule>
  332. CMD_EOF
  333. ln -sf /etc/apache2/sites-available/000-default-ssl.conf /etc/apache2/sites-enabled/
  334. a2enmod ssl
  335. else
  336. cat >/etc/apache2/sites-available/000-default.conf <<CMD_EOF
  337. <VirtualHost _default_:80>
  338. ServerAdmin webmaster@localhost
  339. Include /etc/apache2/sites-available/tile.conf
  340. DocumentRoot /var/www/html
  341. ServerName ${VHOST}
  342. ErrorLog ${APACHE_LOG_DIR}/error.log
  343. CustomLog ${APACHE_LOG_DIR}/access.log combined
  344. </VirtualHost>
  345. CMD_EOF
  346. ln -sf /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/
  347. fi
  348. #13 Tuning your system
  349. PG_VER=$(pg_config | grep '^VERSION' | cut -f4 -d' ' | cut -f1,2 -d.)
  350. sed -i 's/#\?shared_buffers.*/shared_buffers = 128MB/' /etc/postgresql/${PG_VER}/main/postgresql.conf
  351. sed -i 's/#\?checkpoint_segments.*/checkpoint_segments = 20/' /etc/postgresql/${PG_VER}/main/postgresql.conf
  352. sed -i 's/#\?maintenance_work_mem.*/maintenance_work_mem = 256MB/' /etc/postgresql/${PG_VER}/main/postgresql.conf
  353. #Turn off autovacuum and fsync during load of PBF
  354. sed -i 's/#\?fsync.*/fsync = off/' /etc/postgresql/${PG_VER}/main/postgresql.conf
  355. sed -i 's/#\?autovacuum.*/autovacuum = off/' /etc/postgresql/${PG_VER}/main/postgresql.conf
  356. service postgresql restart
  357. if [ $(grep -c 'kernel.shmmax=268435456' /etc/sysctl.conf) -eq 0 ]; then
  358. echo '# Increase kernel shared memory segments - needed for large databases
  359. kernel.shmmax=268435456' >> /etc/sysctl.conf
  360. sysctl -w kernel.shmmax=268435456
  361. fi
  362. #13. Loading data into your server
  363. PBF_FILE="/home/${OSM_USER}/${PBF_URL##*/}"
  364. cd /home/${OSM_USER}
  365. if [ ! -f ${PBF_FILE} ]; then
  366. wget ${PBF_URL}
  367. if [ $? -ne 0 ]; then echo "Error: Failed to download ${PBF_URL}"; exit 1; fi
  368. chown ${OSM_USER}:${OSM_USER} ${PBF_FILE}
  369. fi
  370. sudo -u ${OSM_USER} osm2pgsql ${osm2pgsql_OPTS} ${PBF_FILE}
  371. if [ $? -eq 0 ]; then #If import went good
  372. rm -rf ${PBF_FILE}
  373. fi
  374. #Turn on autovacuum and fsync during load of PBF
  375. sed -i.save 's/#\?fsync.*/fsync = on/' /etc/postgresql/${PG_VER}/main/postgresql.conf
  376. sed -i.save 's/#\?autovacuum.*/autovacuum = on/' /etc/postgresql/${PG_VER}/main/postgresql.conf
  377. ldconfig
  378. enable_osm_updates
  379. #Restart services
  380. service postgresql restart
  381. service apache2 reload
  382. service renderd restart
  383. echo <<EOF
  384. OSM server install done.
  385. Your authentication data is in /root/auth.txt
  386. If you have CA signed certificates, replace server.crt and server.key in /etc/apache2/ssl
  387. EOF

comments powered by Disqus