Add factory reset feature

The `factory-reset` command provides a way to completely wipe the data
partition, thus erasing any local configuration and state.  The command
itself simply enables a special systemd service unit that is activated
during the shutdown process.  This unit runs a script, after all
filesystems, except rootfs, have been unmmounted.  It then erases the
signature of the filesystem on the data partition, so it will appear
blank the next time the system boots.  This will trigger the
`init-storage` process, to create a new filesystem on the partition.
This commit is contained in:
2023-03-12 10:19:37 -05:00
parent 2ebb26529a
commit 274c592f5d
5 changed files with 73 additions and 1 deletions

27
overlay/usr/bin/factory-reset Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
. /lib/gentoo/functions.sh
confirm() {
unset _confirm
printf '%s [y/N] ' "${1-Do you want to continue?}"
read _confirm
case "${_confirm}" in
[Yy]|[Yy][Ee][Ss])
return 0
;;
*)
return 1
;;
esac
}
printf "${WARN}"
printf 'This operation will COMPLETELY ERASE all data and information '
printf 'stored on this system!\n'
printf "${NORMAL}"
confirm || exit 9
ewarn 'The system will now reboot and wipe all data.'
systemctl enable --runtime factory-reset.service
systemctl reboot