Merge branch 'master' into modules
This commit is contained in:
commit
a60e16f8e1
2 changed files with 95 additions and 84 deletions
|
|
@ -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.
|
depends on your specific setup. Be careful.
|
||||||
|
|
||||||
.SH CONFIGURATION
|
.SH CONFIGURATION
|
||||||
Configuration is done via the snapper configuration files, with extra variables
|
Configuration is done via configuration files. The defaults of the
|
||||||
specific to these pacman hooks (see \fBsnapper-configs\fR(5)). The defaults
|
following should be suitable for most users. Follow the pattern
|
||||||
of the following should be suitable for most users.
|
of bash shell variables (VAR=setting) in each configuration file below.
|
||||||
|
|
||||||
The following are possible settings you can place in each snapper configuration
|
The following setting can be changed in the main snap-pac configuration file
|
||||||
file (e.g., \fI/etc/snapper/configs/root\fR, etc.). Follow the pattern of other
|
\fI/etc/snap-pac.conf\fR:
|
||||||
variables in the configuration file (VAR=setting).
|
|
||||||
|
|
||||||
\fBPACMAN_PRE_POST=\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
|
|
||||||
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
|
|
||||||
.RS 4
|
.RS 4
|
||||||
When set to "yes" this causes pacman to abort a transaction if the snap-pac pre
|
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
|
hook fails. This prevents an upgrade/installation/removal from occurring if a
|
||||||
|
|
@ -78,6 +46,51 @@ pre snapshot cannot be performed.
|
||||||
Default is "no".
|
Default is "no".
|
||||||
.RE
|
.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
|
.SH EXAMPLE
|
||||||
|
|
||||||
Installing the nano package as normal:
|
Installing the nano package as normal:
|
||||||
|
|
@ -178,8 +191,8 @@ Follow the instructions pacman gives you (e.g., removing the lock file).
|
||||||
|
|
||||||
.SH FAQ
|
.SH FAQ
|
||||||
.SS Does snap-pac backup non-btrfs /boot partitions?
|
.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
|
Nope. But you can add a hook that does it for you. It would be
|
||||||
following:
|
something like the following:
|
||||||
|
|
||||||
.EX
|
.EX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# snap-pac
|
# snap-pac
|
||||||
# https://github.com/wesbarnett/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
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -18,22 +18,37 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper
|
set -o errtrace
|
||||||
declare -r DESC_LIMIT=48
|
|
||||||
declare -r name="snap-pac"
|
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 pacman_cmd="$(ps -q $(ps -p "$$" -o ppid=) -o args=)"
|
||||||
declare -r pre_or_post=$1
|
declare -r pre_or_post=$1
|
||||||
|
|
||||||
|
[[ -f $SNAPPAC_CONFIG_FILE ]] && [[ -r $SNAPPAC_CONFIG_FILE ]] && source $SNAPPAC_CONFIG_FILE
|
||||||
|
|
||||||
|
declare -r DESC_LIMIT=${DESC_LIMIT:-48}
|
||||||
|
declare -r ABORT_ON_FAIL=${ABORT_ON_FAIL:-"no"}
|
||||||
|
|
||||||
out() { printf "$1 $2\n" "${@:3}"; }
|
out() { printf "$1 $2\n" "${@:3}"; }
|
||||||
error() { out "==> \033[00;31merror:\033[00m" "$@"; } >&2
|
error() { out "==> \033[00;31merror:\033[00m" "$@"; } >&2
|
||||||
die() {
|
die() {
|
||||||
error "$@"
|
[[ $ABORT_ON_FAIL == "no" ]] && exit 0
|
||||||
[[ $PACMAN_ABORT_ON_FAIL == "no" ]] && exit 0
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
error_exit() { die "Aborted due to error."; }
|
trapkill() {
|
||||||
kill_exit() { die "\nExited due to user intervention."; }
|
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() {
|
truncate_description() {
|
||||||
desc="$@"
|
desc="$@"
|
||||||
|
|
@ -44,29 +59,8 @@ truncate_description() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
set_defaults() {
|
trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR
|
||||||
PACMAN_PRE_POST="no"
|
trap trapkill SIGTERM SIGINT
|
||||||
[[ $CONFIG == "root" ]] && PACMAN_PRE_POST="yes"
|
|
||||||
PACMAN_PRE_DESCRIPTION="$pacman_cmd"
|
|
||||||
PACMAN_POST_DESCRIPTION="$pacman_cmd"
|
|
||||||
PACMAN_CLEANUP_ALGORITHM="number"
|
|
||||||
PACMAN_LINK_MODULES="no"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
package_updated() {
|
|
||||||
check="$1"
|
|
||||||
for x in ${packages[@]}; do
|
|
||||||
if [[ "$x" == "$check" ]]; then
|
|
||||||
echo "yes"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo "no"
|
|
||||||
}
|
|
||||||
|
|
||||||
trap error_exit ERR
|
|
||||||
trap kill_exit SIGTERM SIGINT
|
|
||||||
|
|
||||||
mapfile -t packages
|
mapfile -t packages
|
||||||
kernel_updated=$(package_updated "linux")
|
kernel_updated=$(package_updated "linux")
|
||||||
|
|
@ -75,30 +69,34 @@ source "$SNAPPER_CONFIG_FILE"
|
||||||
|
|
||||||
for CONFIG in $SNAPPER_CONFIGS; do
|
for CONFIG in $SNAPPER_CONFIGS; do
|
||||||
|
|
||||||
set_defaults
|
CONFIG_FILE="/etc/snap-pac/$CONFIG.conf"
|
||||||
source /etc/snapper/configs/"$CONFIG"
|
[[ -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"
|
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
|
if [[ "$pre_or_post" == "pre" ]]; then
|
||||||
|
x=$($snapper_cmd "$(truncate_description $PRE_DESCRIPTION)")
|
||||||
if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then
|
|
||||||
x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)" --userdata important=yes)
|
|
||||||
else
|
|
||||||
x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)")
|
|
||||||
fi
|
|
||||||
printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG"
|
printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG"
|
||||||
elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then
|
elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then
|
||||||
if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then
|
if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then
|
||||||
printf "==> Deleting broken kernel modules symlinks...\n"
|
|
||||||
find /usr/lib/modules -xtype l -delete -print
|
|
||||||
printf "==> Symlinking old kernel modules...\n"
|
printf "==> Symlinking old kernel modules...\n"
|
||||||
|
find /usr/lib/modules -xtype l -delete -print
|
||||||
ln -sv /.snapshots/$(<$prefile)/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/
|
ln -sv /.snapshots/$(<$prefile)/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/
|
||||||
fi
|
fi
|
||||||
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"
|
printf "==> %s: %s\n" "$CONFIG" "$x"
|
||||||
rm -f "$prefile"
|
rm -f "$prefile"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue