Skip to content

Commit 0c538ae

Browse files
committed
add notify_admin functionality
Signed-off-by: nachoparker <nacho@ownyourbits.com>
1 parent 986046f commit 0c538ae

File tree

22 files changed

+45
-63
lines changed

22 files changed

+45
-63
lines changed

bin/ncp/NETWORKING/letsencrypt.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ configure()
6767
# Set up auto-renewal
6868
cat > /etc/cron.weekly/letsencrypt-ncp <<EOF
6969
#!/bin/bash
70+
source /usr/local/etc/library.sh
7071
7172
# renew and notify
7273
$letsencrypt renew --quiet
7374
7475
# notify if fails
75-
[[ \$? -ne 0 ]] && ncc notification:generate \
76-
$NOTIFYUSER "SSL renewal error" \
77-
-l "SSL certificate renewal failed. See /var/log/letsencrypt/letsencrypt.log"
76+
[[ \$? -ne 0 ]] && notify_admin \
77+
"SSL renewal error" \
78+
"SSL certificate renewal failed. See /var/log/letsencrypt/letsencrypt.log"
7879
7980
# cleanup
8081
rm -rf $ncdir/.well-known
@@ -84,9 +85,10 @@ EOF
8485
mkdir -p /etc/letsencrypt/renewal-hooks/deploy
8586
cat > /etc/letsencrypt/renewal-hooks/deploy/ncp <<EOF
8687
#!/bin/bash
87-
/usr/local/bin/ncc notification:generate \
88-
$NOTIFYUSER "SSL renewal" \
89-
-l "Your SSL certificate(s) \$RENEWED_DOMAINS has been renewed for another 90 days"
88+
source /usr/local/etc/library.sh
89+
notify_admin \
90+
"SSL renewal" \
91+
"Your SSL certificate(s) \$RENEWED_DOMAINS has been renewed for another 90 days"
9092
exit 0
9193
EOF
9294
chmod +x /etc/letsencrypt/renewal-hooks/deploy/ncp

bin/ncp/SYSTEM/nc-hdd-monitor.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ EOF
4545
}
4646

4747
cat >> /usr/local/etc/ncp-hdd-notif.sh <<EOF
48+
source /usr/local/etc/library.sh
4849
wall "\$SMARTD_MESSAGE"
49-
sudo -u www-data php /var/www/nextcloud/occ notification:generate \
50-
$NOTIFYUSER "NextCloudPi HDD health \$SMARTD_FAILTYPE" \
51-
-l "\$SMARTD_MESSAGE"
50+
notify_admin \
51+
"NextCloudPi HDD health \$SMARTD_FAILTYPE" \
52+
"\$SMARTD_MESSAGE"
5253
EOF
5354
chmod +x /usr/local/etc/ncp-hdd-notif.sh
5455

bin/ncp/UPDATES/nc-autoupdate-nc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ configure()
2121

2222
cat > /etc/cron.daily/ncp-autoupdate-nc <<EOF
2323
#!/bin/bash
24+
source /usr/local/etc/library.sh
2425
2526
echo -e "[ncp-update-nc]" >> /var/log/ncp.log
2627
/usr/local/bin/ncp-update-nc "$NCVER" 2>&1 | tee -a /var/log/ncp.log
@@ -29,8 +30,7 @@ if [[ \${PIPESTATUS[0]} -eq 0 ]]; then
2930
3031
VER="\$( /usr/local/bin/ncc status | grep "version:" | awk '{ print \$3 }' )"
3132
32-
sudo -u www-data php /var/www/nextcloud/occ notification:generate \
33-
"$NOTIFYUSER" "NextCloudPi" -l "Nextcloud was updated to \$VER"
33+
notify_admin "NextCloudPi" "Nextcloud was updated to \$VER"
3434
fi
3535
echo "" >> /var/log/ncp.log
3636
EOF

bin/ncp/UPDATES/nc-autoupdate-ncp.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ configure()
1919

2020
cat > /etc/cron.daily/ncp-autoupdate <<EOF
2121
#!/bin/bash
22+
source /usr/local/etc/library.sh
2223
if /usr/local/bin/ncp-test-updates; then
2324
/usr/local/bin/ncp-update || exit 1
24-
/usr/local/bin/ncc notification:generate \
25-
"$NOTIFYUSER" "NextCloudPi" \
26-
-l "NextCloudPi was updated to \$( cat /usr/local/etc/ncp-version )"
25+
notify_admin "NextCloudPi" "NextCloudPi was updated to \$(cat /usr/local/etc/ncp-version)"
2726
fi
2827
EOF
2928
chmod 755 /etc/cron.daily/ncp-autoupdate

bin/ncp/UPDATES/nc-notify-updates.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ configure()
2626
# code
2727
cat > /usr/local/bin/ncp-notify-update <<EOF
2828
#!/bin/bash
29+
source /usr/local/etc/library.sh
2930
VERFILE=/usr/local/etc/ncp-version
3031
LATEST=/var/run/.ncp-latest-version
3132
NOTIFIED=/var/run/.ncp-version-notified
@@ -43,16 +44,17 @@ echo "Found update from \$( cat \$VERFILE ) to \$( cat \$LATEST ). Sending notif
4344
IFACE=\$( ip r | grep "default via" | awk '{ print \$5 }' | head -1 )
4445
IP=\$( ip a show dev "\$IFACE" | grep global | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
4546
46-
/usr/local/bin/ncc notification:generate \
47-
$USER "NextCloudPi update" \
48-
-l "Update from \$( cat \$VERFILE ) to \$( cat \$LATEST ) is available. Update from https://\$IP:4443"
47+
notify_admin \
48+
"NextCloudPi update" \
49+
"Update from \$( cat \$VERFILE ) to \$( cat \$LATEST ) is available. Update from https://\$IP:4443"
4950
5051
cat \$LATEST > \$NOTIFIED
5152
EOF
5253
chmod +x /usr/local/bin/ncp-notify-update
5354

5455
cat > /usr/local/bin/ncp-notify-unattended-upgrade <<EOF
5556
#!/bin/bash
57+
source /usr/local/etc/library.sh
5658
5759
LOGFILE=/var/log/unattended-upgrades/unattended-upgrades.log
5860
STAMPFILE=/var/run/.ncp-notify-unattended-upgrades
@@ -74,9 +76,9 @@ sed -i 's|INFO Packages that will be upgraded:|INFO Packages that will be upgrad
7476
echo -e "Packages automatically upgraded: \$PKGS\\n"
7577
7678
# notify
77-
/usr/local/bin/ncc notification:generate \
78-
$USER "NextCloudPi Unattended Upgrades" \
79-
-l "Packages automatically upgraded \$PKGS"
79+
notify_admin \
80+
"NextCloudPi Unattended Upgrades" \
81+
"Packages automatically upgraded \$PKGS"
8082
EOF
8183
chmod +x /usr/local/bin/ncp-notify-unattended-upgrade
8284

bin/ncp/UPDATES/nc-update-nc-apps-auto.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ configure()
2020

2121
cat > "$cronfile" <<EOF
2222
#!/bin/bash
23+
source /usr/local/etc/library.sh
2324
OUT="\$(
2425
echo "[ nc-update-nc-apps-auto ]"
2526
echo "checking for updates..."
@@ -28,7 +29,7 @@ echo "checking for updates..."
2829
echo "\$OUT" >> /var/log/ncp.log
2930
3031
APPS=\$( echo "\$OUT" | grep 'updated\$' | awk '{ print \$1 }')
31-
[[ "\$APPS" != "" ]] && /usr/local/bin/ncc notification:generate "$USER" "Apps updated" -l "\$APPS"
32+
[[ "\$APPS" != "" ]] && notify_admin "Apps updated" "\$APPS"
3233
EOF
3334
chmod 755 "$cronfile"
3435
echo "automatic app updates enabled"

changelog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2-
[v1.20.7](https://github.com/nextcloud/nextcloudpi/commit/8ce053f) (2020-01-26) fail2ban: update regex for NC17
2+
[v1.20.9](https://github.com/nextcloud/nextcloudpi/commit/135f4d4) (2020-02-04) add notify_admin functionality
3+
4+
[v1.20.8](https://github.com/nextcloud/nextcloudpi/commit/986046f) (2020-02-05) nc-backup: add more info to description (#1073)
5+
6+
[v1.20.7](https://github.com/nextcloud/nextcloudpi/commit/b404765) (2020-01-26) fail2ban: update regex for NC17
37

48
[v1.20.6 ](https://github.com/nextcloud/nextcloudpi/commit/4a99207) (2020-01-21) ncp-config: dont save passwords
59

@@ -11,7 +15,7 @@
1115

1216
[v1.20.2 ](https://github.com/nextcloud/nextcloudpi/commit/953c47a) (2019-11-13) Extend the ssh configuration check by calling the echo command if the first check fails.
1317

14-
[v1.20.1](https://github.com/nextcloud/nextcloudpi/commit/6d0bc6b) (2019-12-19) Revert "build: dont use empty values by default"
18+
[v1.20.1 ](https://github.com/nextcloud/nextcloudpi/commit/6d0bc6b) (2019-12-19) Revert "build: dont use empty values by default"
1519

1620
[v1.20.0 ](https://github.com/nextcloud/nextcloudpi/commit/f75c415) (2019-12-19) upgrade to NC17.0.2
1721

etc/library.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ function apt_install()
299299
apt-get install -y --no-install-recommends -o Dpkg::Options::=--force-confdef
300300
}
301301

302+
function notify_admin()
303+
{
304+
local header="$1"
305+
local msg="$2"
306+
local admin=$(mysql -u root nextcloud -Nse "select uid from oc_group_user where gid='admin' limit 1;")
307+
[[ "${admin}" == "" ]] && { echo "admin user not found" >&2; return 0; }
308+
ncc notification:generate "${admin}" "${header}" -l "${msg}" || true
309+
}
310+
302311
# License
303312
#
304313
# This script is free software; you can redistribute it and/or modify it

etc/ncp-config.d/l10n/letsencrypt/zh.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"EMAIL": "電子郵件",
66
"Internet access is required for this configuration to complete\nBoth ports 80 and 443 need to be accessible from the internet\n \nYour certificate will be automatically renewed every month": "使用letsencrypt提供的SSL證書\n在執行這個動作之前,請開啟網路且開啟Port 80和443\n完成此動作之後,SSL證書將每個月自動更新續期。",
77
"Warning": "警告",
8-
"letsencrypt": "SSL證書",
9-
"NOTIFYUSER":"提醒用戶"
8+
"letsencrypt": "SSL證書"
109
}
1110
}

etc/ncp-config.d/l10n/nc-autoupdate-nc/pt.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"translations":{
33
"ACTIVE":"Ativo",
4-
"NOTIFYUSER":"Noticar Usuario",
54
"Automatically apply Nextcloud updates":"Aplicar atualizações automaticas ao Nextcloud",
65
"nc-autoupdate-nc":"nc-autoupdate-nc"
76
}

0 commit comments

Comments
 (0)