use subshell; use /tmp for file
This commit is contained in:
parent
b22224f150
commit
e7844991a0
1 changed files with 29 additions and 19 deletions
48
snap-pac
48
snap-pac
|
|
@ -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,33 +55,36 @@ 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"}
|
||||
|
||||
cleanupalgo=${PACMAN_CLEANUP_ALGORITHM:-"number"}
|
||||
if [[ "$pre_or_post" == "pre" ]]; then
|
||||
|
||||
if [[ "$pre_or_post" == "pre" ]]; then
|
||||
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
|
||||
|
||||
description=${PACMAN_PRE_DESCRIPTION:-"$pacman_cmd"}
|
||||
snapper --config $x create --type $pre_or_post --cleanup-algorithm $cleanupalgo --print-number --description "$description" > $prefile_prefix"_"$x
|
||||
elif [[ "$pre_or_post" == "post" ]]; then
|
||||
|
||||
elif [[ "$pre_or_post" == "post" ]]; then
|
||||
if [ -f $prefile_prefix"_"$x ]; 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 $(< $prefile_prefix"_"$x) --description "$description"
|
||||
rm $prefile_prefix"_"$x
|
||||
exit 0
|
||||
|
||||
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"
|
||||
rm $prefile_prefix"_"$x
|
||||
else
|
||||
|
||||
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."
|
||||
|
||||
fi
|
||||
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
|
||||
|
||||
) &
|
||||
|
||||
done
|
||||
|
||||
exit
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue