|
1 | 1 | #!/usr/bin/bash |
2 | 2 |
|
3 | | -if [ ! -f "/home/.deck_remove" ]; then |
| 3 | +if [ ! -f "/.factory_reset" ]; then |
4 | 4 | exit 0 |
5 | 5 | fi |
6 | 6 |
|
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) |
19 | 8 |
|
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 |
22 | 11 |
|
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}') |
24 | 19 | for snapshot in $snapshots_to_delete; do |
25 | 20 | echo "Deleting snapshot: $snapshot" |
26 | 21 | snapper delete "$snapshot" |
27 | 22 | done |
28 | | -transactional-update --no-selfupdate cleanup-overlays |
29 | 23 |
|
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 |
0 commit comments