Skip to content
Snippets Groups Projects
Commit 8e2f0b36 authored by Marko Gobin's avatar Marko Gobin
Browse files

Merge branch 'dev' into 'master'

0.8 release

See merge request gobonja/timeshift-autosnap!7
parents 2a919c13 c60dc9b1
Branches master
No related tags found
No related merge requests found
......@@ -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
......
#!/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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment