add hooks functions

This commit is contained in:
emmett1
2017-11-20 12:34:35 +08:00
parent 1aad213ce8
commit a374aba88d
3 changed files with 84 additions and 0 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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