-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-updates
executable file
·64 lines (53 loc) · 1.95 KB
/
check-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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
#
# Checks Slackware updates and informs the user via Desktop
# notifications.
#
# If this is run as a non-root user, it checks the updates and informs
# the user via Desktop notifications whether there are news or not.
#
# If this is run as root, it updates the package list(s) and informs
# the user via Desktop notifications what are the package upgrades (if
# any). This can be installed as a daily cron job by running the
# following as root:
#
# $ cp check-updates /etc/cron.daily
# 'notify-send' timeout in milliseconds
readonly TIMEOUT=5000
# Wait for network connectivity
sleep 5s
# Check if a mirror is set.
readonly MIRROR=$(grep -v "#" /etc/slackpkg/mirrors | cut -d "/" -f 3)
if [[ -z "${MIRROR}" ]]; then
/usr/bin/notify-send -t "${TIMEOUT}" "You need to select a slackpkg mirror"
exit
fi
if ! ping -c 1 "${MIRROR}" 2>&1 > /dev/null; then
/usr/bin/notify-send -t "${TIMEOUT}" "Unable to check updates"
exit
fi
if [[ $(id -u) == 0 ]]; then
# Root can update the list of packages and display the upgrades.
# Update package lists only if there are news in the changelog.
/usr/sbin/slackpkg -dialog=off -batch=on -default_answer=n update
# Get list of package upgrades in the format [repository]package
UPGRADES=$(/usr/sbin/slackpkg -dialog=off -batch=on -default_answer=n upgrade-all | \
grep -E -e ".+\.t.z" | \
sed -e 's, *, ,g' | \
sed -e 's, ,[,' | \
sed -e 's, ,],' | \
tr -d ' ' | \
sed -e 's,\.t.z,,')
if [[ -n "${UPGRADES}" ]]; then
UPGRADES="Package upgrades: ${UPGRADES}"
/usr/bin/notify-send -t "${TIMEOUT}" "${UPGRADES}"
else
/usr/bin/notify-send -t "${TIMEOUT}" "All up-to-date"
fi
else
# Non-root can only display whether there are news or not.
readonly MSG=$(/usr/sbin/slackpkg -dialog=off -batch=on check-updates | grep -i news)
if [[ -n "${MSG}" ]]; then
/usr/bin/notify-send -t "${TIMEOUT}" "${MSG}"
fi
fi