Guest User

Untitled

a guest
Jun 2nd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Usage:
  4. # $ ./track.sh [-x] <filepath> <username> <password> <host> <bag> [title]
  5. #
  6. # title is optionally derived from filepath
  7.  
  8. set -e
  9. #set -x
  10.  
  11. # TODO: use optparse
  12. if [ "$1" = "-x" ]; then
  13. norepeat=true
  14. shift
  15. fi
  16. filepath=${1:?}
  17. username=${2:?}
  18. password=${3:?}
  19. host=${4:?}
  20. bag=${5:?}
  21. title=${6:-}
  22.  
  23. interval=5
  24.  
  25. # derive tiddler title from filename
  26. if [ -z "$title" ]; then
  27. title=`basename $filepath | sed -e "s/^\(.*\)\..*$/\1/"`
  28. fi
  29.  
  30. cmd="stat --format=%y $filepath" # Linux
  31. #cmd="stat -f '%m' $filepath" # BSD
  32.  
  33. options="-u $username:$password"
  34.  
  35. #trap "echo \"deleting $title\"; sleep 2; exit" 2 # XXX: disabled
  36.  
  37. options="$options -X PUT"
  38. if [ -z "$norepeat" ]; then
  39. lastmod=`$cmd`
  40. else
  41. lastmod=none
  42. fi
  43. while true; do
  44. if [ -z "$norepeat" ]; then
  45. timestamp=`$cmd`
  46. fi
  47. if [ "$lastmod" != "$timestamp" ]; then
  48. {
  49. echo "type: text/javascript";
  50. echo "tags: dev systemConfig";
  51. echo;
  52. cat $filepath;
  53. } | \
  54. curl $options -H "Content-Type: text/plain" --data-binary @- \
  55. "$host/bags/$bag/tiddlers/$title"
  56. if [ -z "$norepeat" ]; then
  57. lastmod=$timestamp
  58. echo "updating $title ($lastmod)"
  59. notify-send TiddlyWeb "updating $title ($lastmod)" # XXX: Ubuntu-specific
  60. sleep $interval
  61. else
  62. exit 0
  63. fi
  64. fi
  65. done
Add Comment
Please, Sign In to add comment