I was not a fan of the lack of detail in the “pre-apt” description in the timeshift app. It was hard to remember what was installed or removed.
So I, well me and AI, came up with a hook/script pair to make the timeshift description show the apt command that was used.
My new /etc/apt/apt.conf.d/80timeshift file:
DPkg::Pre-Invoke { "/usr/local/sbin/timeshift-apt-hook || true"; };
DPkg::Post-Invoke { "/etc/grub.d/41_snapshots-btrfs || true"; };
And my hook is in /usr/local/sbin/timehift-apt-hook:
#!/bin/sh
set -e
# Fetch the parent process command line (the actual apt command)
PARENT_PID=$PPID
PARENT_NAME=$(ps -p $PARENT_PID -o comm=)
# If the parent is a shell, grab the grandparent process instead
if [ "$PARENT_NAME" = "sh" ] || [ "$PARENT_NAME" = "bash" ]; then
GPID=$(ps -p $PARENT_PID -o ppid= | tr -d ' ')
APT_CMD=$(ps -ho args $GPID | sed 's/"/\"/g')
else
APT_CMD=$(ps -ho args $PARENT_PID | sed 's/"/\"/g')
fi
[ -z "$APT_CMD" ] && APT_CMD="apt operation"
# Create a single snapshot and pipe stderr/stdout to the system journal
timeshift --create --comments "apt; $APT_CMD" --scripted 2>&1 \
| logger -t timeshift-apt-hook || true
I hope the cut and paste came through without any missing information.
