From 604f3d64764270c052cfb43081ec522237bbdb75 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Fri, 5 May 2017 11:28:51 +0200 Subject: Massive add for all draft stuff to keep it in sync --- draft/uftp/sinkdo.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 draft/uftp/sinkdo.sh (limited to 'draft/uftp/sinkdo.sh') diff --git a/draft/uftp/sinkdo.sh b/draft/uftp/sinkdo.sh new file mode 100755 index 0000000..1b46437 --- /dev/null +++ b/draft/uftp/sinkdo.sh @@ -0,0 +1,57 @@ +#!/bin/busybox sh + +if [ $# -ne 2 ] +then cat < +EOT + exit 1 +fi + +LANDDIR=$1 +SINKDIR=$2 +cd "$LANDDIR" || exit 2 + +curtask="(start)" +while true +do + f=$(ls | head -n1) + if [ -z "$f" ] + then sleep 1 + continue + fi + if [ ! -f "$f" -o ! -r "$f" ] + then echo "'$LANDDIR/$f' is not a readable file" >&2 + exit 2 + fi + size=$(stat -c'%s' -- "$f") + task=${f:0:2} + if [ "$curtask" == "$task" ] + then # Next file of an already started task + mv "$f" "$SINKDIR/" + else # Switch to the next task + if [ -d "$SINKDIR" ] + then # Inform sinkcat about end-of-data + touch -- "$SINKDIR/zz" + wait + # sinkcat always rmdir "$SINKDIR" on normal exit + if [ -d "$SINKDIR" ] + then echo "Task $task has ran into troubles" >&2 + exit 3 + fi + fi + echo "Switching from task $curtask to $task" >&2 + curtask=$task + if [ "$task" == "99" ] + then # Normal exit condition + rm -v "$f" >&2 + reset + echo "All task completed sucessfully" >&2 + exit 0 + else # Start a new task + chmod +x -- "$f" # XXX Checks on $f (is a script ?) + sinkcat.sh $SINKDIR | "./$f" & + while [ ! -d "$SINKDIR" ]; do sleep 1; done + rm -v "$f" >&2 + fi + fi +done -- cgit v1.2.3