hbbs

bbs.hlirc.net
Log | Files | Refs | README | LICENSE

commit 2eca529eba1af80a969034c9b2ece9d9a77a33df
parent ccc323d47260877a37b3a8c480be969b537f3750
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 13 Jun 2021 12:31:14 +0100

i/log.sh i/hooks.sh: implement hooks

Diffstat:
Ainclude/hooks.sh | 16++++++++++++++++
Minclude/log.sh | 2++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/include/hooks.sh b/include/hooks.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +run_hooks(){ + hooks=$(eval "echo \$hook_trigger_$1") + for h in $hooks + do + [ -f $cwd/hooks/$h ] && script=$cwd/hooks/$h + [ -f $cwd/hooks/$h.sh ] && script=$cwd/hooks/$h.sh + [ -z "$script" ] && { + echo "no script found for hook: $h" >&2 + continue + } + + sh "$script" + done +} diff --git a/include/log.sh b/include/log.sh @@ -1,8 +1,10 @@ #!/bin/sh . $cwd/include/lock.sh +. $cwd/include/hooks.sh add_log(){ + run_hooks "$1" lock $datadir/log/log awk -v "datadir=$datadir" -v "date=$(date +%Y-%d-%m)" -v "time=$(date +%H:%M)" -v "key=$1" -v "value=$2" -F" " ' $1 != date {