Skip to content

Commit 331e87a

Browse files
author
TobiPeterG
committed
feat: rethink factory reset
1 parent 23b629d commit 331e87a

6 files changed

Lines changed: 34 additions & 27 deletions

File tree

etc/systemd/system/factory-reset.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Description=Factory Reset
33
After=local-fs.target
44
Before=first-boot-complete.target
5-
Wants=first-boot-complete.target
5+
Wants=first-boot-complete.target.wants
66
ConditionFirstBoot=yes
77

88
[Service]

etc/systemd/system/first-boot-resize.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[Unit]
22
Description=Reboot to resize
33
After=first-boot-complete.target systemd-repart.service local-fs.target
4+
Before=display-manager.service multi-user.target
45
Requisite=first-boot-complete.target
56

67
[Service]

usr/bin/factory-reset

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
#!/usr/bin/bash
22

3-
if [ ! -f "/home/.deck_remove" ]; then
3+
if [ ! -f "/.factory_reset" ]; then
44
exit 0
55
fi
66

7-
if w | grep -q "^deck\s"; then
8-
echo "User 'deck' is currently logged in. Aborting."
9-
exit 1
10-
fi
11-
12-
echo "User 'deck' is not logged in. Continuing with the process."
13-
14-
rm -rf /home/*
15-
rm -rf /home/.*
16-
mkhomedir_helper deck
17-
18-
echo "Home directory reset completed successfully."
7+
directories=(/home /opt /root /srv /var /usr/local /boot/writable /boot/grub2/i386-pc /boot/grub2/x86_64-efi)
198

20-
# List all snapshots, exclude snapshots 0 and 1, and filter out non-numeric lines
21-
snapshots_to_delete=$(snapper list --disable-used-space --columns=number | awk '$1 ~ /^[0-9]+$/ && $1 != 0 && $1 != 1 && $1 != 2 {print $1}')
9+
rootsource=$(findmnt / -n --output source | sed 's/\[.*\]//g')
10+
mount -t btrfs -o subvol=/ $rootsource /mnt
2211

23-
# Loop through and delete each snapshot
12+
for dir in "${directories[@]}"
13+
do
14+
btrfs subvolume delete /mnt/@$dir
15+
btrfs subvolume snapshot /mnt/@${dir}ori /mnt/@${dir}
16+
done
17+
btrfs subvolume set-default /.snapshots/fr/snapshot
18+
snapshots_to_delete=$(snapper list --disable-used-space --columns=number | awk '$1 ~ /^[0-9]+$/ {print $1}')
2419
for snapshot in $snapshots_to_delete; do
2520
echo "Deleting snapshot: $snapshot"
2621
snapper delete "$snapshot"
2722
done
28-
transactional-update --no-selfupdate cleanup-overlays
2923

30-
echo "All snapshots have been deleted."
24+
mkdir /.snapshots/1
25+
btrfs subvolume snapshot -r /.snapshots/ori/snapshot /.snapshots/1/snapshot
26+
cp /.snapshots/ori/info.xml /.snapshots/1/info.xml
27+
btrfs subvolume set-default /.snapshots/1/snapshot
28+
29+
rm -rf /boot/efi/*
30+
rm -rf /boot/efi/.* || true
31+
cp -r /.snapshots/fr/bori/efi/* /boot/efi/
32+
cp -r /.snapshots/fr/bori/efi/.* /boot/efi/ || true
33+
34+
umount /mnt
35+
systemctl reboot

usr/bin/first-boot-resize

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
if [ -f "/.factory_reset" ]; then
3+
exit 0
4+
fi
25
transactional-update --no-selfupdate -c run btrfs filesystem resize max /
36
transactional-update --no-selfupdate -c 2 run sleep 1
47
snapper modify -c "" 2
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /bin/bash
2-
if ! snapper list --disable-used-space --columns=number | grep -Eq "^\s*2(-|\*|\+|\s)"; then
3-
echo "Snapshot 2 does not exist."
4-
exit 1
5-
fi
6-
transactional-update --no-selfupdate -c 2 run sleep 1
7-
touch "/home/.deck_remove"
2+
3+
rm -rf /boot/efi/*
4+
rm -rf /boot/efi/.* || true
5+
cp -r /.snapshots/fr/bfr/efi/* /boot/efi/
6+
cp -r /.snapshots/fr/bfr/efi/.* /boot/efi/ || true
7+
btrfs subvolume set-default /.snapshots/fr/snapshot

usr/bin/steamos-startup-gamescope

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@
44
echo "[Seat:*]"
55
echo "autologin-session=gamescope-session-steam"
66
} > "/etc/lightdm/lightdm.conf.d/10-gamescope-session.conf"
7-
8-
snapper modify -c "" 2

0 commit comments

Comments
 (0)