update.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  2. #
  3. #Petr Svana, March 2015
  4. #
  5. #change your stuff here
  6. #--------------------------------------------------------
  7. #path to working directory where files will be stored
  8. WORK_DIR=/home/xsvana00/data
  9. #path to logfile
  10. LOGFILE=/home/xsvana00/update.log
  11. #path to web root - where to call PHP scripts and save timestamp
  12. WEB_ROOT=/var/www/html/OsmHiCheck
  13. #database credentials for osmosis
  14. AUTH_FILE=$HOME/.osmosis.auth
  15. #--------------------------------------------------------
  16. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  17. OSMOSIS=osmosis
  18. OSMFILTER=osmfilter
  19. OSMUPDATE=osmupdate
  20. OSMCONVERT=osmconvert
  21. #filenames
  22. PRESENT_DUMP=converted_dump.o5m
  23. PRESENT_FILTERED_DUMP=filtered_dump.o5m
  24. NEXT_DUMP=updated_converted_dump.o5m
  25. NEXT_FILTERED_DUMP=updated_filtered_dump.o5m
  26. UPDATE=update_database.osc
  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. #clip by CZ polygon - got it on http://download.geofabrik.de/europe/czech-republic.html
  38. $OSMUPDATE $PRESENT_DUMP $NEXT_DUMP -B=czech-republic.poly
  39. ret=$?
  40. echo `date` >> $LOGFILE
  41. if [ "$ret" = "21" ]; then
  42. echo NOTICE: Your OSM file is already up-to-date. Aborting... >> $LOGFILE
  43. echo `date '+%d.%m.%Y %H:%M'` > $WEB_ROOT/last_update.txt
  44. exit 0
  45. elif [ "$ret" != "0" ]; then
  46. echo ERROR: Unsuccesful download of updated dump. [$ret] >> $LOGFILE
  47. exit 1
  48. else
  49. echo Updated dump downloaded. [$ret] >> $LOGFILE
  50. fi
  51. $OSMFILTER $NEXT_DUMP --keep-ways="highway=" --keep="operator=cz:KČT information=guidepost tourism=information" --out-o5m > $NEXT_FILTERED_DUMP
  52. ret=$?
  53. echo `date` >> $LOGFILE
  54. if [ "$ret" != "0" ]; then
  55. echo ERROR: Filter operation failed. [$ret] >> $LOGFILE
  56. exit 1
  57. else
  58. echo Updated dump succesfully filtered. [$ret] >> $LOGFILE
  59. fi
  60. $OSMCONVERT $PRESENT_FILTERED_DUMP $NEXT_FILTERED_DUMP --diff -o=$UPDATE
  61. ret=$?
  62. echo `date` >> $LOGFILE
  63. if [ "$ret" != "0" ]; then
  64. echo ERROR: Convert operation failed. [$ret] >> $LOGFILE
  65. exit 1
  66. else
  67. echo Filtered updated dump succesfully converted. [$ret] >> $LOGFILE
  68. fi
  69. $OSMOSIS --rxc file=$UPDATE --wpc authFile=$AUTH_FILE
  70. ret=$?
  71. echo `date` >> $LOGFILE
  72. if [ "$ret" != "0" ]; then
  73. echo ERROR: Failed to update database. [$ret] >> $LOGFILE
  74. exit 1
  75. else
  76. echo "Database updated. [$ret]" >> $LOGFILE
  77. echo `date '+%d.%m.%Y %H:%M'` > $WEB_ROOT/last_update.txt
  78. php $WEB_ROOT/tables/php/saveStats.php
  79. fi
  80. #remove old unused stuff
  81. mv $NEXT_DUMP $PRESENT_DUMP
  82. mv $NEXT_FILTERED_DUMP $PRESENT_FILTERED_DUMP
  83. rm $UPDATE
  84. cd $CURRENT
  85. exit 0