Pemière version de webhook-run
This commit is contained in:
parent
dd413b5616
commit
cf895c3851
|
@ -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
|
Reference in New Issue