-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
debianUpdateNotification.js
51 lines (47 loc) · 2.17 KB
/
debianUpdateNotification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Debian Package Notification Script
/*
* @author Moritz Heusinger <moritz.heusinger@gmail.com>
* The script checks for apt upgrades, everyday at 06:00 p.m., if there are new
* upgrades available it will send an E-Mail to the configured receiverMail.
*
* logging: if true, information will be logged
* senderMail: mail address of the sender
* receiverMail: target mail address
*
* Requirement: An active instance of the Mail adapter
*
*/
const logging = true;
const senderMail = 'john.doe@mail.com';
const receiverMail = 'jane.doe@fmail.com';
createState('javascript.0.system.debianUpgradeable', {
type: 'string',
write: true,
read: true
});
schedule('0 18 * * *', () => {
exec('apt update >/dev/null || sudo apt update >/dev/null && apt list --upgradeable', (err, stdout, stderr) => {
let upgradeable = stdout.split('...')[1];
if (logging) log('Checking for updates via apt ...', 'info');
if (stderr && !stdout) return log(`Error checking for updates via apt: ${stderr}`, `error`);
if (upgradeable.length <= 8) upgradeable = null;
if (upgradeable) {
let upgradeableArrayString = JSON.stringify(upgradeable.split('\n').filter(element => element !== ''));
if(getState('javascript.0.system.debianUpgradeable').val !== upgradeableArrayString) {
setState('javascript.0.system.debianUpgradeable', upgradeableArrayString, true);
if(logging) log('The following upgrades are available:\n' + upgradeable, 'info');
sendTo('email', {
from: senderMail,
to: receiverMail,
subject: 'Es sind neue Updates für deinen Rock64 verfügbar',
text: `Die folgenden Updates sind verfügbar:\n ${upgradeable}`
});
} else {
if (logging) log('There are available dbpkg updates, but non of them are new.', 'info');
} // endElse
} else {
if(logging) log('No new updates available', 'info');
setState('javascript.0.system.debianUpgradeable', '[]', true);
} // endElse
});
});