use subshell; use /tmp for file
This commit is contained in:
parent
b22224f150
commit
e7844991a0
1 changed files with 29 additions and 19 deletions
24
snap-pac
24
snap-pac
|
|
@ -27,19 +27,26 @@ if [[ $EUID -ne 0 ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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'."
|
echo "ERROR: First argument should either be 'pre' or 'post'."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
declare -r pre_or_post=$1
|
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 pacman_cmd="$(sed 's./usr/bin/pacman.pacman.g' <(ps -C pacman -o args=))"
|
||||||
declare -r snapper_config_dir="/etc/snapper/configs"
|
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
|
for x in $configurations; do
|
||||||
|
|
||||||
|
(
|
||||||
|
|
||||||
source $snapper_config_dir/$x
|
source $snapper_config_dir/$x
|
||||||
|
|
||||||
if [[ $x == "root" ]]; then
|
if [[ $x == "root" ]]; then
|
||||||
|
|
@ -48,7 +55,7 @@ for x in $configurations; do
|
||||||
take_snapshot=${PACMAN_PRE_POST:-"no"}
|
take_snapshot=${PACMAN_PRE_POST:-"no"}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $take_snapshot == "yes" ]]; then
|
[[ $take_snapshot != "yes" ]] && exit 0
|
||||||
|
|
||||||
cleanupalgo=${PACMAN_CLEANUP_ALGORITHM:-"number"}
|
cleanupalgo=${PACMAN_CLEANUP_ALGORITHM:-"number"}
|
||||||
|
|
||||||
|
|
@ -56,25 +63,28 @@ for x in $configurations; do
|
||||||
|
|
||||||
description=${PACMAN_PRE_DESCRIPTION:-"$pacman_cmd"}
|
description=${PACMAN_PRE_DESCRIPTION:-"$pacman_cmd"}
|
||||||
snapper --config $x create --type $pre_or_post --cleanup-algorithm $cleanupalgo --print-number --description "$description" > $prefile_prefix"_"$x
|
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
|
elif [[ "$pre_or_post" == "post" ]]; then
|
||||||
|
|
||||||
if [ -f $prefile_prefix"_"$x ]; then
|
if [ -f $prefile_prefix"_"$x ]; then
|
||||||
|
|
||||||
description=${PACMAN_POST_DESCRIPTION:-"$pacman_cmd"}
|
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
|
rm $prefile_prefix"_"$x
|
||||||
|
exit 0
|
||||||
|
|
||||||
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."
|
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
|
fi
|
||||||
|
|
||||||
fi
|
) &
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
exit
|
exit 0
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue