some cleanup

This commit is contained in:
James Barnett 2017-02-14 11:01:19 -06:00
parent e3537fab43
commit 591a0730c6
No known key found for this signature in database
GPG key ID: E4B5E45AA3B8C5C3

View file

@ -52,10 +52,10 @@ trap kill_exit SIGTERM SIGINT
source "$SNAPPER_CONFIG_FILE" source "$SNAPPER_CONFIG_FILE"
[[ $EUID -ne 0 ]] && die "Script must be run as root." [[ $EUID -ne 0 ]] && die "Script must be run as root."
[[ ! -d /var/run/dbus ]] && die "Unable to use snapper without dbus. Are you in a chroot environment?" [[ ! -d /var/run/dbus ]] && die "No dbus available. Are you in a chroot environment?"
[[ $# -ne 1 ]] && die "Only one argument should be passed to this script." [[ $# -ne 1 ]] && die "Only one argument should be passed to this script."
[[ $1 != "pre" ]] && [[ $1 != "post" ]] && [[ $1 != "rem" ]] && die "First argument should either be 'pre', 'post', or 'rem'." [[ $1 != "pre" ]] && [[ $1 != "post" ]] && [[ $1 != "rem" ]] && die "First argument should either be 'pre', 'post', or 'rem'."
[[ -z "$SNAPPER_CONFIGS" ]] && die "No snapper configurations found, so not taking any snapshots!" [[ -z "$SNAPPER_CONFIGS" ]] && die "No snapper configurations found, so not taking any snapshots."
declare -r pre_or_post=$1 declare -r pre_or_post=$1
declare pacman_cmd="$(sed 's./usr/bin/pacman.pacman.g' <(ps -C pacman -o args=))" declare pacman_cmd="$(sed 's./usr/bin/pacman.pacman.g' <(ps -C pacman -o args=))"
@ -83,16 +83,16 @@ for CONFIG in $SNAPPER_CONFIGS; do
[[ $PACMAN_PRE_POST == "no" ]] && continue [[ $PACMAN_PRE_POST == "no" ]] && continue
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" snapper_cmd="snapper --config $CONFIG create --type $pre_or_post --cleanup-algorithm $PACMAN_CLEANUP_ALGORITHM --print-number --description"
x=$((x+1)) x=$((x+1))
printf " %s " "$CONFIG" printf " %s " "$CONFIG"
case "$pre_or_post" in case "$pre_or_post" in
pre) printf "$($snapper_cmd --description "$(truncate_description $PACMAN_PRE_DESCRIPTION)" | tee "$prefile")\n" ;; pre) printf "$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)" | tee "$prefile")\n" ;;
post) post)
if [[ -f $prefile ]]; then if [[ -f $prefile ]]; then
printf "$($snapper_cmd --description "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")")\n" printf "$($snapper_cmd "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")")\n"
rm -f "$prefile" rm -f "$prefile"
else else
warning "%s does not exist, so no post snapshot for %s will be taken. If you are initially installing $name, this is normal." "$prefile" "$CONFIG" warning "%s does not exist, so no post snapshot for %s will be taken. If you are initially installing $name, this is normal." "$prefile" "$CONFIG"
@ -102,4 +102,4 @@ for CONFIG in $SNAPPER_CONFIGS; do
done done
[[ $x -eq 0 ]] && die "No snapper configurations are set up for snapshots to be taken!" [[ $x -eq 0 ]] && die "No snapper configurations are set up for snapshots to be taken."