From a3685820805a1b62c7f29e6c94e8eb507603c40d Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:49:51 -0500 Subject: [PATCH 1/8] notes on kernel branch --- README | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README b/README index ad0b21e..96e19de 100644 --- a/README +++ b/README @@ -26,3 +26,17 @@ After reviewing the man page, check the issues page and file a new issue if your problem is not covered: https://github.com/wesbarnett/snap-pac/issues + +DEVELOPMENT + +Check out any active branches to see what's been added. Most notable is the +"kernel" branch. In that version snap-pac not only does pre/post snapshots but +also detects if the "linux" package has been updated. If so, it symlinks your +old kernel's modules to "/usr/lib/modules" from the pre snapshot so that they +are available. Additionally it symlinks your old kernel and initramfs to a +subfolder in boot where they can be detected by GRUB. So you have the option to +boot into an older kernel if needed. Note that all of these locations need to be +in the "root" snapper configuration's subvolume. Checkout the "kernel" branch +and add PACMAN_KEEP_OLD_KERNELS="yes" to your snapper root configuration to +enable this feature. It probably won't make it into a main release, but I may +package it separately. From 38c0c2960585c1fdb02079d26e4f658d95718e05 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 21:00:52 -0500 Subject: [PATCH 2/8] undo change --- README | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/README b/README index 96e19de..ad0b21e 100644 --- a/README +++ b/README @@ -26,17 +26,3 @@ After reviewing the man page, check the issues page and file a new issue if your problem is not covered: https://github.com/wesbarnett/snap-pac/issues - -DEVELOPMENT - -Check out any active branches to see what's been added. Most notable is the -"kernel" branch. In that version snap-pac not only does pre/post snapshots but -also detects if the "linux" package has been updated. If so, it symlinks your -old kernel's modules to "/usr/lib/modules" from the pre snapshot so that they -are available. Additionally it symlinks your old kernel and initramfs to a -subfolder in boot where they can be detected by GRUB. So you have the option to -boot into an older kernel if needed. Note that all of these locations need to be -in the "root" snapper configuration's subvolume. Checkout the "kernel" branch -and add PACMAN_KEEP_OLD_KERNELS="yes" to your snapper root configuration to -enable this feature. It probably won't make it into a main release, but I may -package it separately. From e6d48a89ade6abc0fe18ef1eb424589aa7c60608 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 08:36:29 -0500 Subject: [PATCH 3/8] remove unused variable --- scripts/snap-pac | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index fdc7b43..d3ad10b 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -23,7 +23,6 @@ declare -r DESC_LIMIT=48 declare -r name="snap-pac" declare PACMAN_ABORT_ON_FAIL="no" declare -r pacman_cmd="$(ps -q $(ps -p "$$" -o ppid=) -o args=)" -declare -i x=0 declare -r pre_or_post=$1 out() { printf "$1 $2\n" "${@:3}"; } From a6e0cd32870562868539ebf79dbddffd329b588f Mon Sep 17 00:00:00 2001 From: James Barnett Date: Wed, 31 May 2017 12:59:48 -0400 Subject: [PATCH 4/8] error tracing --- scripts/snap-pac | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index d3ad10b..767689d 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -18,6 +18,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +set -o errtrace + declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper declare -r DESC_LIMIT=48 declare -r name="snap-pac" @@ -28,12 +30,21 @@ declare -r pre_or_post=$1 out() { printf "$1 $2\n" "${@:3}"; } error() { out "==> \033[00;31merror:\033[00m" "$@"; } >&2 die() { - error "$@" [[ $PACMAN_ABORT_ON_FAIL == "no" ]] && exit 0 exit 1 } -error_exit() { die "Aborted due to error."; } -kill_exit() { die "\nExited due to user intervention."; } +trapkill() { + error "Exited due to user intervention." + die +} +traperror() { + error "Exited due to error on line $1" + out "exit status:" "$2" + out "command:" "$3" + out "bash line:" "$4" + out "function name:" "$5" + die +} truncate_description() { desc="$@" @@ -52,8 +63,8 @@ set_defaults() { PACMAN_CLEANUP_ALGORITHM="number" } -trap error_exit ERR -trap kill_exit SIGTERM SIGINT +trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR +trap trapkill SIGTERM SIGINT source "$SNAPPER_CONFIG_FILE" From f21b4998a47b489775b55c8d9f6fe8f0b1c65e74 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Sun, 17 Dec 2017 21:12:30 -0500 Subject: [PATCH 5/8] typo Signed-off-by: James Barnett --- man8/snap-pac.8 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man8/snap-pac.8 b/man8/snap-pac.8 index 2e174b7..d495fb1 100644 --- a/man8/snap-pac.8 +++ b/man8/snap-pac.8 @@ -178,8 +178,8 @@ Follow the instructions pacman gives you (e.g., removing the lock file). .SH FAQ .SS Does snap-pac backup non-btrfs /boot partitions? -Nope. But you can add hook that does it for you. It would be something like the -following: +Nope. But you can add a hook that does it for you. It would be +something like the following: .EX From c0f92f1cfb0ac94239af0dd7e1a72aeafda2ec5c Mon Sep 17 00:00:00 2001 From: jonasc Date: Fri, 5 Jan 2018 15:22:44 +0100 Subject: [PATCH 6/8] Read configuration values from `/etc/snap-pac` Test whether `/etc/snap-pac` is a readable file and then source it. Set `DESC_LIMIT` only to the default value of `48` if it was not specified in the sourced file. --- scripts/snap-pac | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 767689d..89783ee 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -20,8 +20,10 @@ set -o errtrace +[[ -f /etc/snap-pac ]] && [[ -r /etc/snap-pac ]] && source /etc/snap-pac + declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper -declare -r DESC_LIMIT=48 +declare -r DESC_LIMIT=${DESC_LIMIT:-48} declare -r name="snap-pac" declare PACMAN_ABORT_ON_FAIL="no" declare -r pacman_cmd="$(ps -q $(ps -p "$$" -o ppid=) -o args=)" From 4ec3acfee5e5512035c39005599fc5de59053922 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Wed, 17 Jan 2018 18:33:32 -0500 Subject: [PATCH 7/8] Source settings from /etc/snap-pac and not snapper's files --- scripts/snap-pac | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 767689d..fc88625 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -2,7 +2,7 @@ # snap-pac # https://github.com/wesbarnett/snap-pac -# Copyright (C) 2016, 2017 James W. Barnett +# Copyright (C) 2016, 2017, 2018 James W. Barnett # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,17 +20,21 @@ set -o errtrace -declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper -declare -r DESC_LIMIT=48 declare -r name="snap-pac" -declare PACMAN_ABORT_ON_FAIL="no" +declare -r SNAPPAC_CONFIG_FILE=/etc/snap-pac.conf +declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper declare -r pacman_cmd="$(ps -q $(ps -p "$$" -o ppid=) -o args=)" declare -r pre_or_post=$1 +[[ -f $SNAPPAC_CONFIG_FILE ]] && [[ -r $SNAPPAC_CONFIG_FILE ]] && source $SNAPPAC_CONFIG_FILE + +DESC_LIMIT=${DESC_LIMIT:-48} +ABORT_ON_FAIL=${ABORT_ON_FAIL:-"no"} + out() { printf "$1 $2\n" "${@:3}"; } error() { out "==> \033[00;31merror:\033[00m" "$@"; } >&2 die() { - [[ $PACMAN_ABORT_ON_FAIL == "no" ]] && exit 0 + [[ $ABORT_ON_FAIL == "no" ]] && exit 0 exit 1 } trapkill() { @@ -55,14 +59,6 @@ truncate_description() { fi } -set_defaults() { - PACMAN_PRE_POST="no" - [[ $CONFIG == "root" ]] && PACMAN_PRE_POST="yes" - PACMAN_PRE_DESCRIPTION="$pacman_cmd" - PACMAN_POST_DESCRIPTION="$pacman_cmd" - PACMAN_CLEANUP_ALGORITHM="number" -} - trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR trap trapkill SIGTERM SIGINT @@ -70,19 +66,29 @@ source "$SNAPPER_CONFIG_FILE" for CONFIG in $SNAPPER_CONFIGS; do - set_defaults - source /etc/snapper/configs/"$CONFIG" + CONFIG_FILE="/etc/snap-pac/$CONFIG.conf" + [[ -f "$CONFIG_FILE" ]] && [[ -r "$CONFIG_FILE" ]] && source "$CONFIG_FILE" - [[ $PACMAN_PRE_POST == "no" ]] && continue + if [[ $CONFIG == "root" ]]; then + PRE_POST=${PRE_POST="yes"} + else + PRE_POST=${PRE_POST="no"} + fi + + [[ $PRE_POST == "no" ]] && continue + + PRE_DESCRIPTION=${PRE_DESCRIPTION:-"$pacman_cmd"} + POST_DESCRIPTION=${POST_DESCRIPTION:-"$pacman_cmd"} + CLEANUP_ALGORITHM=${CLEANUP_ALGORITHM:-"number"} prefile="/tmp/$name-pre_$CONFIG" - snapper_cmd="snapper --config $CONFIG create --type $pre_or_post --cleanup-algorithm $PACMAN_CLEANUP_ALGORITHM --print-number --description" + snapper_cmd="snapper --config $CONFIG create --type $pre_or_post --cleanup-algorithm $CLEANUP_ALGORITHM --print-number --description" if [[ "$pre_or_post" == "pre" ]]; then - x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") + x=$($snapper_cmd "$(truncate_description $PRE_DESCRIPTION)") printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then - x=$($snapper_cmd "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")") + x=$($snapper_cmd "$(truncate_description $POST_DESCRIPTION)" --pre-number "$(< "$prefile")") printf "==> %s: %s\n" "$CONFIG" "$x" rm -f "$prefile" fi From d8ef209911d6fc9db18df128c8c67c6b8dded3ca Mon Sep 17 00:00:00 2001 From: James Barnett Date: Wed, 17 Jan 2018 20:49:35 -0500 Subject: [PATCH 8/8] update manpage --- man8/snap-pac.8 | 89 ++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/man8/snap-pac.8 b/man8/snap-pac.8 index d495fb1..9eb2f85 100644 --- a/man8/snap-pac.8 +++ b/man8/snap-pac.8 @@ -30,46 +30,14 @@ but your setup has to be properly configured to use it. The exact procedure depends on your specific setup. Be careful. .SH CONFIGURATION -Configuration is done via the snapper configuration files, with extra variables -specific to these pacman hooks (see \fBsnapper-configs\fR(5)). The defaults -of the following should be suitable for most users. +Configuration is done via configuration files. The defaults of the +following should be suitable for most users. Follow the pattern +of bash shell variables (VAR=setting) in each configuration file below. -The following are possible settings you can place in each snapper configuration -file (e.g., \fI/etc/snapper/configs/root\fR, etc.). Follow the pattern of other -variables in the configuration file (VAR=setting). +The following setting can be changed in the main snap-pac configuration file +\fI/etc/snap-pac.conf\fR: -\fBPACMAN_PRE_POST=\fR\fB\fIyes\fR\fR\fB or \fR\fB\fIno\fR\fR -.RS 4 -Perform pacman pre/post snapshots for this configuration. - -Default is "no", except for the root configuration which is "yes". -.RE - -.BR PACMAN_CLEANUP_ALGORITHM -.RS 4 -Snapper algorithm used in cleaning up the pacman pre/post snapshots. See \fBsnapper\fR(8) for list of valid options. - -Default is "number". -.RE - -\fBPACMAN_PRE_DESCRIPTION=\fR\fB\fIstring\fR\fR -.RS 4 -snapper description used for the pacman pre snapshot. - -Default is the parent program (usually pacman) that called the snapshot script. -.RE - -\fBPACMAN_POST_DESCRIPTION=\fR\fB\fIstring\fR\fR -.RS 4 -snapper description used for the pacman post snapshot. - -Default is the parent program (usually pacman) that called the snapshot script. -.RE - -The following setting can be changed in the snapper configuration file -\fI/etc/conf.d/snapper\fR: - -\fBPACMAN_ABORT_ON_FAIL=\fR\fB\fIyes\fR\fR\fB or \fR\fB\fIno\fR\fR +\fBABORT_ON_FAIL=\fR\fB\fIyes\fR\fR\fB or \fR\fB\fIno\fR\fR .RS 4 When set to "yes" this causes pacman to abort a transaction if the snap-pac pre hook fails. This prevents an upgrade/installation/removal from occurring if a @@ -78,6 +46,51 @@ pre snapshot cannot be performed. Default is "no". .RE +\fBDESC_LENGTH=\fR\fB\fIinteger\fR\fR +.RS 4 +Number of characters to limit length of descriptions used for snapper. + +Default is "48". +.RE + +The following are possible settings used on each specific snapper +configuration you have. To use them, first create the folder +\fI/etc/snap-pac\fR if it does not already exist. Then create a file +for the snapper configuration file you want these settings to apply +to. For example, for the snapper configuration named \fIroot\fR, +create the file \fI/etc/snap-pac/root.conf\fR. \fIsnap-pac\fR requires +and expects configuration files to end in \fI.conf\fR. + +\fBPRE_POST=\fR\fB\fIyes\fR\fR\fB or \fR\fB\fIno\fR\fR +.RS 4 +Perform pacman pre/post snapshots for this configuration. In other +words, if you want snapper to run before and after a pacman +transaction, set this to "yes". + +Default is "no", except for the root configuration which is "yes". +.RE + +.BR CLEANUP_ALGORITHM +.RS 4 +Snapper algorithm used in cleaning up the pacman pre/post snapshots. See \fBsnapper\fR(8) for list of valid options. + +Default is "number". +.RE + +\fBPRE_DESCRIPTION=\fR\fB\fIstring\fR\fR +.RS 4 +snapper description used for the pacman pre snapshot. + +Default is the parent program (usually pacman) that called the snapshot script. +.RE + +\fBPOST_DESCRIPTION=\fR\fB\fIstring\fR\fR +.RS 4 +snapper description used for the pacman post snapshot. + +Default is the parent program (usually pacman) that called the snapshot script. +.RE + .SH EXAMPLE Installing the nano package as normal: