53 lines
812 B
Bash
53 lines
812 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
HOOK_ARGS=$@
|
||
|
HOOK_PATH=$(realpath $0)
|
||
|
HOOK_PATH=${HOOK_PATH%/*}
|
||
|
|
||
|
export HOOK_PATH
|
||
|
|
||
|
err_trap() {
|
||
|
echo "Error: $BASH_COMMAND"
|
||
|
}
|
||
|
|
||
|
if [[ $PINCH_DEBUG -eq 1 ]]; then
|
||
|
pdebug() {
|
||
|
echo -e "\033[33m(DEBUG)\033[0m $@"
|
||
|
}
|
||
|
else
|
||
|
pdebug() {
|
||
|
:
|
||
|
}
|
||
|
fi
|
||
|
|
||
|
pinfo() {
|
||
|
echo -e "\033[32m=>\033[0m $@"
|
||
|
}
|
||
|
|
||
|
export -f pdebug
|
||
|
export -f err_trap
|
||
|
|
||
|
trap err_trap ERR
|
||
|
|
||
|
exec_custom() {
|
||
|
local hooks_path=$HOOK_PATH/../custom.d/$1
|
||
|
|
||
|
for hook in $(ls $hooks_path); do
|
||
|
if [ -x $hooks_path/$hook ]; then
|
||
|
pdebug "Executing custom hook $hooks_path/$hook"
|
||
|
$hooks_path/$hook $HOOK_ARGS
|
||
|
fi
|
||
|
done
|
||
|
}
|
||
|
|
||
|
exec_all() {
|
||
|
for file in $(ls $1 | sort); do
|
||
|
if [ -x $1/$file ]; then
|
||
|
pdebug "Executing hook $1/$file"
|
||
|
$1/$file $HOOK_ARGS
|
||
|
fi
|
||
|
done
|
||
|
}
|
||
|
|
||
|
pdebug "Hook type: $(basename $0)"
|