init.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. #
  3. # need to TRUNCATE all data tables in postgresql before you run this!
  4. # TRUNCATE nodes, relations, relation_members, users, ways, way_nodes;
  5. #
  6. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  7. #
  8. #variables to set
  9. #
  10. #paths
  11. OSMOSIS=osmosis
  12. OSMFILTER=osmfilter
  13. OSMCONVERT=osmconvert
  14. #path to working directory
  15. WORK_DIR=/home/xsvana00/data
  16. #path to logfile
  17. LOGFILE=/home/xsvana00/update.log
  18. LASTUPDATE=/var/www/html/xsvana00/last_update.txt
  19. #filenames
  20. GEOFABRIK_FILE=czech-republic-latest.osm.pbf
  21. FIRST_IMPORT=first_import.pbf
  22. PRESENT_DUMP=converted_dump.o5m
  23. PRESENT_FILTERED_DUMP=filtered_dump.o5m
  24. UPDATE=update_database.osc
  25. #database credential
  26. AUTH_FILE=$HOME/.osmosis.auth
  27. LOCK=/tmp/xsvana00.lock
  28. test -f $LOCK && { echo "Lock file $LOCK exists. Exiting..." >>$LOGFILE; exit; }
  29. touch $LOCK
  30. function finish {
  31. rm $LOCK
  32. }
  33. trap finish EXIT
  34. echo ------------------------------------------------------------ >> $LOGFILE
  35. CURRENT=`pwd`
  36. cd $WORK_DIR
  37. rm $GEOFABRIK_FILE
  38. wget http://download.geofabrik.de/europe/$GEOFABRIK_FILE
  39. ret=$?
  40. echo `date` >> $LOGFILE
  41. if [ "$ret" != "0" ]; then
  42. echo ERROR: Unsuccesful download of OSM data. [$ret] >> $LOGFILE
  43. exit 1
  44. else
  45. echo OSM data downloaded. [$ret] >> $LOGFILE
  46. fi
  47. $OSMCONVERT --out-o5m $GEOFABRIK_FILE >$PRESENT_DUMP
  48. ret=$?
  49. echo `date` >> $LOGFILE
  50. if [ "$ret" != "0" ]; then
  51. echo ERROR: Convert operation failed. [$ret] >> $LOGFILE
  52. exit 1
  53. else
  54. echo OSM download succesfully converted. [$ret] >> $LOGFILE
  55. fi
  56. $OSMFILTER $PRESENT_DUMP --keep-ways="highway=" --keep="operator=cz:KČT" --out-o5m > $PRESENT_FILTERED_DUMP
  57. ret=$?
  58. echo `date` >> $LOGFILE
  59. if [ "$ret" != "0" ]; then
  60. echo ERROR: Filter operation failed. [$ret] >> $LOGFILE
  61. exit 1
  62. else
  63. echo OSM download succesfully filtered. [$ret] >> $LOGFILE
  64. fi
  65. $OSMCONVERT --out-pbf $PRESENT_FILTERED_DUMP >$FIRST_IMPORT
  66. $OSMOSIS --rb $FIRST_IMPORT --wp authFile=$AUTH_FILE
  67. ret=$?
  68. echo `date` >> $LOGFILE
  69. if [ "$ret" != "0" ]; then
  70. echo ERROR: Failed to import database. [$ret] >> $LOGFILE
  71. exit 1
  72. else
  73. echo "Database imported. [$ret]" >> $LOGFILE
  74. echo `date '+%d.%m.%Y %H:%M'` > $LASTUPDATE
  75. php /var/www/html/xsvana00/tables/php/saveStats.php
  76. fi
  77. rm $FIRST_IMPORT
  78. rm $GEOFABRIK_FILE
  79. cd $CURRENT
  80. exit 0