-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzen_notify
executable file
·292 lines (287 loc) · 9.3 KB
/
zen_notify
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash
# Zen_notify
# mar. oct. 11 16:21:02 CEST 2016
# Copyright 2010-2016 PirateProd
# <wildtruc@noneltd.net>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with main.c;if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
## basics
local_nvdir=/home/$USER/.zenvidia
nvdir=/usr/local/share/zenvidia
script_conf=$nvdir/script.conf
basic_conf=$local_nvdir/basic.conf
nvtmp=$local_nvdir/notify
# deficon=swiss_knife
deficon=zen-emblem
## check if zen_taskbar_menu exit
zen_bar=$(command -v zen_task_menu)
export PATH=$PATH:/usr/local/bin
export TEXTDOMAIN=zenvidia
export TEXTDOMAINDIR=$nvdir/locale
[ $script_conf ] || exit 0
. $script_conf
. $basic_conf
## script could need to sleep during the desktop session boot time.
## to uncomment only in case of session autostart notif issue.
# sleep 15
[ -d $nvtmp ] || mkdir -p $nvtmp
notif_temp=$(mktemp --tmpdir -d zen_notif-XXXX)
ARCH=$HOSTTYPE
drv_list=$nvtmp/drvlist
last_update=$nvtmp/last_update
last_beta=$nvtmp/last_beta
local_src=$local_nvdir/src
[ -d $local_src ] || mkdir -p $local_src
## reset all notif display options
driver_up=0
zen_up=0
msg_suffix=$"update"
ping -c2 www.nvidia.com &>/dev/null
cnx=$?
ifs=$IFS
## capture for exit status
trap "IFS=\$ifs rm -Rf $notif_temp" EXIT
driver_ctrl(){
## reset all value.
unset ver_array last_array DRV_LIST
drv_diff=0
greater=0
rem_diff=0
drv_temp=$(mktemp $notif_temp/drv_notif-XXXX)
if [ $cnx -eq 0 ]; then
## default driver caracters max count.
nb=9
## get all driver list.
wget -q -O $drv_temp https://$nvidia_ftp-$ARCH/
## get latest.txt file.
wget -q -O $last_update https://$nvidia_ftp-$ARCH/latest.txt
## latest.txt fiel dfine current official version.
## end of all driver list define the beta version if different from diiferent of official.
cat $drv_temp| sed -En "s/^.*href.*'(.*)\/'>.*$/\1/p" > $drv_list
cat $drv_temp| sed -En "s/^.*href.*'(.*)\/'>.*$/\1/p"| tail -n1 > $last_beta
LAST_DRV=$(cat $last_update | awk '{ print $1 }')
LAST_BETA=$(cat $last_beta)
if [ -s $nvdir/version.txt ]; then
version=$(cat $nvdir/version.txt)
else
version=$(modinfo -F version nvidia)
fi
## driver version could be in the form xxx.xxx.xxx or xxx.xx
## it is needed to short it to number only.
offi_short(){
if [ "$LAST_DRV" ]; then
unset count_array prefix part
count_array=( $(printf "$LAST_DRV"|tr . ' ') )
for c in ${count_array[@]}; do
i=$(printf "$c"|wc -m)
for ((i=$i; i<3; i++)) { prefix='0';}
part+=$(printf ${prefix}$c)
done
[ ${#count_array[*]} -eq 3 ] || suffix='000'
echo "${part[*]}$suffix"
else
echo "0"
fi
}
beta_short(){
if [ "$LAST_BETA" ]; then
unset count_array prefix part
count_array=( $(printf "$LAST_BETA"|tr . ' ') )
for c in ${count_array[@]}; do
i=$(printf "$c"|wc -m)
for ((i=$i; i<3; i++)) { prefix='0';}
part+=$(printf ${prefix}$c)
done
[ ${#count_array[*]} -eq 3 ] || suffix='000'
echo "${part[*]}$suffix"
else
echo "0"
fi
}
ver_array(){
if [ "$version" ]; then
unset count_array prefix part
count_array=( $(printf "$version"|tr . ' ') )
for c in ${count_array[@]}; do
i=$(printf "$c"|wc -m)
for ((i=$i; i<3; i++)) { prefix='0';}
part+=$(printf ${prefix}$c)
done
[ ${#count_array[*]} -eq 3 ] || suffix='000'
echo "${part[*]}$suffix"
else
echo "0"
fi
}
if [ $(beta_short) -ne $(offi_short) ]; then
rem_diff=1 ; last_array=( $(beta_short) )
else
rem_diff=0 ; last_array=( $(offi_short) )
fi
for last in ${last_array[@]}; do
[ ${last} -eq $(ver_array) ] || drv_diff=1
[ ${last} -gt $(ver_array) ] && greater=1
done
if [ $rem_diff -eq 1 ]; then
DRV_LIST=( $"$LAST_DRV, official driver" $"$LAST_BETA, beta driver" )
else
DRV_LIST=( $"$LAST_DRV, official drivers" )
fi
echo -e "${DRV_LIST[*]}"
if [ ${#DRV_LIST[@]} -gt 0 ]; then
IFS=$(echo -en "\n\b")
cnt=0
for drv_line in ${DRV_LIST[@]}; do
driver=$(printf "$drv_line"|cut -d',' -f1)
release=$(printf "$drv_line"|cut -d',' -f2)
if [ $drv_diff -gt 0 ]; then
if [ $cnt -eq 0 ]; then sol='';eol=''; else sol='\n';eol=''; fi
if [[ $(grep -E -c "$driver" $drv_list) -gt 0 ]]; then
_driver_notif+=( $"$sol<b>$driver</b> $release.$eol" )
else
_driver_notif+=( $"$sol<b>$driver</b> $release update.\n<i>(not dowloadable yet)</i>$eol" )
fi
((cnt++))
fi
done
if [[ $greater -gt 0 || ! "$(echo -e "${DRV_LIST[*]}")" =~ $(modinfo -F version nvidia) ]]; then
notif_msg+=$"Nvidia driver "
driver_up=1
fi
fi
fi
if [ $cnx -gt 0 ]; then
unset _driver_notif
notif_msg=$"Nvidia driver notification"
_driver_notif+=$"<b>WARNING</b> : No Signal"
msg_suffix=''
fi
}
source_ctrl(){
if [ $cnx -eq 0 ]; then
rep_git_local=$(find -P $HOME -maxdepth 4 -name "zenvidia" -type d)
if [ -d $rep_git_local ]; then
if [ $driver_up -gt 0 ]; then
notif_txt=$"and Zenvidia"; line='\n'
else
notif_txt='Zenvidia'; line=''
fi
tmp_git_src=$(mktemp -d $notif_temp/tmp_git.XXX)
test -f $local_src/zen_git.log || touch $local_src/zen_git.log
IFS=$(echo -en "\n\b")
CHECK_GIT_REPO(){
local_date=$(env LANG=En_en date +%Y''%m''%d)
# extract date from log
git_rm_fetch_date=$(git log -n1 | sed -n '/Date/p'| awk '{print $3" "$4" "$6}')
# convert date to comparable number
git_rm_date=$(date -d "$git_rm_fetch_date" +%Y''%m''%d)
# extract version line
git_rm_version=$(git log -n1 | grep -E -o "v[0-9].*")
git_local_version=$(cat $local_nvdir/zen_version)
# git_local_version=$(cat $nvdir/zen_version)
git_rm_fetch_log=$(git log -n1 | sed -n "/-/,/-/p")
# before acting, we need to know the last pull record in local dir.
if [ $rep_git_local ]; then
pushd $rep_git_local
git_local_pull_date=$(cat .git/logs/refs/heads/master| grep "clone\|pull"|awk '{print $5}'|sed -n '$p')
git_pull_date=$(date -d "@$git_local_pull_date" +%Y''%m''%d)
if [ ! "$git_local_version" ]; then
git_local_version=$(git log -n1 | grep -E -o "v[0-9].*")
test "$git_local_version" || git_local_version=0
echo -e "$git_local_version" > $nvdir/zen_version
fi
popd
else
git_pull_date=0
git_local_version=0
fi
# then, we need to know if log is about version update or issue warning message.
# log and issue is mandatory formated with a '-' in commit message.
# ISSUE is by default set to 0.
issue=0
if [ ${#git_rm_fetch_log[*]} -gt 0 ]; then
if [ "$git_rm_version" ]&&[ "$git_rm_version" != "$git_local_version" ]; then
if [ $(grep -c "$git_rm_fetch_date" $local_src/zen_git.log) -eq 0 ]; then
if [ $(grep -c "\-" <<< ${git_rm_fetch_log[*]}) -gt 0 ]; then
cat <<-LOG >> $local_src/zen_git.log
$git_rm_fetch_date : $git_rm_version
$git_rm_fetch_log
LOG
fi
fi
else
if [ $(grep -c "\- ISSUE :" <<< ${git_rm_fetch_log[*]}) -gt 0 ]; then
issue=1
git_rm_warn_log=$(cut -d'-' -f2 <<< ${git_rm_fetch_log[*]})
fi
fi
fi
# if last pull/clone date is lower than the remote's, display update message.
if [ $git_pull_date -lt $git_rm_date ]; then
if [ "$git_rm_version" != "$git_local_version" ]; then
zen_up=1
# is the log message an issue warning ?
if [ $issue = 0 ]; then
notif_msg+="$notif_txt "
_driver_notif+=($"${line}zenvidia git repo update.\n$git_rm_fetch_date $git_rm_version")
else
notif_msg+="$notif_txt "
_driver_notif+=($"${line}zenvidia git warning.\n$git_rm_fetch_date $git_rm_warn_log")
fi
fi
fi
}
# clone remote .git dir only to get changes.
pushd $tmp_git_src
git clone -n --depth=1 $zenvidia_git .
# then check diff in date, then in data, if local repos exist.
CHECK_GIT_REPO
popd
else
zen_up=0
fi
fi
}
notifying(){
# only display notif if driver_ctrl or source_ctrl are true.
test -f $local_nvdir/taskbar_message || touch $local_nvdir/taskbar_message
echo -e "notif=0" > $local_nvdir/taskbar_message
if [[ $cnx -eq 0 ]]&&[[ $driver_up -gt 0 || $zen_up -gt 0 ]]; then
notify-send -t 5000 -u low -i "$deficon" $"${notif_msg[*]}$msg_suffix" "$(echo "${_driver_notif[@]}")"
echo -e "notif=1" > $local_nvdir/taskbar_message
echo -e "notif_text=\"${_driver_notif[@]}\"" >> $local_nvdir/taskbar_message
fi
## launch zen_taskbar.
if [ -e $zen_bar ]; then
exec $zen_bar &
fi
}
usage_help(){
printf "# Usage : zen_notify [option], where option are:\n"
printf "\t -z : check nvidia & zenvidia.\n"
printf "\t -n : check nvidia only.\n"
printf "\t -h : this help.\n"
}
# icon_set=$deficon
test $# -gt 0 || usage_help
while [ $# -gt 0 ]
getopts "z n h" OPT; do
case $OPT in
z) driver_ctrl; source_ctrl; notifying
;;
n) driver_ctrl; notifying
;;
h) usage_help ;;
esac
done