summaryrefslogtreecommitdiff
path: root/examples/mkevents
blob: 0c25233d34283b73f7498fd56a363fa5ace3cde1 (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2013 Jonas Smedegaard <dr@jones.dk>
  4. # Description: render and publish event webpage from RDF data
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. set -e
  19. # defaults sensible for the author when invoked from project root
  20. outfile=events.html
  21. infiles="data/*/*.ttl data/*/*/*.ttl"
  22. rsync_credentials=coreander
  23. rsync_path=/home/jonas/public_websites/data.biks.dk/events/index.html
  24. script=bin/rdf2events
  25. # make backup of eventual existing output
  26. if [ -f $outfile~ ]; then
  27. echo >&2 "ERROR: old tempfile $outfile~ exist!"
  28. echo >&2 "Check that script isn't already running, remove the file, and try again."
  29. exit 1
  30. fi
  31. echo "Rendering $outfile..."
  32. $script $infiles > $outfile~
  33. if [ -f $outfile ]; then
  34. echo "Comparing $outfile against older version..."
  35. errorcode=0
  36. diff -ruN $outfile $outfile~ || errorcode=$?
  37. case $errorcode in
  38. 0) echo "No changes from previous version"; exit;;
  39. 1) printf "Above are changes from previous version. ";;
  40. *) echo >&2 "ERROR: internal diff error!"; exit $errorcode;;
  41. esac
  42. fi
  43. # ask, publish, and update on-disk file for later comparison
  44. printf "OK to publish (y/N)? "
  45. read do_update
  46. case $do_update in
  47. y|Y)
  48. echo "Publishing $outfile..."
  49. rsync -a $outfile~ $rsync_credentials:$rsync_path
  50. mv -f $outfile~ $outfile
  51. echo "Done: $outfile published succesfully!"
  52. ;;
  53. *)
  54. rm $outfile~
  55. echo "Cancelled, as requested."
  56. exit
  57. ;;
  58. esac