-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspun-live
executable file
·115 lines (104 loc) · 3.67 KB
/
spun-live
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# simple pacman update notifier
# a very simplistic update notification script written
# in bash, using notify-send and kdialog.
TEXTDOMAIN=spun
main() {
if [[ $1 == '-h' || $1 == '--help' ]]; then
echo $"Simple pacman update notifier, v0.3"
echo $"Usage: spun [OPTIONS]"
echo $"Options: "
echo $" -g, --gui show the kdialog configuration GUI"
exit 0
elif [[ $1 == '-g' || $1 == '--gui' ]]; then
gui=1
gui
fi
# If the gui is enabled, make sure kdialog is installed
if [[ $gui == 1 ]]; then
checkgui || (echo $"kdialog cannot be found"; exit 1)
fi
# Check to see if the script is already running
if [[ -r /tmp/spun/pid ]]; then
kill -CONT $(cat "$tmpdir/pid" 2>/dev/null) 2>/dev/null &&
fail $"spun is already running!\nonly one instance can be run at a time."
fi
# Calculate seconds to sleep:
[[ $waittime -le 10080 && $waittime -ge 1 ]] &&
let sleeptime=$waittime*60 ||
fail $"Bad value for 'waittime' variable.\nMust be an integer between 1 and 10080."
[[ $daemon == 1 ]] || dothings && daemon
}
isignored() {
oifs=$IFS IFS=$'\n'
local ignoredpkgs=( $(grep '^ *IgnorePkg' "$pacmanconf" | cut -d '=' -f 2-) )
IFS=$oifs
grep -q "^[ ]*$1[ ]*[^ ]*" <<< "${ignoredpkgs[@]}"
}
check() {
[[ -f $tmpdir ]] || mkdir -p "$tmpdir"
[[ -e "$tmpdir/local" ]] || ln -s /var/lib/pacman/local "$tmpdir"
[[ -z $update ]] && eval $update >&2>>"$tmpdir/log"
eval $check | tee -a "$tmpdir/log"
}
daemon() {
echo -n $":: Starting spun... "
mkdir -p $tmpdir
dothings &
echo $" [Done]"
}
checkgui() {
if test -x $(which kdialog); then
return 0
else
echo $"Sorry, kdialog cannot be found."
exit 1
fi
}
gui() {
checkgui
nwaittime=$(kdialog --inputbox $"Minutes to wait between each check for updates:" $waittime \
--title $"SPUN Config" | sed 's/[^0-9].*//g')
if [[ $nwaittime == "" ]]; then nwaittime=$waittime; fi
if ! [[ $nwaittime -le 10080 && $nwaittime -ge 1 ]]; then
fail $"The value you specified is invalid."
else
sed -i "s/^waittime=.*/waittime=$nwaittime/" ~/.spunrc
fi
nicon=$(kdialog --geticon actions --title $"Choose notification icon - SPUN Config")
if [[ $nicon == "" ]]; then nicon=$icon; fi
sed -i "s/^icon=.*/icon='$nicon'/" ~/.spunrc && kdialog --msgbox $"Configuration saved.\nThe script must be restarted for changes to take effect." ||
kdialog --error $"Configuration could not be saved.\nMake sure /etc/spun.conf exists and ~/.spunrc is writable."
exit 0
}
dothings() {
[[ $daemon == 1 ]] && echo $BASHPID > "$tmpdir/pid"
while true; do
upkgz=( )
for pkg in $(check); do
isignored $pkg || upkgz+=( $pkg )
done
[[ -n ${upkgz[@]} ]] && notify "${upkgz[@]}"
sleep $sleeptime
done
}
notify() {
npkgz=( )
for pkg in "$@"; do
grep -q " $pkg " <<< "${notified[@]}" || npkgz+=( "$pkg" ) notified+=( " $pkg " )
done
[[ -n "${npkgz[@]}" ]] && eval $notify $n_opts $"'There are updates available!'" \
\"$"Run 'sudo pacman -Syu' to update.\n \
<a href=http://chakraos.org/wiki/index.php?title=Pacman>Visit the Chakra wiki</a> to learn more about Pacman. \n\
Updates are available for the following package(s): \n" "${npkgz[*]}"\"
[[ -n "${npkgz[@]}" && -n "$playwith" && -n "$audio" ]] && eval $playwith $audio >/dev/null 2>/dev/null &
}
fail() {
[[ $gui != 1 ]] && printf "$1\n" ||
kdialog --error "$1"
exit 1
}
[[ -r /etc/spun.conf ]] && source /etc/spun.conf || fail $"/etc/spun.conf cannot be found or is invalid!"
[[ -r ~/.spunrc ]] && source ~/.spunrc || /bin/cp /etc/spun.conf ~/.spunrc
daemon=${daemon-1} waittime=${waittime-5} notified=( )
main "$@"