aboutsummaryrefslogtreecommitdiffstats
path: root/teaqueue-server
diff options
context:
space:
mode:
Diffstat (limited to 'teaqueue-server')
-rwxr-xr-xteaqueue-server53
1 files changed, 53 insertions, 0 deletions
diff --git a/teaqueue-server b/teaqueue-server
new file mode 100755
index 0000000..02c8b6a
--- /dev/null
+++ b/teaqueue-server
@@ -0,0 +1,53 @@
+#!/bin/bash
+# use bash for trap
+
+set -eu
+
+# default options
+queuefn="queue.txt"
+donefn="done.txt"
+port=1340
+
+usage()
+{
+ cat <<EOF
+Usage: $0 [OPTIONS...]
+
+Feeds lines from a text file to teaqueue-clients.
+
+Options:
+ -h, --help show usage
+ -p, --port what port to use (default: 1340)
+ -q, --queue what filename to use as input queue
+ -d, --done what filename to use for storing done items
+EOF
+}
+
+# arg parsing
+TEMP=$(getopt -o hH:p: --long help,host,port -n teaqueue-client -- "$@")
+if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
+eval set -- "$TEMP"
+while true; do
+ case "$1" in
+ -h|--help) usage; exit 0;;
+ -p|--port) port="$2"; shift 2;;
+ -q|--queue) queuefn="$2"; shift 2;;
+ -d|--done) donefn="$2"; shift 2;;
+ --) shift; break;;
+ *) echo "Arguments parsing error" >&2; exit 1;;
+ esac
+done
+
+my_exit()
+{
+ mv "${queuefn}" "${queuefn}.old"
+ comm --nocheck-order -23 "${queuefn}.old" "${donefn}" > "${queuefn}"
+ exit 0
+}
+
+trap my_exit SIGINT SIGTERM
+
+cat "${queuefn}" | while read -r line; do
+ printf "%s\n" "$line" | nc -q0 -l -p $port
+ printf "%s\n" "$line"
+done > "${donefn}"