41 lines
921 B
Bash
41 lines
921 B
Bash
#! /bin/bash
|
|
|
|
if [[ $EUID != 0 ]]; then
|
|
# We're not root... yet!
|
|
# Let's not forget to define the db while we have forgehook $USER
|
|
# TODO: replace with ~/database
|
|
db=$HOME/webhooks
|
|
sudo forgehook-run $@
|
|
exit $?
|
|
fi
|
|
|
|
# If the $db is empty/unset, we have a logic bug somewhere!
|
|
if [ -z $db ]; then
|
|
echo "FATAL ERROR: Could not find forgehook database (BUG)"
|
|
fi
|
|
|
|
# We only take one argument!
|
|
if [[ $# != 1 ]]; then
|
|
echo "FATAL ERROR: forgehook-run can't deal with $# argument(s) (BUG)"
|
|
[[ $# != 0 ]] && echo "Found arguments: "$@""
|
|
exit 1
|
|
fi
|
|
|
|
# Ok now we're root
|
|
|
|
r="$1"
|
|
# hexencode URL
|
|
rhex="$(echo -n "$r" | base64)"
|
|
|
|
# Don't loop when nothing matches, plz?
|
|
shopt -s nullglob
|
|
|
|
# Iterate over the hex-encoded URL's subscriptions
|
|
for i in $db/"$rhex".*; do
|
|
# Strip $rhex prefix
|
|
user="$(basename "$i")"
|
|
user="${user#$rhex.}"
|
|
|
|
sudo -u "$user" forgehook-trigger "$1"
|
|
done
|