diff --git a/leaf b/leaf index d1b2481..5b6fbfb 100755 --- a/leaf +++ b/leaf @@ -48,9 +48,17 @@ main() { prepare|build|install|force-install|remove|pack|dirct-install) leaf_check_permission for _item in "${@:2}"; do - leaf_find_pkgbuild "${_item}" + if [[ x"$1" == x"remove" ]]; then + leaf_find_remove_pkgbuild "${_item}" + else + leaf_find_pkgbuild "${_item}" + fi leaf_reset_state - source "${PKGBUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}".PKGBUILD + if [[ x"$1" == x"remove" ]]; then + source "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}/PKGBUILD" + else + source "${PKGBUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}".PKGBUILD + fi leaf_parse_options srcdir="${BUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}" pkgdir="${srcdir}"/__pkgdir__ @@ -177,6 +185,18 @@ leaf_find_pkgbuild() { fi } +leaf_find_remove_pkgbuild() { + local _location="$(find "${TRACE_DIR}" -type d -wholename "*$1*" -printf "%P\n")" + if [ -z "${_location}" ]; then + leaf_error "Package $1 does NOT exist" + elif [[ $(echo "${_location}" | wc -l) == 1 ]]; then + PKG_PREFIX="$(echo "${_location}" | awk -F'/' '{print $1}')" + PKG_NAME="$(echo "${_location%.PKGBUILD}" | awk -F'/' '{print $2}')" + else + leaf_error "Ambiguous packages, the prefix or version of package must be specified" + fi +} + leaf_invoke_hooks() { local _hook _target _hook_dir local _trace_dir="${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}" @@ -362,6 +382,7 @@ leaf_trace_package() { find . -type f | sort > "${_trace_dir}"/FILES find . -type l | sort > "${_trace_dir}"/LINKS sed -i "s/.//" "${_trace_dir}"/{DIRS,FILES,LINKS} + install -vm644 "${PKGBUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}.PKGBUILD" "${_trace_dir}/PKGBUILD" popd > /dev/null 2>&1 }