diff --git a/README.md b/README.md index c8b46468cb3b25d26cfd7bb8f9f4cb41551b1152..599e56ca43bb4f1138a5b409ac1c5e8d9a538c92 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Timeshift auto-snapshot script which runs before package upgrade using Pacman ho * Deletes old snapshots which are created using this script. * Auto generates grub if grub-btrfs package is installed. * Can be manually executed by running `timeshift-autosnap` command with elevated privileges. +* Autosnaphot can be temporarily skipped by setting SKIP_AUTOSNAP environment variable (e.g. `sudo SKIP_AUTOSNAP= pacman -Syu`) # /etc/timeshift-autosnap.conf options: * `skipAutosnap` - if set to **true** script won't be executed. @@ -14,7 +15,7 @@ Timeshift auto-snapshot script which runs before package upgrade using Pacman ho * `updateGrub` - if set to **false** grub entries won't be generated. # Notes -* Currently only tested in `BTRFS` mode but should work in `RSYNC` mode too since script is automating Timeshift operations. +* It' working both in `BTRFS` and `RSYNC` mode. * This script is made in Arch and Arch based distros in mind but if there would be interest it should be easily ported to other distros. # Contribution diff --git a/timeshift-autosnap b/timeshift-autosnap index 3305cb16fc02049dc9be4810d44595660707a586..f0d1975ef12db624b8a57549019707c34a6d70cb 100755 --- a/timeshift-autosnap +++ b/timeshift-autosnap @@ -1,17 +1,17 @@ #!/bin/bash #author: gobonja -if [ $(findmnt / -no fstype) == "overlay" ] ; then - echo "==> skipping timeshift-autosnap because system is booted in Live CD mode..."; exit 0; -fi +[ $(findmnt / -no fstype) == "overlay" ] && { printf "==> skipping timeshift-autosnap because system is booted in Live CD mode..."; exit 0; } + +[[ -v SKIP_AUTOSNAP ]] && { printf "==> skipping timeshift-autosnap due SKIP_AUTOSNAP environment variable being set."; exit 0; } readonly CONF_FILE=/etc/timeshift-autosnap.conf -readonly SNAPSHOTS_TO_DELETE=/tmp/timeshift-autosnap-tmp +readonly SNAPSHOTS_TO_DELETE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX) readonly SNAPSHOT_NAME_PATTERN="[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}" readonly SNAPSHOT_DESCRIPTION="{timeshift-autosnap} {created before upgrade}" -function get_property() { +get_property() { if [ ! -f $CONF_FILE ]; then echo "$CONF_FILE not found! Using $1=$3" >&2; param_value=$3 @@ -19,8 +19,8 @@ function get_property() { param_value=`sed '/^\#/d' $CONF_FILE | grep $1 | tail -n 1 |\ cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'` - if ([ $2 == "boolean" ] && [ $param_value != true ] && [ $param_value != false ]) || \ - ([ $2 == "integer" ] && [[ ! $param_value =~ ^[-+]?([1-9][[:digit:]]*|1)$ ]]) ; then + if ([ "$2" == "boolean" ] && [ "$param_value" != true ] && [ "$param_value" != false ]) || \ + ([ "$2" == "integer" ] && [[ ! "$param_value" =~ ^[-+]?([1-9][[:digit:]]*|1)$ ]]) ; then echo "Wrong paramater in $CONF_FILE. Using $1=$3" >&2 param_value=$3 fi @@ -42,7 +42,7 @@ if $(get_property "deleteSnapshots" "boolean" "true") ; then count=$(($(sed -n '$=' $SNAPSHOTS_TO_DELETE)-$(get_property "maxSnapshots" "integer" "3"))) - if [ $count -gt 0 ] ; then + if [ "$count" -gt 0 ] ; then sed -i $(($count))q $SNAPSHOTS_TO_DELETE for snapshot in $(cat $SNAPSHOTS_TO_DELETE); do