-
Notifications
You must be signed in to change notification settings - Fork 3
/
slackware_check_for_updates_JBs.sh
executable file
·317 lines (262 loc) · 10.7 KB
/
slackware_check_for_updates_JBs.sh
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
#
# Autor= João Batista Ribeiro
# Bugs, Agradecimentos, Críticas "construtivas"
# me envie um e-mail. Ficarei Grato!
# e-mail: joao42lbatista@gmail.com
#
# Com contibuições de Rumbler Soppa (github.com/rumbler)
#
# Este programa é um software livre; você pode redistribui-lo e/ou
# modifica-lo dentro dos termos da Licença Pública Geral GNU como
# publicada pela Fundação do Software Livre (FSF); na versão 2 da
# Licença, ou (na sua opinião) qualquer versão.
#
# Este programa é distribuído na esperança que possa ser útil,
# mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a
# qualquer MERCADO ou APLICAÇÃO EM PARTICULAR.
#
# Veja a Licença Pública Geral GNU para mais detalhes.
# Você deve ter recebido uma cópia da Licença Pública Geral GNU
# junto com este programa, se não, escreva para a Fundação do Software
#
# Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Script: Script to check for Slackware updates
#
# Last update: 19/06/2023
#
echo -e "\n # Script to check for Slackware updates #"
echo " # Simple check: can make false negative #"
helpMessage() {
echo -e "\nOptions:\n -h this message"
echo " -n to turn notification off"
echo -e "\n # If has a mirror not valid in \"/etc/slackpkg/mirrors\" you can use:"
echo " -s to select one mirror from stable version"
echo " -c to select one mirror from current version"
echo -e " -i to insert your favorite mirror <ftp:|http:|file:>\n"
exit 0
}
optionNotRecognized() {
echo -e "\n Error: The option: \"$1\" is not recognized"
echo -e " For help run: $(basename "$0") -h\n"
exit 1
}
while getopts "hscin" valuesInput; do
case $valuesInput in
'h' )
helpMessage ;;
's' | 'c' | 'i' )
optionInput=$valuesInput ;;
'n' )
notificationOff=1 ;;
* )
optionNotRecognized "$valuesInput" ;;
esac
done
mirrorSuggestion() {
slackwareVersion=$(grep "VERSION=" /etc/os-release | cut -d '"' -f2)
slackwareArch=$(uname -m)
mirrorPart1="http://slackware.uk/slackware/"
mirrorCurrent="${mirrorPart1}slackware64-current/"
if echo "$slackwareArch" | grep -q 64; then
mirrorPart2="slackware64-$slackwareVersion/"
else
mirrorPart2="slackware-$slackwareVersion/"
fi
mirrorFinal=$mirrorPart1$mirrorPart2
if [ "$optionInput" == '' ]; then
echo -e "\nSuggested mirrors to use:"
echo " s - (stable) - $mirrorFinal"
echo " c - (current) - $mirrorCurrent"
echo " i - Or insert your favorite mirror"
echo -en "\nWhich mirror you want? (hit enter to stable): "
read -r optionInput
fi
if [ "$optionInput" == 's' ] || [ "$optionInput" == '' ]; then
mirrorDl=$mirrorFinal
elif [ "$optionInput" == 'c' ]; then
mirrorDl=$mirrorCurrent
elif [ "$optionInput" == 'i' ]; then
mirrorSource=''
testMirrorCommand="echo \"\$mirrorSource\" | grep -vqE \"^ftp:|^http:|^file:\""
while eval "$testMirrorCommand"; do
echo -en "\nType the new mirror: "
read -r mirrorSource
if eval "$testMirrorCommand"; then
echo -e "\nError: the mirror \"$mirrorSource\" is not valid"
echo "One valid mirror has \"ftp:\", \"http:\" or \"file:\""
fi
done
echo -e "\nNew mirror: $mirrorSource"
mirrorDl=$mirrorSource
else
optionNotRecognized "$optionInput"
fi
}
getValidMirror() {
if [ "$mirrorDl" == '' ]; then # Check if mirrorDl was set by mirrorSuggestion()
mirrorDl=$(grep -v "#" /etc/slackpkg/mirrors | head -n 1 | sed 's/ //g')
if [ "$mirrorDl" != '' ]; then
echo -e "\nMirror active in \"/etc/slackpkg/mirrors\":\n\"$mirrorDl\""
mirrorDlTest=$(echo "$mirrorDl" | cut -d "/" -f1)
if [ "$mirrorDlTest" == "file:" ]; then
mirrorDlTmp=$(echo "$mirrorDl" | cut -d '/' -f2-)
if [ ! -d "$mirrorDlTmp" ]; then
echo -e "\nThe mirror folder don't exist: \"$mirrorDl\""
mirrorNotValid=1
else
if [ ! -e "${mirrorDlTmp}ChangeLog.txt" ]; then
echo -e "\nThe \"ChangeLog.txt\" file don't exist: \"${mirrorDlTmp}ChangeLog.txt\""
mirrorNotValid=1
fi
fi
else
if echo "$mirrorDl" | grep -vqE "^http:|^ftp:"; then
mirrorNotValid=1
fi
fi
else
echo -e "\nThere is no mirror active in \"/etc/slackpkg/mirrors\""
echo -e " # Please active one mirror #"
mirrorNotValid=1
fi
fi
if [ "$mirrorNotValid" == 1 ]; then
if [ "$mirrorDl" != '' ]; then
echo -e " # This mirror is not valid #"
fi
mirrorSuggestion
fi
echo -e "\nUsing the mirror: \"$mirrorDl\""
getUpdateMirror
}
alinPrint() {
inputValue=$1
countSpaces=$2
echo -en " # $inputValue"
spacesUsed=${#inputValue}
while [ "$spacesUsed" -lt "$countSpaces" ]; do
echo -n " "
((spacesUsed++))
done
}
tracePrint() {
countTmp=1
echo -n " "
countTotal=$(echo "$count1 * 2 + $count2 * 2 + 13" | bc)
while [ "$countTmp" -lt "$countTotal" ]; do
echo -n "-"
((countTmp++))
done
echo
}
getUpdateMirror() {
echo -e "\nGetting the \"ChangeLog.txt\" from: \"$mirrorDl\". Please wait..."
tmpFile=$(mktemp) # Tmp file to save the "ChangeLog.txt"
mirrorDlTest=$(echo "$mirrorDl" | cut -d "/" -f1)
if [ "$mirrorDlTest" == "file:" ]; then
mirrorDl=$(echo "$mirrorDl" | cut -d '/' -f2-)
echo -e "\n# cp \"${mirrorDl}ChangeLog.txt\" \"$tmpFile\" #"
cp "${mirrorDl}ChangeLog.txt" "$tmpFile"
else
echo -e "\n# wget \"${mirrorDl}ChangeLog.txt\" -O \"$tmpFile\" #\n"
wget "${mirrorDl}ChangeLog.txt" -O "$tmpFile"
fi
changePkgs=$(grep -E "txz|tgz" "$tmpFile") # Find packages to update
count1=20
count2=55
echo
tracePrint
alinPrint "Package name" "$count1"
alinPrint "Version installed" "$count2"
alinPrint "Update available" "$count2"
alinPrint "Summary" "$count1"
echo "#"
tracePrint
for value in $changePkgs; do
packageNameTmp=$(echo "$value" | cut -d ':' -f1 | rev | cut -d '/' -f1)
packageName=$(echo "$packageNameTmp" | cut -d '-' -f4- | rev)
packageNameUpdate=$(echo "$packageNameTmp" | rev)
packageVersionInstalled=$(find /var/log/packages/ -type f | grep "$packageName" | rev | cut -d '/' -f1 | rev)
countPkg=$(echo -e "$packageVersionInstalled" | wc -l) # To test if found more than one package with "$packageName"
countPkgTmp=1
for pkg in $packageVersionInstalled; do
pkgTmp=$(echo "$pkg" | rev | cut -d '-' -f4- | rev)
if [ "$pkgTmp" == "$packageName" ]; then
packageVersionInstalled=$pkg
break
else
if [ "$countPkg" == "$countPkgTmp" ]; then
packageVersionInstalled=''
fi
fi
((countPkgTmp++))
done
versionUpdate=$(echo "$packageNameUpdate" | rev | cut -d '-' -f3 | rev)
versionInstalled=$(echo "$packageVersionInstalled" | rev | cut -d '-' -f3 | rev)
packageNameUpdateTmp=$(echo "$packageNameUpdate" | rev | cut -d '.' -f2- | rev)
locatePackage=$(find /var/log/packages/ -type f | grep "$packageNameUpdateTmp")
if [ "$locatePackage" == '' ]; then # To not print the last package (the already update in the Slackware)
if [ "$packageVersionInstalled" != '' ]; then # To print only if the package has another version installed
updatesFound=1
alinPrint "$packageName" "$count1"
alinPrint "$packageVersionInstalled" "$count2"
alinPrint "$packageNameUpdate" "$count2"
if [ "$versionInstalled" == "$versionUpdate" ]; then
alinPrint "Rebuilt" "$count1"
else
alinPrint "$versionInstalled to $versionUpdate" "$count1"
fi
echo "#"
tracePrint
fi
else
valueToStopPrint=$packageNameUpdateTmp
break
fi
done
changesToShow=$(sed '/'"$valueToStopPrint"'/q' "$tmpFile")
countLinesTmp=$(echo "$changesToShow" | grep -c "\+\-\-\-\-\-\-")
if [ "$countLinesTmp" == 0 ]; then
countLinesTmp=1
else
((countLinesTmp++))
fi
lastLineToPrint=$(cat -n "$tmpFile" | grep "\+\-\-\-\-\-\-" | grep -v '^\-\-$' | sed ''"$countLinesTmp"' q' | tail -n 1 | awk '{print $1}')
if [ "$updatesFound" == 1 ]; then
updaesAvailable=$(sed ''"$lastLineToPrint"' q' "$tmpFile")
updaesAvailable=$(echo -e "\n+--------------------------+\n$updaesAvailable")
echo -e "$updaesAvailable\n"
updaesAvailable=${updaesAvailable//'"'/'\"'} # Change " to \" go get error with "echo "notify-send""
iconName="audio-volume-high"
notificationToSend=$(echo -e "notify-send \"$(basename "$0")\n\n Updates available\" \"$updaesAvailable\" -i \"$iconName\"")
else
updatesFound=0
lastKernelUpdate=$(grep "kernel-generic" "$tmpFile" | grep -v "testing/" | head -n 1 | cut -d '-' -f3)
lastKernelInstalled=$(ls /var/log/packages/kernel-*"$lastKernelUpdate"* 2> /dev/null)
if [ "$lastKernelInstalled" == '' ]; then
lastKernelUpdate=$(grep "patches/packages/linux" "$tmpFile" | grep -v "testing/" | head -n 1 | cut -d '/' -f3 | cut -d '-' -f2)
lastKernelInstalled=$(ls /var/log/packages/kernel-*"$lastKernelUpdate"* 2> /dev/null)
if [ "$lastKernelInstalled" == '' ]; then
echo -e "\n # Kernel update: $lastKernelUpdate #\n"
iconName="audio-volume-high"
notificationToSend=$(echo -e "notify-send \"$(basename "$0")\n\n Updates available\" \"Kernel update: $lastKernelUpdate\" -i \"$iconName\"")
updatesFound=1
fi
fi
if [ "$updatesFound" == 0 ]; then
echo -e "\n # Updates not found #\n"
iconName="audio-volume-muted"
notificationToSend=$(echo -e "notify-send \"$(basename "$0")\n\n Updates not found\" \"No news is good news\" -i \"$iconName\"")
fi
fi
rm "$tmpFile"
if [ "$notificationOff" != 1 ]; then
eval "$notificationToSend"
fi
}
if [ "$optionInput" != '' ]; then
mirrorSuggestion
fi
getValidMirror