From 57483e78d440ab734bf896ec0defd54cce2553c2 Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Tue, 31 May 2022 13:55:40 +0200 Subject: [PATCH] Move checkOwner() to functions.sh --- lib/functions.sh | 9 +++++++++ lib/prerequisites.sh | 13 ++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/functions.sh b/lib/functions.sh index 2dccb5d..c524dd4 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -7,6 +7,15 @@ exitIfNotRoot() { fi } +checkOwner(){ + COUNT=$(find $1 ! -user $2 |wc -l) + if [ $COUNT -gt 0 ]; then + log ERROR "$COUNT files in $1 are not owned by user $2. Run find $1 ! -user $2 to see them, chown -R $2 $1 to correct this issue." + return 1 + fi + return 0 +} + log() { echo -e "$(date +'%Y-%m-%d %T')" "$1:" "$2" } diff --git a/lib/prerequisites.sh b/lib/prerequisites.sh index 13e32f6..e04161b 100755 --- a/lib/prerequisites.sh +++ b/lib/prerequisites.sh @@ -2,22 +2,13 @@ source lib/functions.sh -checkOwner(){ - ## Check for file permissions - COUNT=$(find $1 ! -user $2 |wc -l) - if [ $COUNT -gt 0 ]; then - log ERROR "$COUNT files in $1 are not owned by user $2. Run find $1 ! -user $2 to see them, chown -R $2 $1 to correct this issue." - exit 1 - fi -} - if ! id "bridgehead" &>/dev/null; then log ERROR "User bridgehead does not exist. Please consult readme for installation." exit 1 fi -checkOwner . bridgehead -checkOwner /etc/bridgehead bridgehead +checkOwner . bridgehead || exit 1 +checkOwner /etc/bridgehead bridgehead || exit 1 ## Check if user is a su log INFO "Checking if all prerequisites are met ..."