3
# updates_available: calculate and cache the number of updates available
4
# Copyright (C) 2008 Canonical Ltd.
6
# Authors: Dustin Kirkland <kirkland@canonical.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, version 3 of the License.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
color 2>/dev/null || color() { true; }
23
if [ "$1" = "--detail" -o "$1" = "--short" ]; then
24
if which apt-get >/dev/null; then
25
detail=`apt-get -s -o Debug::NoLocking=true upgrade`
26
if [ "$1" = "--detail" ]; then
29
short=`printf "$detail" | grep ^Inst | wc -l`
40
if [ "$u" -gt 0 ]; then
41
printf "$(color b r W)%d$(color -)$(color r W)!" "$u"
43
if [ "$s" -gt 0 ]; then
54
# Now we actually have to do hard computational work to calculate updates.
55
# Let's try to be "nice" about it:
56
renice 10 $$ >/dev/null 2>&1 || true
57
ionice -c3 -p $$ >/dev/null 2>&1 || true
58
# These are very computationally intensive processes.
59
# Background this work, have it write to the cache files,
60
# and let the next cache check pick up the results.
61
if [ -x /usr/lib/update-notifier/apt-check ]; then
62
# If apt-check binary exists, use it
63
/usr/lib/update-notifier/apt-check 2>&1 | tail -n 1 | sed "s/;/ /" > $mycache &
64
elif which apt-get >/dev/null; then
65
# If apt-get exists, use it
66
apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst > $mycache &
67
elif which zypper >/dev/null; then
68
# If zypper exists, use it
69
zypper --no-refresh lu --best-effort | grep 'v |' | wc -l > $mycache &
70
elif which yum >/dev/null; then
71
# If yum exists, use it
72
# TODO: We need a better way of counting updates available from a RH expert
73
yum list updates -q | egrep -v "Updated Packages" | wc -l > $mycache &
79
# The following is somewhat Ubuntu and Debian specific (apt).
80
# I would welcome contributions from other distros to make this
81
# more distro-agnostic.
83
[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$HOME/.byobu"
84
mycache="$DIR/$PKG.updates-available"
86
# If mycache is present, use it
87
[ -r $mycache ] && print_updates `grep "^[0-9]" $mycache | sed "s/ .*$//"`
89
# Update the cache if necessary
90
if [ ! -e "$mycache" ] || [ "/var/lib/apt" -nt "$mycache" ] || [ "/var/lib/apt/lists" -nt "$mycache" ]; then
91
# If apt is newer than mycache, background an update now
92
update_cache "$mycache"