borgmatic-base/scripts/os

82 lines
1.8 KiB
Text
Raw Normal View History

2021-09-04 09:17:00 -04:00
#!/bin/bash
restoreDir="/etc/restore"
kernel="$(uname -s)"
scriptPath="$(dirname "$(readlink -f "$0")")"
if [[ "$kernel" == "Darwin" ]]; then
restoreDir="${HOME}/restore"
fi
createRestoreDir() {
if [[ -d "${restoreDir}" ]]; then
# Keeps the directory, due to newer borgmatic service restrictions.
rm -rf "${restoreDir}/*" || exit 2
else
mkdir -p "${restoreDir}" || exit 2
2021-09-04 09:17:00 -04:00
fi
}
checkOS() {
if [[ "$kernel" == "Darin" ]]; then
return 0
elif [[ "$kernel" == "Linux" ]]; then
if [[ -f /etc/os-release ]]; then
source /etc/os-release
return 0
else
echo "Unknown Linux Distribution"
return 1
fi
fi
return 1
}
runOsHook() {
local hook="$1"
if [[ "$kernel" == "Darwin" ]]; then
"${scriptPath}/os_macos" "$hook"
elif [[ "$kernel" == "Linux" ]]; then
case "$ID" in
debian) "${scriptPath}/os_debian" "$hook";;
fedora) "${scriptPath}/os_fedora" "$hook";;
garuda) "${scriptPath}/os_garuda" "$hook";;
2021-09-04 09:17:00 -04:00
solus) "${scriptPath}/os_solus" "$hook";;
opensuse-leap) "${scriptPath}/os_suse" "$hook";;
opensuse-tumbleweed) "${scriptPath}/os_suse" "$hook";;
esac
fi
return $?
}
hook_check() {
checkOS || exit 200
runOsHook before_check
}
hook_pre() {
hook_check || exit 200
createRestoreDir || exit $?
runOsHook before_backup
}
hook_post() {
2022-09-05 17:20:14 -04:00
if [[ ! -f "${restoreDir}/.do-not-delete" ]]; then
rm -rf "$restoreDir"
fi
runOsHook after_backup
2021-09-04 09:17:00 -04:00
}
case "$1" in
before_check) hook_check || exit $?;;
before_backup) hook_pre || exit $?;;
after_backup) hook_post || exit $?;;
esac