timekeeper.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash -e
  2. cd $LEKTORDIR
  3. # the feed information
  4. ID='tag:example.com:timekeeper'
  5. HASH=$(printf $ID | sha1sum | awk '{ print $1; }' )
  6. # other metadata
  7. HOST=$(hostname)
  8. MAX=10
  9. # create the feed
  10. mkdir -p src/$HASH
  11. echo $ID >src/$HASH/id
  12. echo Timekeeper >src/$HASH/name
  13. mkdir -p "tmp/$HASH"
  14. mkdir -p "new/$HASH"
  15. # create entries every hour
  16. while true; do
  17. TIME=$(date '+%s')
  18. ENTRY="$HASH/$TIME.$$.$HOST"
  19. # if the file exists, wait two seconds and try again
  20. RETRY=0
  21. while [ -e $ENTRY ]
  22. do
  23. # if we've waited more than $MAX times, then
  24. # give up
  25. if [ $RETRY -gt $MAX ]; then
  26. exit 1
  27. fi
  28. sleep 2
  29. RETRY=$(expr $RETRY + 1)
  30. done
  31. # create the entry
  32. mkdir -p tmp/$ENTRY
  33. # create entry values
  34. echo 'Current Time' >tmp/$ENTRY/title
  35. echo $TIME >tmp/$ENTRY/content
  36. echo "tag:example.com:timekeeper#$TIME" >tmp/$ENTRY/id
  37. ln -s $LEKTORDIR/src/$HASH tmp/$ENTRY/feed
  38. # move the entry to the new location
  39. mv tmp/$ENTRY new/$ENTRY
  40. # wait for half an hour and do it again
  41. sleep 3600
  42. done