feat: install hook and remove hook

This commit is contained in:
Yingjie Wang 2025-03-28 21:29:09 -04:00
parent 789f541a29
commit b15df24b60
2 changed files with 22 additions and 6 deletions

25
leaf
View File

@ -144,12 +144,26 @@ leaf_find_pkgbuild() {
}
leaf_invoke_hooks() {
local _hook _target
local _hook _target _hook_dir
local _trace_dir="${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}"
find "${HOOK_DIR}" -type f -name "*.HOOK" | while read -r _hook; do
case "$1" in
install)
_hook_dir="${INSTALL_HOOK_DIR}"
;;
remove)
_hook_dir="${REMOVE_HOOK_DIR}"
;;
*)
leaf_error "leaf_invoke_hooks get $1, which is invalid."
;;
esac
if [ ! -d "${_hook_dir}" ]; then
leaf_error "Hook dir ${_hook_dir} does not exist."
fi
find "${_hook_dir}" -type f -name "*.HOOK" | while read -r _hook; do
source "${_hook}"
for _target in "${target[@]}"; do
if [ -n "$(grep -e "${_target}" "${_trace_dir}"/FILES)" ]; then
if grep -qe "${_target}" "${_trace_dir}"/FILES 2>/dev/null; then
operation
break
fi
@ -183,7 +197,7 @@ leaf_merge_package() {
cat "${_trace_dir}"/LINKS | while read -r _item; do
cp -dp ."${_item}" "${_item}"
done
leaf_invoke_hooks
leaf_invoke_hooks install
popd > /dev/null 2>&1
}
@ -437,8 +451,9 @@ leaf_remove_package() {
cat "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}/DIRS" | while read -r _directory; do
rmdir --ignore-fail-on-non-empty "${_directory}"
done
rm -rf "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}"
src_postremove
leaf_invoke_hooks remove
rm -rf "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}"
leaf_update_package_database delete "${PKG_PREFIX}/${PKG_NAME}"
leaf_update_environment
}

View File

@ -3,7 +3,8 @@ DIST_DIR="${LEAF_DIR}/distfiles"
BUILD_DIR="${LEAF_DIR}/build"
PKGBUILD_DIR="${LEAF_DIR}/pkgbuild"
TRACE_DIR="${LEAF_DIR}/trace"
HOOK_DIR="${LEAF_DIR}/hooks"
INSTALL_HOOK_DIR="${LEAF_DIR}/hooks/install"
REMOVE_HOOK_DIR="${LEAF_DIR}/hooks/remove"
BINARY_DIR="${LEAF_DIR}/binaries"
TEMP_DIR="${LEAF_DIR}/temp"
INSTALLED_PACKAGES="${LEAF_DIR}/installed"