2023-06-26 19:52:01 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-06-26 17:04:28 +02:00
|
|
|
|
2023-06-29 14:02:50 +02:00
|
|
|
# used to work around cases where stdin is unavailable or not a terminal
|
|
|
|
if bash -c ': > /dev/tty' > /dev/null 2>&1; then
|
|
|
|
TTY_OR_CONSOLE="/dev/tty"
|
|
|
|
else
|
|
|
|
TTY_OR_CONSOLE="/dev/console"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2023-06-26 17:04:28 +02:00
|
|
|
function yesno {
|
|
|
|
unset DISCARD_ME
|
|
|
|
while [ -z "$DISCARD_ME" ]; do
|
2023-06-29 14:02:50 +02:00
|
|
|
read -p "[y/n] " -n1 DISCARD_ME < $TTY_OR_CONSOLE
|
2023-06-26 17:04:28 +02:00
|
|
|
case "$DISCARD_ME" in
|
|
|
|
y)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
n)
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo " Please enter y for yes or n for no."
|
|
|
|
unset DISCARD_ME
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overlay should still be mounted, right?
|
|
|
|
|
|
|
|
cat /proc/mounts
|
|
|
|
|
|
|
|
read -p "
|
2023-06-29 14:02:50 +02:00
|
|
|
press any key" -n1 DISCARD_ME < $TTY_OR_CONSOLE
|
2023-06-26 17:04:28 +02:00
|
|
|
|
|
|
|
# And no services running?
|
|
|
|
|
|
|
|
ps aux | grep -vF "[kworker"
|
|
|
|
|
|
|
|
read -p "
|
2023-06-29 14:02:50 +02:00
|
|
|
press any key" -n1 DISCARD_ME < $TTY_OR_CONSOLE
|
2023-06-26 17:04:28 +02:00
|
|
|
|
|
|
|
#TODO: remove above debugging sanity checks
|
|
|
|
|
|
|
|
#TODO: refuse to run if system is running
|
|
|
|
|
|
|
|
#TODO: add a way to tell the system whether to back up before shutting down
|
|
|
|
|
|
|
|
#TODO: colors
|
|
|
|
echo "Back up system changes to disk?
|
|
|
|
|
|
|
|
This only affects things outside the /home directory.
|
|
|
|
Backing up the system will take some time.
|
|
|
|
"
|
|
|
|
|
|
|
|
if yesno; then
|
|
|
|
echo "Backing up..."
|
|
|
|
#TODO: fiddle with squashfs parameters to find optimal settings
|
2023-06-28 19:55:09 +02:00
|
|
|
#TODO: exclude /tmp
|
|
|
|
mksquashfs / /run/void-usb/container/new_squashfs.img -b 1M -comp xz -one-file-system -progress -noappend -e /var/cache/xbps
|
2023-06-26 17:04:28 +02:00
|
|
|
#TODO: check if enough disk space
|
|
|
|
# yes -> create new image next to old image
|
|
|
|
# no -> create new image in RAM
|
|
|
|
#TODO: figure out when appending to existing squashfs is a good idea
|
2023-06-28 19:55:09 +02:00
|
|
|
mv /run/void-usb/container/new_squashfs.img /run/void-usb/container/squashfs.img
|
2023-06-26 17:04:28 +02:00
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "Not backing up."
|
|
|
|
fi
|