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
|
#!/bin/sh
# expire the cache in X seconds; 1 hour by default
EXPIRATION=3600
print_updates() {
u=$1
if [ "$u" = "0" ]; then
echo ""
else
echo "$u!"
fi
exit 0
}
cache=/var/run/updates-available
mycache=/var/tmp/updates-available-$USER
u=
# If global updates-available cache is present, use it.
# Only available in Jaunty+.
if [ -r $cache ]; then
u=`grep -m 1 "^[0-9]" $cache | sed "s/\s.*$//"`
print_updates $u
fi
# If the user's updates-available cache is present, and less than an hour old,
# use it. (The "hour" part should be configurable)
if [ -r $mycache -a -O $mycache ]; then
now=`date +%s`
timestamp=`stat -c "%Y" $mycache`
diff=`expr $now - $timestamp`
if [ $diff -lt $EXPIRATION ]; then
u=`grep -m 1 "^[0-9]" $mycache | sed "s/\s.*$//"`
print_updates $u
fi
fi
# If apt-check binary exists, use it
if [ -x /usr/lib/update-notifier/apt-check ]; then
u=`/usr/lib/update-notifier/apt-check 2>&1 | tail -n 1 | sed "s/;.*$//"`
echo "$u" > $mycache
print_updates $u
fi
# If apt-get exists, use it
if [ -x /usr/bin/apt-get ]; then
u=`/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst`
echo "$u" > $mycache
print_updates $u
fi
# If yum exists, use it
if [ -x /usr/bin/yum ]; then
u=`/usr/bin/yum list updates | grep -c "updates"`
print_updates $u
fi
# If we're here, we have no idea
print_updates "?"
|