Updated script format to better match resticprofiles

This commit is contained in:
Eric Renfro 2023-12-03 06:02:44 -05:00
parent 500a32ee9e
commit c83ab1a749
Signed by: psi-jack
GPG key ID: 14977F3A50D9A5BF
2 changed files with 33 additions and 12 deletions

View file

@ -36,7 +36,6 @@ checkOS() {
runOsHook() { runOsHook() {
local hook="$1" local hook="$1"
checkOS || exit 200
if [[ "$kernel" == "Darwin" ]]; then if [[ "$kernel" == "Darwin" ]]; then
"${scriptPath}/os_macos" "$hook" "${scriptPath}/os_macos" "$hook"
elif [[ "$kernel" == "Linux" ]]; then elif [[ "$kernel" == "Linux" ]]; then
@ -52,22 +51,35 @@ runOsHook() {
return $? return $?
} }
hook_pre() { hook_before() {
hook_check || exit 200 checkOS || exit 200
createRestoreDir || exit $? 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 if [[ ! -f "${restoreDir}/.do-not-delete" ]]; then
rm -rf "$restoreDir" rm -rf "$restoreDir"
fi fi
runOsHook after_backup runOsHook final
} }
case "$1" in case "$1" in
before_backup) hook_pre || exit $?;; before) hook_before || exit $?;;
after_backup) hook_post || exit $?;; after) hook_after || exit $?;;
fail) hook_final || exit $?;;
finally) hook_final || exit $?;;
esac esac

View file

@ -6,7 +6,7 @@ function is_bin_in_path {
builtin type -P "$1" &>/dev/null builtin type -P "$1" &>/dev/null
} }
hook_pre() { hook_before() {
if ! is_bin_in_path aptitude; then if ! is_bin_in_path aptitude; then
echo "aptitude needs to be installed for backups to work properly." echo "aptitude needs to be installed for backups to work properly."
exit 1 exit 1
@ -109,12 +109,21 @@ EOF
popd || exit 2 popd || exit 2
} }
hook_post() { hook_after() {
: :
} }
hook_fail() {
:
}
hook_final() {
:
}
case "$1" in case "$1" in
before_backup) hook_pre || exit $?;; before) hook_before || exit $?;;
after_backup) hook_post || exit $?;; after) hook_after || exit $?;;
fail) hook_final || exit $?;;
finally) hook_final || exit $?;;
esac esac