From 3616ce48a98302d35a7bc76dd1ecc37edbab54e0 Mon Sep 17 00:00:00 2001 From: szaimen Date: Sun, 30 Oct 2022 02:12:06 +0200 Subject: [PATCH] fix the notify script Signed-off-by: szaimen --- Containers/nextcloud/notify.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Containers/nextcloud/notify.sh b/Containers/nextcloud/notify.sh index f782f315..f74ec16b 100644 --- a/Containers/nextcloud/notify.sh +++ b/Containers/nextcloud/notify.sh @@ -1,23 +1,25 @@ #!/bin/bash if [[ "$EUID" = 0 ]]; then - sudo -u www-data -s -E + COMMAND=(sudo -E -u www-data php /var/www/html/occ) +else + COMMAND=(php /var/www/html/occ) fi SUBJECT="$1" MESSAGE="$2" -if [ "$(php /var/www/html/occ config:app:get notifications enabled)" = "no" ]; then +if [ "$("${COMMAND[@]}" config:app:get notifications enabled)" = "no" ]; then echo "Cannot send notification as notification app is not enabled." exit 1 fi echo "Posting notifications to users that are admins..." -NC_USERS=$(php /var/www/html/occ user:list | sed 's|^ - ||g' | sed 's|:.*||') +NC_USERS=$("${COMMAND[@]}" user:list | sed 's|^ - ||g' | sed 's|:.*||') mapfile -t NC_USERS <<< "$NC_USERS" for user in "${NC_USERS[@]}" do - if php /var/www/html/occ user:info "$user" | cut -d "-" -f2 | grep -x -q " admin" + if "${COMMAND[@]}" user:info "$user" | cut -d "-" -f2 | grep -x -q " admin" then NC_ADMIN_USER+=("$user") fi @@ -26,7 +28,7 @@ done for admin in "${NC_ADMIN_USER[@]}" do echo "Posting '$SUBJECT' to: $admin" - php /var/www/html/occ notification:generate "$admin" "$NC_DOMAIN: $SUBJECT" -l "$MESSAGE" + "${COMMAND[@]}" notification:generate "$admin" "$NC_DOMAIN: $SUBJECT" -l "$MESSAGE" done echo "Done!"