resticprofiles-base/scripts/os

90 lines
1.9 KiB
Text
Raw Normal View History

2023-12-03 02:09:46 -05: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
rm -rf "${restoreDir}/*" || exit 2
else
mkdir -p "${restoreDir}" || exit 2
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";;
solus) "${scriptPath}/os_solus" "$hook";;
opensuse-leap) "${scriptPath}/os_suse" "$hook";;
opensuse-tumbleweed) "${scriptPath}/os_suse" "$hook";;
esac
fi
return $?
}
hook_before() {
checkOS || exit 200
2024-01-09 22:57:47 -05:00
pushd "$scriptPath" &>/dev/null
git checkout -- .
git pull
popd &>/dev/null
2023-12-03 02:09:46 -05:00
createRestoreDir || exit $?
runOsHook before
}
hook_fail() {
checkOS || exit 200
runOsHook fail
2023-12-03 02:09:46 -05:00
}
hook_after() {
checkOS || exit 200
runOsHook after
}
hook_final() {
checkOS || exit 200
2023-12-03 02:09:46 -05:00
if [[ ! -f "${restoreDir}/.do-not-delete" ]]; then
rm -rf "$restoreDir"
fi
runOsHook final
2023-12-03 02:09:46 -05:00
}
case "$1" in
before) hook_before || exit $?;;
after) hook_after || exit $?;;
fail) hook_final || exit $?;;
finally) hook_final || exit $?;;
2023-12-03 02:09:46 -05:00
esac