check if root runs script
This commit is contained in:
parent
deb7d862ed
commit
fbb7c5ae81
2 changed files with 11 additions and 3 deletions
|
|
@ -28,3 +28,4 @@ Description = snapper pre snapshot
|
||||||
Depends = snapper
|
Depends = snapper
|
||||||
When = PreTransaction
|
When = PreTransaction
|
||||||
Exec = /usr/share/libalpm/hooks.bin/snap-pac/snap-pac pre
|
Exec = /usr/share/libalpm/hooks.bin/snap-pac/snap-pac pre
|
||||||
|
AbortOnFail
|
||||||
|
|
|
||||||
13
snap-pac
13
snap-pac
|
|
@ -22,9 +22,14 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
echo "ERROR: Script must be run as root."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$1" != "pre" ]] && [[ "$1" != "post" ]]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
declare -r pre_or_post=$1
|
declare -r pre_or_post=$1
|
||||||
|
|
@ -49,12 +54,12 @@ for x in $configurations; do
|
||||||
|
|
||||||
if [[ "$pre_or_post" == "pre" ]]; then
|
if [[ "$pre_or_post" == "pre" ]]; then
|
||||||
|
|
||||||
snapper --config $x create --type pre --cleanup-algorithm $cleanupalgo --print-number --description "$pre_description" > $prefile_prefix"_"$x
|
snapper --config $x create --type $pre_or_post --cleanup-algorithm $cleanupalgo --print-number --description "$pre_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
|
||||||
snapper --config $x create --cleanup-algorithm $cleanupalgo --type post --pre-number $(cat $prefile_prefix"_"$x) --description "$post_description"
|
snapper --config $x create --type $pre_or_post --cleanup-algorithm $cleanupalgo --pre-number $(cat $prefile_prefix"_"$x) --description "$post_description"
|
||||||
rm $prefile_prefix"_"$x
|
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."
|
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."
|
||||||
|
|
@ -65,3 +70,5 @@ for x in $configurations; do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue