-
Notifications
You must be signed in to change notification settings - Fork 2
/
telegraf-apt.sh
86 lines (67 loc) · 3.23 KB
/
telegraf-apt.sh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
# shellcheck disable=SC1091
case "$1" in
--update)
if [ "$(systemctl is-active telegraf.service)" = "active" ]; then
kill -USR1 "$(pgrep -f -o "$0")" || true
fi
;;
*)
trap exit INT
trap "echo" USR1
while true; do
release_version=$(cat /etc/debian_version)
release_codename=$(. /etc/os-release; echo "$VERSION_CODENAME" | sed 's/^[a-z]/\U&/g')
echo "apt debian_release=\"$release_version\""
echo "apt debian_codename=\"$release_codename\""
release_ltsinfo=$(curl -sf https://wiki.debian.org/LTS | grep "Debian $(echo "$release_version" | cut -d '.' -f 1)")
if [ -n "$release_ltsinfo" ]; then
if echo "$release_ltsinfo" | grep -q "#98fb98"; then
release_support=0
elif echo "$release_ltsinfo" | grep -q "#FCED77"; then
release_support=1
else
release_support=2
fi
echo "apt debian_support=$release_support"
fi
updates_regular=$(apt-get -qq -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | grep ^Inst | grep -c -v Security)
updates_security=$(apt-get -qq -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | grep ^Inst | grep -c Security)
updates_packages=$(apt-get -qq -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | grep ^Inst | cut -d ' ' -f 2 | paste -s -d " ")
if [ "$updates_security" -gt 0 ] && [ "$updates_regular" -gt 0 ]; then
updates_severity=3
elif [ "$updates_security" -gt 0 ]; then
updates_severity=2
elif [ "$updates_regular" -gt 0 ]; then
updates_severity=1
else
updates_severity=0
fi
echo "apt updates_regular=$updates_regular"
echo "apt updates_security=$updates_security"
echo "apt updates_packages=\"$updates_packages\""
if [ -n "$release_support" ]; then
echo "apt updates_severity=$(( release_support * 10 + updates_severity))"
fi
if sudo -l /usr/sbin/needrestart -b >> /dev/null; then
needrestart_info=$(sudo needrestart -b)
needrestart_kernel=$(echo "$needrestart_info" | grep -c "NEEDRESTART-KSTA: 3")
needrestart_services=$(echo "$needrestart_info" | grep -c "NEEDRESTART-SVC")
if [ "$needrestart_kernel" -eq 1 ] && [ "$needrestart_services" -gt 0 ]; then
needrestart_severity=3
elif [ "$needrestart_kernel" -eq 1 ]; then
needrestart_severity=2
elif [ "$needrestart_services" -gt 0 ]; then
needrestart_severity=1
else
needrestart_severity=0
fi
echo "apt needrestart_services=$needrestart_services"
echo "apt needrestart_severity=$needrestart_severity"
fi
pkill -P $$
sleep infinity &
wait
done
;;
esac