From cf895c385104c0013438a18b28f48adfda1e5ae6 Mon Sep 17 00:00:00 2001 From: southerntofu Date: Mon, 27 Apr 2020 01:31:50 +0200 Subject: [PATCH] =?UTF-8?q?Pemi=C3=A8re=20version=20de=20webhook-run?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webhook-run | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 webhook-run diff --git a/webhook-run b/webhook-run new file mode 100644 index 0000000..b12dcc8 --- /dev/null +++ b/webhook-run @@ -0,0 +1,56 @@ +#! /bin/bash + +if [[ $EUID != 0 ]]; then + # We're not root... yet! + sudo webhook-run $@ + exit $? +fi + +# Ok now we're root + +from_hex() { + echo -n "$@" | base64 -d +} + +from_url() { + echo -n "$@" | base64 +} + +db=/home/webhook/webhooks + +# We only take one argument! +r="$1" +rhex="$(from_url "$r")" + +# Don't loop when nothing matches, plz? +shopt -s nullglob + +for i in $db/"$rhex".*; do + # Strip $rhex prefix + user="$(basename "$i")" + user="${user#$rhex.}" + + # Now find the user's git-build tasks subscribing to the repo + #r="$(from_hex "$rhex")" + gitbuild=/home/"$user"/.git-build + if [ ! -d "$gitbuild" ]; then + echo "$user has no ~/.git-build/ so we skip" + continue + fi + + # Could use some grep-fu here, but maybe not intoduce another dependency? + FOUND=0 + for f in $gitbuild/*.source; do + if [[ "$r" = "$(cat "$f")" ]]; then + FOUND=1 + task="$(basename "$f" .source)" + echo "$task for $user" + bin="$(which git-build.sh)" + sudo -u "$user" bash "$bin" "$t" + fi + done + + if [[ $FOUND = 0 ]]; then + echo "User $user is subscribed to $r but no matching task was found" + fi +done