Browse Source

Added simple bash scripts

Getty Ritter 8 years ago
parent
commit
744056aa15
2 changed files with 76 additions and 0 deletions
  1. 23 0
      util/simple-show.sh
  2. 53 0
      util/timekeeper.sh

+ 23 - 0
util/simple-show.sh

@@ -0,0 +1,23 @@
+#/bin/bash -e
+
+cd $LEKTORDIR
+
+for FEED in $(ls new)
+do
+    mkdir -p cur/$FEED
+
+    # print feed header
+    echo "In feed $(cat src/$FEED/name):"
+    echo
+
+    for ENTRY in $(ls new/$FEED)
+    do
+        # print entry
+        echo "$(cat new/$FEED/$ENTRY/title)"
+        cat new/$FEED/$ENTRY/content | head -n 4
+        echo
+
+        # move entry to `cur`
+        mv new/$FEED/$ENTRY cur/$FEED/$ENTRY
+    done
+done

+ 53 - 0
util/timekeeper.sh

@@ -0,0 +1,53 @@
+#!/bin/bash -e
+
+cd $LEKTORDIR
+
+# the feed information
+ID='tag:example.com:timekeeper'
+HASH=$(printf $ID | sha1sum | awk '{ print $1; }' )
+
+# other metadata
+HOST=$(hostname)
+MAX=10
+
+# create the feed
+mkdir -p src/$HASH
+echo $ID         >src/$HASH/id
+echo Timekeeper  >src/$HASH/name
+
+mkdir -p "tmp/$HASH"
+mkdir -p "new/$HASH"
+
+# create entries every hour
+while true; do
+    TIME=$(date '+%s')
+    ENTRY="$HASH/$TIME.$$.$HOST"
+
+    # if the file exists, wait two seconds and try again
+    RETRY=0
+    while [ -e $ENTRY ]
+    do
+        # if we've waited more than $MAX times, then
+        # give up
+        if [ $RETRY -gt $MAX ]; then
+            exit 1
+        fi
+        sleep 2
+        RETRY=$(expr $RETRY + 1)
+    done
+
+    # create the entry
+    mkdir -p tmp/$ENTRY
+
+    # create entry values
+    echo 'Current Time'                      >tmp/$ENTRY/title
+    echo $TIME                               >tmp/$ENTRY/content
+    echo "tag:example.com:timekeeper#$TIME"  >tmp/$ENTRY/id
+    ln -s $LEKTORDIR/src/$HASH                tmp/$ENTRY/feed
+
+    # move the entry to the new location
+    mv tmp/$ENTRY new/$ENTRY
+
+    # wait for half an hour and do it again
+    sleep 3600
+done