summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/intentions-queue53
1 files changed, 53 insertions, 0 deletions
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}"
+}