use subshell; use /tmp for file

This commit is contained in:
James Barnett 2016-04-26 14:35:02 -05:00
parent b22224f150
commit e7844991a0

View file

@ -27,19 +27,26 @@ if [[ $EUID -ne 0 ]]; then
exit 1
fi
if [[ "$1" != "pre" ]] && [[ "$1" != "post" ]]; then
if [[ $# -ne 1 ]]; then
echo "ERROR: Only one argument should be passed to this script."
exit 1
fi
if [[ $1 != "pre" ]] && [[ $1 != "post" ]]; then
echo "ERROR: First argument should either be 'pre' or 'post'."
exit 1
fi
declare -r pre_or_post=$1
declare -r prefile_prefix="/usr/share/libalpm/hooks.bin/snap-pac/.pre"
declare -r prefile_prefix="/tmp/snap-pac-pre"
declare -r pacman_cmd="$(sed 's./usr/bin/pacman.pacman.g' <(ps -C pacman -o args=))"
declare -r snapper_config_dir="/etc/snapper/configs"
declare -r configurations="$(find $snapper_config_dir/* -printf '%f\t')"
declare -r configurations="$(find $snapper_config_dir/* -printf '%f\t\0')"
for x in $configurations; do
(
source $snapper_config_dir/$x
if [[ $x == "root" ]]; then
@ -48,7 +55,7 @@ for x in $configurations; do
take_snapshot=${PACMAN_PRE_POST:-"no"}
fi
if [[ $take_snapshot == "yes" ]]; then
[[ $take_snapshot != "yes" ]] && exit 0
cleanupalgo=${PACMAN_CLEANUP_ALGORITHM:-"number"}
@ -56,25 +63,28 @@ for x in $configurations; do
description=${PACMAN_PRE_DESCRIPTION:-"$pacman_cmd"}
snapper --config $x create --type $pre_or_post --cleanup-algorithm $cleanupalgo --print-number --description "$description" > $prefile_prefix"_"$x
exit 0
elif [[ "$pre_or_post" == "post" ]]; then
if [ -f $prefile_prefix"_"$x ]; then
description=${PACMAN_POST_DESCRIPTION:-"$pacman_cmd"}
snapper --config $x create --type $pre_or_post --cleanup-algorithm $cleanupalgo --pre-number $(cat $prefile_prefix"_"$x) --description "$description"
snapper --config $x create --type $pre_or_post --cleanup-algorithm $cleanupalgo --pre-number $(< $prefile_prefix"_"$x) --description "$description"
rm $prefile_prefix"_"$x
exit 0
else
echo "WARNING: $prefile_prefix"_"$x does not exist, so no post snapshot will be taken. If you are initially installing snap-pac, this is normal."
exit 1
fi
fi
fi
) &
done
exit
exit 0