Merge pull request #1957 from ublue-os/snapper-ujust

feat: Move default snapper config into ujust as followup to #1939
This commit is contained in:
HikariKnight 2024-12-09 16:22:36 +01:00 committed by GitHub
commit 0de3c688e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 85 additions and 1 deletions

View File

@ -0,0 +1,61 @@
#!/bin/bash
set_snapper_defaults () {
# Set the config to 0 retention, has to be changed by user
sudo snapper set-config "TIMELINE_MIN_AGE=1800"
sudo snapper set-config "TIMELINE_LIMIT_DAILY=0"
sudo snapper set-config "TIMELINE_LIMIT_HOURLY=0"
sudo snapper set-config "TIMELINE_LIMIT_MONTHLY=0"
sudo snapper set-config "TIMELINE_LIMIT_WEEKLY=0"
sudo snapper set-config "TIMELINE_LIMIT_QUARTERLY=0"
sudo snapper set-config "TIMELINE_LIMIT_YEARLY=0"
# Set manual/boot retention to 0
sudo snapper set-config "NUMBER_MIN_AGE=1800"
sudo snapper set-config "NUMBER_LIMIT=0"
sudo snapper set-config "NUMBER_LIMIT_IMPORTANT=0"
# Enable cleanup
sudo systemctl enable --now snapper-cleanup.timer
}
cleanup_snapper () {
sudo snapper cleanup number
sudo snapper cleanup timeline
}
disable_snapper () {
# Make a config for /var/home as /home will not work
sudo snapper -c root delete-config
# Disable the timeline and boot timers
sudo systemctl disable --now snapper-timeline.timer
sudo systemctl disable --now snapper-boot.timer
}
if [ -z "$1" ] || [ "$1" == "enable" ]; then
# Create an empty config for the home subvolume if a root config does not exist
if ! sudo snapper get-config >/dev/null 2>&1; then
# Make a config for /var/home as /home will not work
sudo snapper create-config /var/home
# Set the snapper config settings
set_snapper_defaults
# Disable the timeline and boot timers
sudo systemctl disable --now snapper-timeline.timer
sudo systemctl disable --now snapper-boot.timer
# Launch btrfs assistant so people can change the settings
zenity --info --text="Please change retention settings to what you want in the Snapper Settings tab in btrfs-assistant. Deleted data that still exist in a snapshot will still use disk space!"
btrfs-assistant-launcher &
fi
elif [ "$1" == "clean" ]; then
cleanup_snapper
elif [ "$1" == "wipe" ]; then
set_snapper_defaults
cleanup_snapper
disable_snapper
sudo systemctl disable --now snapper-cleanup.timer
else
disable_snapper
fi

View File

@ -174,6 +174,30 @@ ptyxis-transparency opacity="0.95":
printf "Value must be between 0 and 1: %s.\n" "{{ opacity }}"
fi
# Configure snapshotting for /var/home
configure-snapshots ACTION="":
#!/usr/bin/bash
source /usr/lib/ujust/ujust.sh
OPTION={{ ACTION }}
if [ "$OPTION" == "help" ]; then
echo "Usage: ujust configure-snapshots <option>"
echo " <option>: Specify the quick option to skip the prompt"
echo " Use 'enable' enable snapshotting of /var/home"
echo " Use 'disable' disable snapshotting of /var/home"
echo " Use 'wipe' disable snapshotting and remove all automatic snapshots of /var/home"
exit 0
elif [ "$OPTION" == "" ]; then
echo "${bold}Snapper setup and configuration${normal}"
OPTION=$(Choose "Enable Snapper" "Disable Snapper" "Wipe Snapper config and automatic snapshots")
fi
if [[ "${OPTION,,}" =~ ^enable ]]; then
/usr/libexec/bazzite-snapper-config enable
elif [[ "${OPTION,,}" =~ ^disable ]]; then
/usr/libexec/bazzite-snapper-config disable
elif [[ "${OPTION,,}" =~ ^wipe ]]; then
/usr/libexec/bazzite-snapper-config wipe
fi
# Bazzite CLI mod for bluefin style cli-bing (modfied copy of https://github.com/ublue-os/bluefin/blob/faf7303afa6f8d6e747940c1d1ba63c6d2d43c80/system_files/shared/usr/libexec/ublue-bling.sh#L62)
bazzite-cli:
#!/usr/bin/bash
@ -356,7 +380,6 @@ toggle-password-feedback ACTION="":
#!/usr/bin/bash
PWFEEDBACK_FILE="/etc/sudoers.d/enable-pwfeedback"
OPTION={{ ACTION }}
if [ "$OPTION" = "on" ]; then
echo 'Defaults pwfeedback' | sudo tee $PWFEEDBACK_FILE
echo "enabled, restart terminal to see changes"