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
|
2024-07-07 16:36:14 -04:00
|
|
|
rm -rf "${restoreDir:?}/*" || exit 2
|
2023-12-03 02:09:46 -05:00
|
|
|
else
|
|
|
|
mkdir -p "${restoreDir}" || exit 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checkOS() {
|
2024-07-07 15:51:24 -04:00
|
|
|
if [[ "$kernel" == "Darwin" ]]; then
|
2023-12-03 02:09:46 -05:00
|
|
|
return 0
|
|
|
|
elif [[ "$kernel" == "Linux" ]]; then
|
|
|
|
if [[ -f /etc/os-release ]]; then
|
|
|
|
source /etc/os-release
|
2024-06-27 22:29:39 -04:00
|
|
|
DISTRO="$ID"
|
|
|
|
DISTRO_CURRENT="$DISTRO"
|
|
|
|
if [[ -n "$ID_LIKE" ]]; then
|
2024-07-07 15:57:40 -04:00
|
|
|
DISTRO="${ID_LIKE%% *}"
|
2024-06-27 22:29:39 -04:00
|
|
|
fi
|
2023-12-03 02:09:46 -05:00
|
|
|
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
|
2024-06-27 22:29:39 -04:00
|
|
|
case "$DISTRO" in
|
2024-07-07 16:36:14 -04:00
|
|
|
debian|ubuntu) "${scriptPath}/os_debian" "$hook";;
|
2023-12-03 02:09:46 -05:00
|
|
|
fedora) "${scriptPath}/os_fedora" "$hook";;
|
2024-07-07 16:36:14 -04:00
|
|
|
arch) "${scriptPath}/os_arch" "$hook";;
|
2023-12-03 02:09:46 -05:00
|
|
|
solus) "${scriptPath}/os_solus" "$hook";;
|
|
|
|
opensuse-leap) "${scriptPath}/os_suse" "$hook";;
|
|
|
|
opensuse-tumbleweed) "${scriptPath}/os_suse" "$hook";;
|
|
|
|
esac
|
2024-06-27 22:29:39 -04:00
|
|
|
|
2024-06-28 13:15:10 -04:00
|
|
|
if command -v flatpak &>/dev/null; then
|
|
|
|
"${scriptPath}/flatpak" "$hook"
|
|
|
|
fi
|
2023-12-03 02:09:46 -05:00
|
|
|
fi
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2023-12-03 06:02:44 -05:00
|
|
|
hook_before() {
|
|
|
|
checkOS || exit 200
|
2024-07-07 16:36:14 -04:00
|
|
|
pushd "$scriptPath" &>/dev/null || exit 201
|
2024-01-09 22:57:47 -05:00
|
|
|
git checkout -- .
|
|
|
|
git pull
|
2024-07-07 16:36:14 -04:00
|
|
|
popd &>/dev/null || exit 201
|
2023-12-03 02:09:46 -05:00
|
|
|
|
|
|
|
createRestoreDir || exit $?
|
2023-12-03 06:02:44 -05:00
|
|
|
runOsHook before
|
|
|
|
}
|
|
|
|
|
|
|
|
hook_fail() {
|
|
|
|
checkOS || exit 200
|
|
|
|
runOsHook fail
|
2023-12-03 02:09:46 -05:00
|
|
|
}
|
|
|
|
|
2023-12-03 06:02:44 -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
|
2023-12-03 06:02:44 -05:00
|
|
|
runOsHook final
|
2023-12-03 02:09:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
2023-12-03 06:02:44 -05:00
|
|
|
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
|