From 8a0c325ee2783ca7100adb2a27b1e13fdaf49f07 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 26 Apr 2016 10:58:29 -0500 Subject: [PATCH] check that script is run as root --- snap-pac | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/snap-pac b/snap-pac index 4eead61..9575991 100755 --- a/snap-pac +++ b/snap-pac @@ -21,6 +21,13 @@ # Main script. Is sourced in hooks and functions are called. # e.g.: bash -c ". snap-pac; pre" +set -e + +if [[ $EUID -ne 0 ]]; then + echo "snap-pac must be run as root." + exit +fi + # Have to store pre snapshot number in a file, since the script is run in a # subshell. Exporting a variable doesn't seem to work declare -r prefile_prefix="/usr/share/libalpm/hooks.bin/snap-pac/.pre" @@ -29,14 +36,14 @@ declare -r prefile_prefix="/usr/share/libalpm/hooks.bin/snap-pac/.pre" # pacman_cmd function read_configs { + declare -r pre_or_post=$1 + # pacman command that called the hook in the first place declare -r pacman_cmd="$(echo $(ps -C pacman -o args=) | sed 'sX/usr/bin/pacmanXpacmanXg')" declare -r snapper_config_dir="/etc/snapper/configs" configurations="$(ls $snapper_config_dir)" - declare -r pre_or_post=$1 - declare -i i=0 for x in $configurations; do