Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Usage:
- # $ ./track.sh [-x] <filepath> <username> <password> <host> <bag> [title]
- #
- # title is optionally derived from filepath
- set -e
- #set -x
- # TODO: use optparse
- if [ "$1" = "-x" ]; then
- norepeat=true
- shift
- fi
- filepath=${1:?}
- username=${2:?}
- password=${3:?}
- host=${4:?}
- bag=${5:?}
- title=${6:-}
- interval=5
- # derive tiddler title from filename
- if [ -z "$title" ]; then
- title=`basename $filepath | sed -e "s/^\(.*\)\..*$/\1/"`
- fi
- cmd="stat --format=%y $filepath" # Linux
- #cmd="stat -f '%m' $filepath" # BSD
- options="-u $username:$password"
- #trap "echo \"deleting $title\"; sleep 2; exit" 2 # XXX: disabled
- options="$options -X PUT"
- if [ -z "$norepeat" ]; then
- lastmod=`$cmd`
- else
- lastmod=none
- fi
- while true; do
- if [ -z "$norepeat" ]; then
- timestamp=`$cmd`
- fi
- if [ "$lastmod" != "$timestamp" ]; then
- {
- echo "type: text/javascript";
- echo "tags: dev systemConfig";
- echo;
- cat $filepath;
- } | \
- curl $options -H "Content-Type: text/plain" --data-binary @- \
- "$host/bags/$bag/tiddlers/$title"
- if [ -z "$norepeat" ]; then
- lastmod=$timestamp
- echo "updating $title ($lastmod)"
- notify-send TiddlyWeb "updating $title ($lastmod)" # XXX: Ubuntu-specific
- sleep $interval
- else
- exit 0
- fi
- fi
- done
Add Comment
Please, Sign In to add comment