#!/bin/sh
# Armbian: tell the user that the system runs from a snapshot (GRUB snapshot
# entry or snapshot menu: /run/armbian-snapshot/number). Changes are lost at
# reboot. The console output is a section of the login message (motd).
n="$(cat /run/armbian-snapshot/number 2> /dev/null)"
[ -n "$n" ] || n="$(sed -n 's/.*armbian\.snapshot=\([0-9]*\).*/\1/p' /proc/cmdline)"
[ -n "$n" ] || exit 0
# The snapshot menu keeps the date. GRUB boots have no date.
when="$(cat /run/armbian-snapshot/date 2> /dev/null)"
running="snapshot $n"
[ -n "$when" ] && running="snapshot $n, the system as on $when UTC"
case "$1" in
--notify)
	command -v notify-send > /dev/null || exit 0
	notify-send -u critical -a Armbian "Running snapshot $n" "Running: $running
Changes: in RAM only, lost at reboot
Keep it: sudo armbian-snapshot restore
Go back: reboot"
	;;
*)
	printf '\n\033[0;90m Snapshot: \033[0m\n\n'
	printf ' \033[1;33m%-7s\033[0m : \033[0;91m%s\033[0m\n' "Running" "$running"
	printf ' \033[1;33m%-7s\033[0m : %s\n' "Changes" "in RAM only, lost at reboot"
	printf ' \033[1;33m%-7s\033[0m : \033[0;92m%s\033[0m\n' "Keep it" "sudo armbian-snapshot restore"
	printf ' \033[1;33m%-7s\033[0m : \033[0;92m%s\033[0m\n' "Go back" "reboot"
	;;
esac
