Source settings from /etc/snap-pac and not snapper's files
This commit is contained in:
parent
f21b4998a4
commit
4ec3acfee5
1 changed files with 25 additions and 19 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue