diff --git a/scripts/os b/scripts/os index daf1ed7..e0406a6 100755 --- a/scripts/os +++ b/scripts/os @@ -36,7 +36,6 @@ checkOS() { runOsHook() { local hook="$1" - checkOS || exit 200 if [[ "$kernel" == "Darwin" ]]; then "${scriptPath}/os_macos" "$hook" elif [[ "$kernel" == "Linux" ]]; then @@ -52,22 +51,35 @@ runOsHook() { return $? } -hook_pre() { - hook_check || exit 200 +hook_before() { + checkOS || exit 200 createRestoreDir || exit $? - runOsHook before_backup + runOsHook before } -hook_post() { +hook_fail() { + checkOS || exit 200 + runOsHook fail +} + +hook_after() { + checkOS || exit 200 + runOsHook after +} + +hook_final() { + checkOS || exit 200 if [[ ! -f "${restoreDir}/.do-not-delete" ]]; then rm -rf "$restoreDir" fi - runOsHook after_backup + runOsHook final } case "$1" in - before_backup) hook_pre || exit $?;; - after_backup) hook_post || exit $?;; + before) hook_before || exit $?;; + after) hook_after || exit $?;; + fail) hook_final || exit $?;; + finally) hook_final || exit $?;; esac diff --git a/scripts/os_debian b/scripts/os_debian index 6540eb7..8ea880d 100755 --- a/scripts/os_debian +++ b/scripts/os_debian @@ -6,7 +6,7 @@ function is_bin_in_path { builtin type -P "$1" &>/dev/null } -hook_pre() { +hook_before() { if ! is_bin_in_path aptitude; then echo "aptitude needs to be installed for backups to work properly." exit 1 @@ -109,12 +109,21 @@ EOF popd || exit 2 } -hook_post() { +hook_after() { : } +hook_fail() { + : +} + +hook_final() { + : +} case "$1" in - before_backup) hook_pre || exit $?;; - after_backup) hook_post || exit $?;; + before) hook_before || exit $?;; + after) hook_after || exit $?;; + fail) hook_final || exit $?;; + finally) hook_final || exit $?;; esac