From f67e43ca9ba64ffdfa4c41614ce62b81936f6e4b Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 30 Jan 2020 10:44:25 +0100 Subject: lib/intentions-queue: a start --- lib/intentions-queue | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'lib') diff --git a/lib/intentions-queue b/lib/intentions-queue index 56742fa..6710eb5 100755 --- a/lib/intentions-queue +++ b/lib/intentions-queue @@ -26,3 +26,56 @@ fi # 3. update mysql database # 4. upload database to mirror # 5. update packages on mirror + +# intent_something +# create an intention, provided on stdin +# note, that this function is not thread-safe +intent_something() { + local next_number + next_number=$(( + $( + find "${intentions_directory}" \ + -maxdepth 1 \ + -type f \ + -name 'intention.*' \ + -printf '%f\n' \ + | sed ' + s/^intention\.// + t + d + ' \ + | sort -nr \ + | grep -xm1 '[0-9]\+' \ + || echo 0 + )+1 + )) + { + printf '%s\n' \ + '#!/bin/sh' \ + 'set -e' + cat + printf 'rm "%s"\n' "${intentions_directory}/intention.${next_number}" + } > "${intentions_directory}/intention.${next_number}" + chmod +x "${intentions_directory}/intention.${next_number}" +} + +# execute_intention +# executes the next intention +execute_intention() { + local next_number + next_number=$( + find "${intentions_directory}" \ + -maxdepth 1 \ + -type f \ + -name 'intention.*' \ + -printf '%f\n' \ + | sed ' + s/^intention\.// + t + d + ' \ + | sort -n \ + | grep -xm1 '[0-9]\+' + ) || return 0 + "${intentions_directory}/intention.${next_number}" +} -- cgit v1.2.3