Source settings from /etc/snap-pac and not snapper's files

This commit is contained in:
James Barnett 2018-01-17 18:33:32 -05:00
parent f21b4998a4
commit 4ec3acfee5
No known key found for this signature in database
GPG key ID: E4B5E45AA3B8C5C3

View file

@ -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
@ -20,17 +20,21 @@
set -o errtrace set -o errtrace
declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper
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
DESC_LIMIT=${DESC_LIMIT:-48}
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() {
[[ $PACMAN_ABORT_ON_FAIL == "no" ]] && exit 0 [[ $ABORT_ON_FAIL == "no" ]] && exit 0
exit 1 exit 1
} }
trapkill() { trapkill() {
@ -55,14 +59,6 @@ truncate_description() {
fi 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 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR
trap trapkill SIGTERM SIGINT trap trapkill SIGTERM SIGINT
@ -70,19 +66,29 @@ 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 $PACMAN_PRE_DESCRIPTION)") x=$($snapper_cmd "$(truncate_description $PRE_DESCRIPTION)")
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
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