ubuntu-22.04.3-desktop-amd64/casper/filesystem/usr/libexec/zsys-system-autosnapshot

54 lines
1.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/sh
set -eu
ZSYS_SNAPSHOT_UUFILE="/var/run/zsys-snapshot.unattended-upgrades"
ZSYS_UPDATEOOTMENU_UUFILE="/var/run/zsys-bootmenu.unattended-upgrades"
UUPIDFILE="/var/run/unattended-upgrades.pid"
# Return 0 unattended-upgrade isnt running or if we didnt proceeded the action for it yet.
can_run() {
local zsys_uufile="$1"
local uupid=""
# Not running under unattended-upgraded (no pid file)
if [ ! -f "${UUPIDFILE}" ]; then
rm -f "${zsys_uufile}"
return 0
fi
# Not running under unattended-upgraded (unattended upgrade has a leftover pid file)
uupid="$(cat $UUPIDFILE)"
if ! kill -0 $uupid 2>/dev/null; then
rm -f "${zsys_uufile}"
return 0
fi
# unattended-upgraded is running, do we have a matching pid file stored?
if [ -f "${zsys_uufile}" ]; then
zuupid="$(cat ${zsys_uufile})"
# We took a snapshot on that unattended-upgrades run. Nothing to do
if [ "$uupid" = "$zuupid" ]; then
return 1
fi
fi
cp "${UUPIDFILE}" "${zsys_uufile}"
return 0
}
zsys_uufile="${ZSYS_SNAPSHOT_UUFILE}"
if [ "$1" = "update-menu" ]; then
zsys_uufile="${ZSYS_UPDATEOOTMENU_UUFILE}"
fi
if ! can_run "${zsys_uufile}"; then
exit 0
fi
if [ "$1" = "update-menu" ]; then
zsysctl boot update-menu --auto
else
zsysctl state save --system --no-update-bootmenu --auto
fi