| 1 | #!/bin/sh |
| 2 | |
| 3 | SNAPPER_CONFIGS_FILE="/etc/snapper/snapper" |
| 4 | SNAPPER_CONFIG_APK_SNAP_ITEM="root-apk-snap" |
| 5 | |
| 6 | # Check if /etc/snapper/snapper exists, add call to config for apk-snap |
| 7 | if [ -f "$SNAPPER_CONFIGS_FILE" ]; then |
| 8 | # Extract the value of SNAPPER_CONFIGS from the file |
| 9 | SNAPPER_CONFIGS=$(awk -F'[:"]+' '/^SNAPPER_CONFIGS=/ {print $3}' "$SNAPPER_CONFIGS_FILE") |
| 10 | |
| 11 | # Check if "root-apk-snap" is in the SNAPPER_CONFIGS |
| 12 | if [ -n "$SNAPPER_CONFIGS" ] && echo "$SNAPPER_CONFIGS" | grep -qw "$SNAPPER_CONFIG_APK_SNAP_ITEM"; then |
| 13 | SNAPPER_CONFIGS=$(echo "$SNAPPER_CONFIGS" | sed "s/\b$DEFAULT_SNAPPER_ITEM\b//g" | sed 's/ / /g' | sed 's/^ //;s/ $//') |
| 14 | sed -i "/^SNAPPER_CONFIGS=/s/=.*/=\"$SNAPPER_CONFIGS\"/" "$SNAPPER_CONFIGS_FILE" |
| 15 | echo "$SNAPPER_CONFIG_APK_SNAP_ITEM removed from SNAPPER_CONFIGS: $SNAPPER_CONFIGS" |
| 16 | fi |
| 17 | else |
| 18 | echo "Snapper not properly installed, $SNAPPER_CONFIGS_FILE does not exist" |
| 19 | fi |
| 20 | |
| 21 | |
| 22 | # Check if snapper config for apk-snap, and snapshots subvol exists; and take appropriate action |
| 23 | if [ -f "/etc/snapper/configs/root-apk-snap" ] && [ -d "/.snapshots" ]; then |
| 24 | echo "snapper config for apk-snap removed, ./snapshots subvol not removed." |
| 25 | rm -f /etc/snapper/configs/root-apk-snap |
| 26 | |
| 27 | elif [ -f "/etc/snapper/configs/root-apk-snap" ] && [ ! -d "/.snapshots" ]; then |
| 28 | echo "snapper config for apk-snap removed, snapshots subvol does not exist." |
| 29 | rm -f /etc/snapper/configs/root-apk-snap |
| 30 | |
| 31 | elif [ -f "/etc/snapper/configs/root-apk-snap" ] || [ -d "/.snapshots" ]; then |
| 32 | echo "snapper config for apk-snap does not exist, snapshots subvol not removed." |
| 33 | |
| 34 | elif [ -f "/etc/snapper/configs/root-apk-snap" ] || [ ! -d "/.snapshots" ]; then |
| 35 | echo "snapper config for apk-snap does not exist, snapshots subvol does not exist." |
| 36 | fi |