fix the notify script

Signed-off-by: szaimen <szaimen@e.mail.de>
This commit is contained in:
szaimen 2022-10-30 02:12:06 +02:00
parent 0397f30bb5
commit 3616ce48a9

View file

@ -1,23 +1,25 @@
#!/bin/bash #!/bin/bash
if [[ "$EUID" = 0 ]]; then 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 fi
SUBJECT="$1" SUBJECT="$1"
MESSAGE="$2" 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." echo "Cannot send notification as notification app is not enabled."
exit 1 exit 1
fi fi
echo "Posting notifications to users that are admins..." 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" mapfile -t NC_USERS <<< "$NC_USERS"
for user in "${NC_USERS[@]}" for user in "${NC_USERS[@]}"
do 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 then
NC_ADMIN_USER+=("$user") NC_ADMIN_USER+=("$user")
fi fi
@ -26,7 +28,7 @@ done
for admin in "${NC_ADMIN_USER[@]}" for admin in "${NC_ADMIN_USER[@]}"
do do
echo "Posting '$SUBJECT' to: $admin" 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 done
echo "Done!" echo "Done!"