Bring some more bits of the planet server under chef control
[chef.git] / cookbooks / planet / files / default / bin / planet2pbf
1 #!/bin/bash
2
3 # DO NOT EDIT - This file is being maintained by Chef
4
5 set -e
6 user=`whoami`
7 if [ "$user" != "www-data" ];
8         then
9                 echo 'Error: run as www-data'
10                 exit 1
11         fi
12
13 if [ -f /tmp/planet2pbf.lock ]; then
14         if [ "$(ps -p `cat /tmp/planet2pbf.lock` | wc -l)" -gt 1 ]; then
15                 echo planet2pbf process is still running
16                 exit 1
17         else
18                 # process not running, but lock file not deleted?
19                 rm /tmp/planet2pbf.lock
20         fi
21 fi
22 echo $$ >/tmp/planet2pbf.lock
23
24 YEARFULL=`TZ=GMT+24 date +%Y`
25
26 cd /store/planet/planet/
27 if [ -z $1 ]
28 then
29         YEAR=`TZ=GMT+24 date +%y`
30         MONTH=`TZ=GMT+24 date +%m`
31         DAY=`TZ=GMT+24 date +%d`
32         if [ -f ${YEARFULL}/planet-${YEAR}${MONTH}${DAY}.osm.bz2 -o -f ${YEARFULL}/.planet-${YEAR}${MONTH}${DAY}.osm.bz2.new ];
33         then
34                 planet=planet-${YEAR}${MONTH}${DAY}.osm
35         else
36                 echo Error /store/planet/planet/${YEARFULL}/planet-${YEAR}${MONTH}${DAY}.osm.bz2 not available
37                 exit 1
38         fi
39 else
40         planet=$1
41 fi
42 while [ -f ${YEARFULL}/.${planet}.bz2.new ]; 
43 do 
44         echo sleeping - ${planet}.bz2
45         sleep 300
46 done
47 if [ -f /store/planet/planet/${YEARFULL}/${planet}.bz2 ]
48 then
49         echo $planet
50         if [ -f /store/planet/pbf/${planet}.pbf ];
51         then
52                 echo Error: file /store/planet/pbf/${planet}.pbf exists
53                 exit 1
54         fi
55         JAVACMD_OPTIONS=-Xmx2048M
56         export JAVACMD_OPTIONS
57         pbzip2 -dc /store/planet/planet/${YEARFULL}/${planet}.bz2 | /home/grant/code/osmosis-0.43/bin/osmosis --read-xml - --buffer bufferCapacity=18000 --write-pbf /store/planet/pbf/${planet}.pbf
58         cd /store/planet/pbf/
59         md5sum ${planet}.pbf >${planet}.pbf.md5
60         ln -fs ${planet}.pbf planet-latest.osm.pbf
61         ln -fs ${planet}.pbf.md5 planet-latest.osm.pbf.md5
62 else
63         echo Error no file - ${planet}.bz2
64 fi
65
66 rm /tmp/planet2pbf.lock
67