-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_pihole_updates
40 lines (28 loc) · 963 Bytes
/
check_pihole_updates
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
#!/usr/bin/perl
use strict;
use warnings;
# Sample output:
# pihole2# pihole -up --check-only
# [i] Checking for updates...
# [i] Pi-hole Core: update available
# [i] Web Interface: update available
# [i] FTL: update available
my $output = qx'pihole -up --check-only';
#print $output;
# Updates available?
my $ua_core = $output =~ /Pi-hole Core:\s*update available/ ? 1 : 0;
my $ua_webui = $output =~ /Web Interface:\s*update available/ ? 1 : 0;
my $ua_ftl = $output =~ /FTL:\s*update available/ ? 1 : 0;
my @updates;
push @updates, "Core" if $ua_core;
push @updates, "WebUI" if $ua_webui;
push @updates, "FTL" if $ua_ftl;
my $ua_sum = 0;
for ( $ua_core, $ua_webui, $ua_ftl ) { $ua_sum++ if $_ }
print "Pi-Hole: $ua_sum update(s) available";
if ( $ua_sum > 0 ) {
print ": ";
print join ",", @updates;
}
print ". | updates=$ua_sum core=$ua_core webui=$ua_webui ftl=$ua_ftl\n";
exit ( $ua_sum != 0 );