-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzen_notify
More file actions
executable file
·229 lines (222 loc) · 7.77 KB
/
zen_notify
File metadata and controls
executable file
·229 lines (222 loc) · 7.77 KB
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
#!/bin/bash
# Zen_notify
# mar. oct. 11 16:21:02 CEST 2016 (initial prequel)
# Copyright 2022-2026 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
set -euo pipefail
# export PS4='->$(tput setaf 6)${LINENO}$(tput sgr 0)$(printf "\\t")-> '
## 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
git_hub_api="https://api.github.com/repos/wildtruc/zenvidia/commits?sha=master&per_page=1"
git_lab_api="https://gitlab.com/api/v4/projects/56148921/repository/commits?sha=master&per_page=1"
## gitlhub check (0), gitlab check (1)
git_master=0
declare -a _driver_notif=()
declare driver_up=0 zen_up=0
connected(){
local site=${site:-$nvidia_base_url}
ping -c2 $site &>/dev/null; echo "$?"
}
version_array(){
# synt : version_array [object]
local version=${1}
local count_array c part prefix='' suffix='' local IFS=' '
count_array=( $(echo "$version"|tr . ' ') )
for c in ${count_array[@]}; do
(( ${#c} < 3 )) && prefix=0 || prefix=''
part+=$(printf ${prefix}$c)
done
[ ${#count_array[@]} -eq 3 ] || suffix='000'
echo "${part[*]}$suffix"
return
}
git_local_version(){ [ -f ${local_nvdir}/zen_version ] && cat ${local_nvdir}/zen_version || cat ${nvdir}/zen_version; }
git_log_message(){
git_master=0
if [ ${git_master} = 0 ]; then
curl -s "$git_hub_api" | jq -r '.[].commit.message'
else
curl -s "$git_hub_api" | jq -r '.[].message'
fi
}
driver_ctrl(){
## reset all value.
# unset ver_array last_array DRV_LIST
local last_array=() DRV_LIST=() # ver_array=()
local drv_diff=0 greater=0 rem_diff=0
local prefix='' suffix='' msg_suffix=''
local LAST_DRV=0 LAST_BETA=0 version=0
drv_temp=$(mktemp $notif_temp/drv_notif-XXXX)
if [ $(connected) -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 || true)
else
version=$(modinfo -F version nvidia || true)
fi
if (( $(version_array "$LAST_BETA") != $(version_array "$LAST_DRV") )); then
rem_diff=1 ; last_array=( $(version_array "$LAST_BETA") )
else
rem_diff=0 ; last_array=( $(version_array "$LAST_DRV") )
fi
for last in ${last_array[@]}; do
(( ${last} == $(version_array "$version") )) || drv_diff=1
(( ${last} > $(version_array "$version") )) && 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
if [ ${#DRV_LIST[@]} -gt 0 ]; then
local sol eol
local IFS=$'\n'
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=$((cnt+1))
fi
done
if [[ $greater -gt 0 || ! "$(echo -e "${DRV_LIST[*]}")" =~ $(modinfo -F version nvidia) ]]; then
notif_msg+=$"Nvidia driver "
driver_up=1
fi
fi
else
notif_msg=$"Nvidia driver notification"
_driver_notif+=$"<b>WARNING</b> : No Signal"
msg_suffix=''
fi
}
source_ctrl(){
if [ $(connected) -eq 0 ]; then
# tmp_git_src=$(mktemp -d $notif_temp/tmp_git.XXX)
test -f $local_src/zen_git.log || touch $local_src/zen_git.log
# git_lab_api="https://gitlab.com/api/v4/projects/56148921/repository/commits?sha=master&per_page=1"
if [ $driver_up -gt 0 ]; then
notif_txt=$"and Zenvidia"; line='\n'
else
notif_txt='Zenvidia'; line=''
fi
if [ ${git_master} = 0 ]; then
git_remote_version=$(curl -s "$git_hub_api" | jq -r '.[].commit.message'| sed -n '1p')
git_remote_date=$(curl -s "$git_hub_api" | jq -r '.[].commit.committer.date'| awk -F"T" '{print $1}')
# git_pull_date=$(date -d "@$git_remote_date" +%Y''%m''%d)
else
git_remote_version=$(curl -s "$git_lab_api" | jq -r '.[].title')
git_remote_date=$(curl -s "$git_lab_api" | jq -r '.[].date'| awk -F"T" '{print $1}')
# git_pull_date=$(date -d "@$git_remote_date" +%Y''%m''%d)
fi
if [[ $(git_local_version) != ${git_remote_version} ]]; then
if (( $(grep -c "${git_remote_version}" $local_src/zen_git.log) == 0 )); then
git_log_tee="$(cat <<-LOG
$git_remote_date - $(git_log_message)
LOG
)"
echo -e "* $git_log_tee" | tee -a $local_src/zen_git.log
fi
notif_msg+="$notif_txt "
_driver_notif+=($"${line}zenvidia git repo update.""\n""$git_remote_date $git_remote_version")
zen_up=1
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 [[ $(connected) -eq 0 ]]&&[[ $driver_up -gt 0 || $zen_up -gt 0 ]]; then
if (( $(connected) == 0 ))&&(( ${driver_up} > 0 || ${zen_up} > 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