diff --git a/functions/functions b/functions/functions index d3b6e35..f0c215a 100644 --- a/functions/functions +++ b/functions/functions @@ -8,6 +8,7 @@ ROOT_DIR=/ INDEX_DIR=/var/spkg/index BACKUP_DIR=/var/spkg/backup REJECTED_DIR=/var/spkg/rejected +HOOK_DIR=/etc/hooks if [ -f $CONF_FILE ]; then . $CONF_FILE diff --git a/installpkg b/installpkg index 9411753..bd27dc4 100755 --- a/installpkg +++ b/installpkg @@ -117,6 +117,12 @@ installpkg() { KO) msg "postupgrade : ${color_red}FAIL${color_reset}" ;; esac + if [ "$UPGRADE_PKG" ]; then + runupgradehooks + else + runinstallhooks + fi + if [ -f $INDEX_DIR/$name/.pkgreadme ]; then msg "This package has ${color_green}readme${color_reset}" fi @@ -376,6 +382,46 @@ checkneworphan() { } +runinstallhooks() { + + for hook in $(ls $HOOK_DIR/*.hook); do + description=$(cat "$hook" | grep ^Description | cut -d ' ' -f3-) + operation=$(cat "$hook" | grep ^Operation | cut -d ' ' -f3-) + target=$(cat "$hook" | grep ^Target | cut -d ' ' -f3-) + exec=$(cat "$hook" | grep ^Exec | cut -d ' ' -f3-) + if [ -n "$description" ] && [ -n "$operation" ] && [ -n "$target" ] && [ -n "$exec" ]; then + if [ "$(echo $operation | grep -w "install" )" ]; then + if [ "$(grep -E $target $INDEX_DIR/$name/.files)" ]; then + msg "$description" + $exec + fi + fi + fi + unset description operation target exec + done + +} + +runupgradehooks() { + + for hook in $(ls $HOOK_DIR/*.hook); do + description=$(cat "$hook" | grep ^Description | cut -d ' ' -f3-) + operation=$(cat "$hook" | grep ^Operation | cut -d ' ' -f3-) + target=$(cat "$hook" | grep ^Target | cut -d ' ' -f3-) + exec=$(cat "$hook" | grep ^Exec | cut -d ' ' -f3-) + if [ -n "$description" ] && [ -n "$operation" ] && [ -n "$target" ] && [ -n "$exec" ]; then + if [ "$(echo $operation | grep -w "upgrade" )" ]; then + if [ "$(grep -E $target $INDEX_DIR/$name/.files)" ]; then + msg "$description" + $exec + fi + fi + fi + unset description operation target exec + done + +} + removemakedepends() { ORPHAN="yes" diff --git a/removepkg b/removepkg index b8f9d1c..ef2dff7 100755 --- a/removepkg +++ b/removepkg @@ -68,6 +68,8 @@ removepkg() { [ "$(grep -x usr/share/info/ $INDEX_DIR/$1/.files)" ] && INFOPAGESUPD=yes [ "$(grep usr/lib/ $INDEX_DIR/$1/.files | grep -E "*.so")" ] && LIBDBUPD=yes + runpreremovehooks $1 + rm -R $INDEX_DIR/$1 if [ -d $INDEX_DIR/$1 ]; then @@ -88,6 +90,8 @@ removepkg() { KO) msg "postremove : ${color_red}FAIL${color_reset}" ;; esac + runremovehooks + # remove lock file spkglock } @@ -199,6 +203,39 @@ check_directory() { [ "$DIR_ERROR" ] && exit 1 } +runremovehooks() { + + if [ "${#runthishook[@]}" -gt 0 ]; then + for hook in ${runthishook[@]}; do + description=$(cat "$hook" | grep ^Description | cut -d ' ' -f3-) + operation=$(cat "$hook" | grep ^Operation | cut -d ' ' -f3-) + target=$(cat "$hook" | grep ^Target | cut -d ' ' -f3-) + exec=$(cat "$hook" | grep ^Exec | cut -d ' ' -f3-) + if [ -n "$description" ] && [ -n "$operation" ] && [ -n "$target" ] && [ -n "$exec" ]; then + msg "$description" + $exec + fi + unset description operation target exec + done + fi + +} + +runpreremovehooks() { + + for hook in $(ls $HOOK_DIR/*.hook); do + operation=$(cat "$hook" | grep ^Operation | cut -d ' ' -f3-) + target=$(cat "$hook" | grep ^Target | cut -d ' ' -f3-) + if [ "$(echo $operation | grep -w "remove" )" ]; then + if [ "$(grep -E $target $INDEX_DIR/$1/.files)" ]; then + runthishook+=($hook) + fi + fi + unset operation target + done + +} + parse_options() { while [ "$1" ]; do