Move checkOwner() to functions.sh

This commit is contained in:
Martin Lablans 2022-05-31 13:55:40 +02:00
parent ff3d6fb4fe
commit 57483e78d4
2 changed files with 11 additions and 11 deletions

View File

@ -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"
}

View File

@ -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 ..."