This repository has been archived on 2022-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
archive_hook.sh/triggers/git-build

38 lines
1.2 KiB
Bash

#! /bin/bash
# We only take one argument!
if [[ $# != 1 ]] || [[ "" = "$1" ]]; then
echo "FATAL ERROR: forgehook-trigger can't deal with those $# argument(s) (BUG)"
[[ $# != 0 ]] && echo "Found arguments: "$@""
exit 1
fi
# OK, now we're running as unprivileged user who wants to start their build scripts
# TODO: Maybe we should not care whether matching build tasks were found? Or maybe
# we do care and we want the forgehook-endpoint to have nice info about which remotes
# failed to update and why?
# TODO: https://tildegit.org/southerntofu/git-build.sh/issues/14
# Logic should be moved to git-build so this becomes simpler
gitbuild=$HOME/.git-build
if [ ! -d "$gitbuild" ]; then
echo "[forgehook-trigger] WARNING: $USER has no $gitbuild"
continue
fi
FOUND=0
for f in $gitbuild/*.source; do
if [[ "$1" = "$(cat "$f")" ]]; then
FOUND=1
task="$(basename "$f" .source)"
echo "[forgehook-trigger] Running $task for $USER"
bin="$(which git-build.sh)"
"$bin" "$task" > /dev/null &
fi
done
if [[ $FOUND = 0 ]]; then
echo "[forgehook-trigger] WARNING: $USER is subscribed to $r but no matching task was found"
fi