From edcc7cf15c42a48f0f5f90aabc5241c20c26ffb6 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 15 Jun 2008 14:35:30 +0200 Subject: bin/pkg: Made hook-handling simpler --- bin/pkg | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'bin') diff --git a/bin/pkg b/bin/pkg index 11ba47d..040917b 100755 --- a/bin/pkg +++ b/bin/pkg @@ -135,6 +135,16 @@ real_priority () { esac } +# Execute a hook +exec_hook () { + package="$1" + hook="$2" + if ([ -r $PDIR/$package/hooks/$hook ]) { + info "Executing $hook hook\n" + . $PDIR/$package/hooks/$hook + } +} + # Check dependencies and offer to install them check_deps () { [ -r $PDIR/$1/dependencies ] || return 0 @@ -265,10 +275,7 @@ pkg_add () { cd $PDIR/$1 make } - if ([ -r $PDIR/$1/hooks/post-add ]) { - info 'Executing post-add hook\n' - . $PDIR/$1/hooks/post-add - } + exec_hook "$1" "post-add" check_deps "$1" check_conflicts "$1" cd $PDIR/$1 @@ -286,10 +293,7 @@ pkg_remove () { confirm_no "Package '$1' is $(real_priority $(cat priority)). Really remove?" || return } } - if ([ -f $PDIR/$1/hooks/pre-remove ]) { - info 'Executing pre-remove hook\n' - . $PDIR/$1/hooks/pre-remove - } + exec_hook "$1" "pre-remove" genocide_collected "$1" removelinks "$1" rm -r $PDIR/$1 @@ -311,10 +315,7 @@ pkg_update () { info "Building binaries\n" make } - if ([ -r hooks/post-update ]) { - info 'Executing post-update hook\n' - . hooks/post-update - } + exec_hook "$1" "post-update" checklinks $CL_OPTIONS populate_collected "$1" } else { -- cgit v1.2.3