fix: errexit fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
shopt -s inherit_errexit 2>/dev/null || true
|
||||||
|
|
||||||
RED_COLOR="\e[1;31m"
|
RED_COLOR="\e[1;31m"
|
||||||
PURPLE_COLOR="\e[1;35m"
|
PURPLE_COLOR="\e[1;35m"
|
||||||
@@ -404,6 +405,44 @@ leaf_update_environment() {
|
|||||||
[ ! -r /etc/profile ] || source /etc/profile
|
[ ! -r /etc/profile ] || source /etc/profile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leaf_run_phase() {
|
||||||
|
# usage: leaf_run_phase <phase_name> <func_name>
|
||||||
|
local phase="$1" fn="$2"
|
||||||
|
|
||||||
|
LEAF_PHASE_RC=0
|
||||||
|
|
||||||
|
declare -F "$fn" >/dev/null || {
|
||||||
|
LEAF_PHASE_RC=127
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
echo -e "${GREEN_COLOR}>>> ${PKG_PREFIX}/${PKG_NAME}: ${phase}${CLEAR_COLOR}"
|
||||||
|
|
||||||
|
set +e
|
||||||
|
(
|
||||||
|
set -eE -o pipefail
|
||||||
|
"$fn"
|
||||||
|
)
|
||||||
|
LEAF_PHASE_RC=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
leaf_phase_must() {
|
||||||
|
local phase="$1" fn="$2" msg="$3"
|
||||||
|
leaf_run_phase "$phase" "$fn"
|
||||||
|
if [ "${LEAF_PHASE_RC}" -ne 0 ]; then
|
||||||
|
leaf_error "${msg:-${fn} failed (rc=${LEAF_PHASE_RC})}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
leaf_phase_try() {
|
||||||
|
# just run, caller checks $LEAF_PHASE_RC
|
||||||
|
leaf_run_phase "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
leaf_prepare_package() {
|
leaf_prepare_package() {
|
||||||
local url sourcefile index _md5sum local_src
|
local url sourcefile index _md5sum local_src
|
||||||
|
|
||||||
@@ -453,22 +492,42 @@ leaf_prepare_package() {
|
|||||||
|
|
||||||
popd >/dev/null || true
|
popd >/dev/null || true
|
||||||
echo "Sources ready."
|
echo "Sources ready."
|
||||||
src_prepare
|
leaf_phase_must "Preparing" src_prepare "Prepare faild."
|
||||||
}
|
}
|
||||||
|
|
||||||
leaf_build_package() {
|
leaf_build_package() {
|
||||||
leaf_prepare_package
|
leaf_prepare_package
|
||||||
src_build
|
leaf_phase_must "Building" src_build "Build faild."
|
||||||
|
|
||||||
if ! src_check; then
|
leaf_phase_try "Checking" src_check
|
||||||
if [ "${FORCE_INSTALL}" == "1" ]; then
|
if [ "${LEAF_PHASE_RC}" -ne 0 ]; then
|
||||||
|
if [ "${FORCE_INSTALL:-0}" = "1" ]; then
|
||||||
echo -e "${RED_COLOR}* Tests failed, but is in force-install mode.${CLEAR_COLOR}"
|
echo -e "${RED_COLOR}* Tests failed, but is in force-install mode.${CLEAR_COLOR}"
|
||||||
else
|
else
|
||||||
leaf_error "Tests failed, please check. Aborting installation."
|
leaf_error "Tests failed, please check. Aborting installation."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
src_install
|
## run tests (strict: any failing command inside src_check fails the whole check)
|
||||||
|
#local _check_rc=0
|
||||||
|
#set +e
|
||||||
|
#( set -e; src_check )
|
||||||
|
#_check_rc=$?
|
||||||
|
#set -e
|
||||||
|
#
|
||||||
|
#if [ "${_check_rc}" -ne 0 ]; then
|
||||||
|
# if [ "${FORCE_INSTALL}" = "1" ]; then
|
||||||
|
# echo -e "${RED_COLOR}* Tests failed, but is in force-install mode.${CLEAR_COLOR}"
|
||||||
|
# else
|
||||||
|
# leaf_error "Tests failed, please check. Aborting installation."
|
||||||
|
# fi
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# ensure pkgdir exists
|
||||||
|
rm -rf -- "${pkgdir}"
|
||||||
|
install -dm755 -- "${pkgdir}"
|
||||||
|
|
||||||
|
leaf_phase_must "Installing" src_install "Installing failed."
|
||||||
local _option
|
local _option
|
||||||
for _option in $(echo ${!BUILD_OPTIONS[*]}); do
|
for _option in $(echo ${!BUILD_OPTIONS[*]}); do
|
||||||
if [[ x"${_option}" == x"strip" ]] && [[ x"${BUILD_OPTIONS[$_option]}" == x"1" ]]; then
|
if [[ x"${_option}" == x"strip" ]] && [[ x"${BUILD_OPTIONS[$_option]}" == x"1" ]]; then
|
||||||
@@ -492,9 +551,9 @@ leaf_install_package() {
|
|||||||
# trace need to to in the same fakeroot
|
# trace need to to in the same fakeroot
|
||||||
leaf_trace_package "${pkgdir}"
|
leaf_trace_package "${pkgdir}"
|
||||||
# ROOT starts
|
# ROOT starts
|
||||||
src_preinstall
|
leaf_phase_must "Preinstall" src_preinstall "Preinstall failed."
|
||||||
leaf_merge_package "${pkgdir}"
|
leaf_merge_package "${pkgdir}"
|
||||||
src_postinstall
|
leaf_phase_must "Postinstall" src_postinstall "Postinstall failed."
|
||||||
leaf_update_package_database add "${PKG_PREFIX}/${PKG_NAME}"
|
leaf_update_package_database add "${PKG_PREFIX}/${PKG_NAME}"
|
||||||
leaf_update_environment
|
leaf_update_environment
|
||||||
# ROOT ends
|
# ROOT ends
|
||||||
@@ -507,9 +566,9 @@ leaf_dirct-install_package() {
|
|||||||
# trace need to to in the same fakeroot
|
# trace need to to in the same fakeroot
|
||||||
leaf_trace_package "${pkgdir}"
|
leaf_trace_package "${pkgdir}"
|
||||||
# ROOT starts
|
# ROOT starts
|
||||||
src_preinstall
|
leaf_phase_must "Preinstall" src_preinstall "Preinstall failed."
|
||||||
leaf_merge_package "${pkgdir}"
|
leaf_merge_package "${pkgdir}"
|
||||||
src_postinstall
|
leaf_phase_must "Postinstall" src_postinstall "Postinstall failed."
|
||||||
leaf_update_package_database add "${PKG_PREFIX}/${PKG_NAME}"
|
leaf_update_package_database add "${PKG_PREFIX}/${PKG_NAME}"
|
||||||
leaf_update_environment
|
leaf_update_environment
|
||||||
# ROOT ends
|
# ROOT ends
|
||||||
@@ -525,7 +584,7 @@ leaf_remove_package() {
|
|||||||
[ -n "$(grep "${PKG_PREFIX}/${PKG_NAME}" ${INSTALLED_PACKAGES})" ] || {
|
[ -n "$(grep "${PKG_PREFIX}/${PKG_NAME}" ${INSTALLED_PACKAGES})" ] || {
|
||||||
leaf_error "Package ${PKG_PREFIX}/${PKG_NAME} is NOT installed"
|
leaf_error "Package ${PKG_PREFIX}/${PKG_NAME} is NOT installed"
|
||||||
}
|
}
|
||||||
src_preremove
|
leaf_phase_must "Preremove" src_preremove "Preremove failed."
|
||||||
local _file _link _directory _etc_backup_path _relative_path _backup_etc=false
|
local _file _link _directory _etc_backup_path _relative_path _backup_etc=false
|
||||||
_etc_backup_path="/etc/.leaf_backup/${PKGNAME}_$(date +%Y%m%d%H%M%S)"
|
_etc_backup_path="/etc/.leaf_backup/${PKGNAME}_$(date +%Y%m%d%H%M%S)"
|
||||||
cat "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}/FILES" | while read -r _file; do
|
cat "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}/FILES" | while read -r _file; do
|
||||||
@@ -549,7 +608,7 @@ leaf_remove_package() {
|
|||||||
rmdir --ignore-fail-on-non-empty "${_directory}"
|
rmdir --ignore-fail-on-non-empty "${_directory}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
src_postremove
|
leaf_phase_must "Postremove" src_postremove "Postremove failed."
|
||||||
leaf_invoke_hooks remove
|
leaf_invoke_hooks remove
|
||||||
rm -rf "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}"
|
rm -rf "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}"
|
||||||
leaf_update_package_database delete "${PKG_PREFIX}/${PKG_NAME}"
|
leaf_update_package_database delete "${PKG_PREFIX}/${PKG_NAME}"
|
||||||
|
|||||||
Reference in New Issue
Block a user