-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_debianoffspring_updates.sh
80 lines (70 loc) · 2.73 KB
/
check_debianoffspring_updates.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
#!/bin/bash
script="check_debianoffspring_updates.sh"
version="1.0.0"
author="John Gonzalez"
while getopts ":v" opt; do
case $opt in
v)
echo "$script - $author - $version"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Check the operating system
if [ -f "/etc/debian_version" ]; then
# Debian logic
# Check for updates
updates=$(apt list --upgradable 2>/dev/null | grep -c /)
# Check for security, stable, and recommended updates
security=$(apt list --upgradable 2>/dev/null | grep -c /.*security)
stable=$(apt list --upgradable 2>/dev/null | grep -c /.*stable)
# Check for kernel updates
kernel=$(apt list --upgradable linux-image-* 2>/dev/null | grep -c linux-image)
if [ $updates -eq 0 ]; then
echo "No updates available."
exit 0
elif [ $security -gt 0 ] || [ $stable -gt 0 ] || [ $kernel -gt 0 ]; then
echo "$updates Debian updates are available. $security are security updates, $stable are stable updates, $kernel are kernel updates."
exit 2
else
echo "$updates Debian updates are available. $security are security updates, $stable are stable updates, $kernel are kernel updates."
exit 1
fi
elif [ -f "/etc/lsb-release" ]; then
# Ubuntu logic
# Check for updates
updates=$(apt list --upgradable 2>/dev/null | grep -c /)
# Check for security, stable, and recommended updates
security=$(apt list --upgradable 2>/dev/null | grep -cE '/.*security|/.*ubuntu.*security')
stable=$(apt list --upgradable 2>/dev/null | grep -cE '/.*stable|/.*ubuntu.*stable')
# Check for kernel updates
kernel=$(apt list --upgradable linux-image-* 2>/dev/null | grep -c linux-image)
# Check if any packages are in phased update
phased_updates=0
for package in $(apt list --upgradable 2>/dev/null | awk -F/ '{print $1}'); do
policy_output=$(apt-cache policy "$package")
if echo "$policy_output" | grep -q "phased"; then
phased_updates=$((phased_updates + 1))
fi
done
if [ $updates -eq 0 ]; then
echo "No updates available."
exit 0
elif [ $phased_updates -eq $updates ]; then
echo "$updates Ubuntu updates are available. All updates are in phased update."
exit 0
elif [ $security -gt 0 ] || [ $stable -gt 0 ] || [ $kernel -gt 0 ] || [ $phased_updates -gt 0 ]; then
echo "$updates Ubuntu updates are available. $security are security updates, $stable are stable updates, $kernel are kernel updates. $phased_updates updates are in phased updates."
exit 2
else
echo "$updates Ubuntu updates are available. $security are security updates, $stable are stable updates, $kernel are kernel updates. $phased_updates updates are in phased updates."
exit 1
fi
else
echo "Unsupported operating system"
exit 1
fi