-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtbxmalib
More file actions
389 lines (359 loc) · 10.9 KB
/
tbxmalib
File metadata and controls
389 lines (359 loc) · 10.9 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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#!/bin/bash
#tbxmalib_dir=$(dirname "$(readlink -f ${0})")
# Remove some mystery
TRUE=0
FALSE=1
OVERWRITE=1
APPEND=0
declare -g ACSO_KERNEL_INFO_ARRAY_STR
declare -ga ACSO_KERNEL_INFO_INDEX
declare -gA ACSO_KERNEL_INFO_ARRAY
declare -r ACSO_KERNEL_KEYS=("version" "branch" "endoflife" "source" "released" "url")
declare -g TBXML_LIB_FUNC_RESULT
function test_customarray(){
get_linuxinfo_str
dump_kerninfo_str "${ACSO_KERNEL_INFO_ARRAY_STR}"
echo -e "${TBXML_LIB_FUNC_RESULT}"
echo "----------------------"
get_item "${ACSO_KERNEL_INFO_ARRAY_STR}" "5.14-rc5" 'url'
#IFS=$'\n'
echo "${TBXML_LIB_FUNC_RESULT}" #quote these - things get magled containinga dot .followed by a 1
echo "----------------------"
build_kerninfo_array "${ACSO_KERNEL_INFO_ARRAY_STR}"
dump_kerninfo_arr
# echo $(get_item "4.19.202")
}
# check TBXML_LIB_FUNC_RESULT for the result of this or any function in here
function dump_kerninfo_str(){
local result IFS
# echo #broken here
while IFS=">" read -d '<' TAG VALUE ; do
if [[ "${TAG}" = "item" ]] ; then
result="${result}\n${TAG}=("
else
[[ "${TAG:0:1}" != "/" ]] && result="${result}\n\t${TAG}=${VALUE}"
[[ "${TAG}" == "/item" ]] && result="${result} )"
fi
done < <(echo -e "${1}")
result+=" )"
TBXML_LIB_FUNC_RESULT="${result}"
#echo -e "${TBXML_LIB_FUNC_RESULT}"
}
function dump_kerninfo_arr(){
for i in "${!ACSO_KERNEL_INFO_INDEX[@]}" ; do
item="${ACSO_KERNEL_INFO_INDEX[$i]}"
echo -e "item=${item}"
for item_key in "${ACSO_KERNEL_KEYS[@]}" ; do
nk="${item_key},${i}"
value=${ACSO_KERNEL_INFO_ARRAY["${nk}"]}
echo -e "\t${item_key}=${value}"
done
echo "---------------"
done
}
function clear_array(){
unset ACSO_KERNEL_INFO_INDEX
unset ACSO_KERNEL_INFO_ARRAY
declare -ga ACSO_KERNEL_INFO_INDEX
declare -gA ACSO_KERNEL_INFO_ARRAY
}
function build_kerninfo_array(){
useage="build_kerninfo_array source_xml_string (usually ACSO_KERNEL_INFO_ARRAY_STR) "
[ $# -lt 1 ] && exception "${useage}"
local IFS record recordid
recordid=""
clear_array
while IFS=">" read -d '<' TAG VALUE ; do
VALUE="${VALUE//[[:space:]]}"
case $TAG in
'item')
title=''
version=''
branch=''
endoflife=''
source=''
released=''
url=''
if [ -z "${recordid}" ]; then
recordid=0
else
((recordid+=1))
fi
;;
'title')
title="${VALUE}"
;;
'version')
version="${VALUE}"
;;
'branch')
branch="${VALUE}"
;;
'endoflife')
endoflife="${VALUE}"
;;
'source')
source="${VALUE}"
;;
'released')
released="${VALUE}"
;;
'url' )
url="${VALUE}"
;;
'/item')
ACSO_KERNEL_INFO_INDEX[${recordid}]=${version}
ACSO_KERNEL_INFO_ARRAY["version,${recordid}"]="${version}"
ACSO_KERNEL_INFO_ARRAY["branch,${recordid}"]="${branch}"
ACSO_KERNEL_INFO_ARRAY["endoflife,${recordid}"]="${endoflife}"
ACSO_KERNEL_INFO_ARRAY["source,${recordid}"]="${source}"
ACSO_KERNEL_INFO_ARRAY["released,${recordid}"]="${released}"
ACSO_KERNEL_INFO_ARRAY["url,${recordid}"]="${url}"
;;
esac
done < <(echo "${1}")
}
# check TBXML_LIB_FUNC_RESULT for the result of this or any function in here
function get_item(){
local result_field record result IFS
useage="get_item haystack neeedle (result_field) optional "
[ $# -lt 2 ] && exception "${useage}"
[ $# -eq 3 ] && result_field="${3}"
srch_term="${2}"
local match
match=$FALSE
while IFS='>' read -d '<' TAG VALUE ; do
#echo -e "${TAG}=${VALUE}\n"
# TAG=${TAG//[[:space:]]}
# VALUE=${VALUE//[[:space:]]}
case $TAG in
'item')
title=''
version=''
branch=''
endoflife=''
source=''
released=''
url=''
;;
'title')
title="${VALUE}"
[ "${VALUE}" == "${srch_term}" ] && match=$TRUE
;;
'version')
version="${VALUE}"
[ "${VALUE}" == "${srch_term}" ] && match=$TRUE
;;
'branch')
branch="${VALUE}"
[ "${VALUE}" == "${srch_term}" ] && match=$TRUE
;;
'endoflife')
endoflife="${VALUE}"
[ "${VALUE}" == "${srch_term}" ] && match=$TRUE
;;
'source')
source="${VALUE}"
[ "${VALUE}" == "${srch_term}" ] && match=$TRUE
;;
'released')
released="${VALUE}"
[ "${VALUE}" == "${srch_term}" ] && match=$TRUE
;;
'url' )
url="${VALUE}"
[ "${VALUE}" == "${srch_term}" ] && match=$TRUE
;;
'/item')
if [ "${match}" == "$TRUE" ] ; then
if [ -n "${result_field}" ] ; then
declare -A rec
#rec["title"]="${title//[[:space:]]}"
rec["version"]="${version//[[:space:]]}"
rec["branch"]="${branch//[[:space:]]}"
rec["endoflife"]="${endoflife//[[:space:]]}"
rec["source"]="${source//[[:space:]]}"
rec["released"]="${released//[[:space:]]}"
rec["url"]="${url//[[:space:]]}"
#for f in 'title version branch endoflife source released url' ;
for f in "${!rec[@]}" ;
do
if [ "${result_field}" == "${f}" ] ; then
result="${rec[$f]}"
break
fi
done
else
#record="<title>${title//[[:space:]]}</title>"
record="<version>${version//[TBXML_LIB_FUNC_RESULT[:space:]]}</version>"
record+="<branch>${branch//[[:space:]]}</branch>"
record+="<endoflife>${endoflife//[[:space:]]}</endoflife>"
record+="<source>${source//[[:space:]]}</source>"
record+="<released>${released//[[:space:]]}</released>"
record+="<url>${url//[[:space:]]}</url>"
result="${record}"
break
fi
fi
match=$FALSE
;;
esac
done < <(echo "${1}")
TBXML_LIB_FUNC_RESULT=$result
#echo $TBXML_LIB_FUNC_RESULT
return 1
}
# xmlgetnext () {
# local IFS='>'
# read -d '<' TAG VALUE
# }
function get_linuxinfo_str(){
local tv1 tv2 tv3 EOF uri result IFS dontcare
record=""
result=""
EOF=$FALSE
uri=https://www.kernel.org/feeds/kdist.xml
while IFS='>' read -d '<' TAG VALUE ; do
case "${TAG}" in
'item') #echo "${result}"
#clear all the variables
#title=''
released=''
description=''
endoflife="No"
version=''
branch=''
source=''
released=''
url=''
link=''
;;
'title')
OIFS=$IFS
IFS=":"
#echo "title =${VALUE}"
read -r tv1 tv2 <<< "${VALUE}"
IFS=$OIFS
version=${tv1//[[:space:]]}
branch=${tv2//[[:space:]]}
[ "${title:0:4}" == "next" ] && break
#echo "title=$title"
;; #echo "${result}"
'description')
url=$( echo "${VALUE}" | grep -E -o 'https.*linux-([0-9]{1,}\.)+[0-9]{1,}' | head -n 1 |cut -d\" -f 1)
# Seems bogus to turn < to < and then delete all tags but (I was rally tired atdontcare the time)
# I couldnt get the >/%lts out - Hmmm
description=$( echo "${VALUE}" | sed -e 's/</</g' -e 's/>/>/g' -e 's/<[^>]*>//g' -e 's/:/=/g' )
OIFS=$IFS${EOF}
IFS=$'\n'
for tv3 in $description ; do
tv3="${tv3//[[:space:]]}"
[ "${tv3}" == "" ] && continue
#echo " line in desc=${tv3}"
IFS='='
read -r tv1 tv2 <<< "${tv3}"
#get rid of any brackets - left one gets an equals = right one gets stripped
tv2=$( echo "${tv2//[[:space:]]}" | sed -re 's/[(]/=/g' -re 's/[)]//g' )
if [ -n "${tv1}" ] && [ -n "${tv2}" ] ; then #if we have an attribute->value pair
[ "${tv2:0:4}" == "next" ] && break #and its not NEXT-blah
case "${tv1,,}" in #check the lowercase version of it
'version')
#we actually already have version -
# version can occasionally have an extra equals - this will be an eol indicator
# the thing before the first equals will be version
read -r dontcare eolinfo <<< "${tv2}"
if [[ "${eolinfo}" == *"="* ]] ; then #if the thing after the equals has another equals in it - look for eol
read -r endoflife dontcare <<< "${eolinfo}" # the thing after that will be the branch again - we can ignore it
[ "${endoflife,,}" == "eol" ] && endoflife="Yes"
fi
;;
'source')
source="${tv2//[[:space:]]}"
;;
'released' )
released="${tv2//[[:space:]]}"
;;
esac
fi
IFS=$'\n'
done
IFS=$OIFS
;;
'/item')
#echo "$title released: ${released}"
#record="<title>${title}</title>"
record="<version>${version}</version>"
record+="<branch>${branch}</branch>"
record+="<endoflife>${endoflife}</endoflife>"
record+="<source>${source}</source>"
record+="<released>${released}</released>"
record+="<url>${url}</url>"
result+="<item>${record}</item>"
ACSO_KERNEL_INFO_ARRAY_STR="${ACSO_KERNEL_INFO_ARRAY_STR}<item>${record}</item>"
;;
esac
done < <(wget -qO - $uri )
}
#
# function self_check(){
# include_file=${lib_dir}/${___ME___}
# shafile=${include_file}.sha
# #echo $shafile
#
# while IFS= read -r line || [ -n "$line" ]; do
# OIFS=$IFS
# IFS=" "
# read -r hash func <<< "${line}"
# IFS=$OIFS
# [ "${func}" == ${___ME___} ] && break
# done < $shafile
#
# if [ ! -z "${hash}" ] ; then
# if [[ "$(echo "${hash} ${include_file}"| sha1sum -c - )" != *"OK"* ]] ; then
# die "${___ME___} is corrupt or has been modified - suggest you re-download"
# fi
# else
# die "No hash to check file : ${include_file}"
# fi
# }
#
# self_check
#
# I've given up on this as a PITA
# keeping the code here to remember how I did it
#
# function libinclude(){
# #for now I'll read the hash from a file -
# #later change that to retrieve said file from the repo
# # its really kinda overkill -
# # I have code in the include file to check this file against a hash as well
# if [ $# -lt 1 ]; then
# errmessage=" > This function accepts one mandtory argument.
# > Being the file to be included"
# exception "${errmessage}"
# fi
#
# include_file=${lib_dir}/${1}
# shafile=${include_file}.sha
#
# while IFS= read -r line || [ -n "$line" ]; do
# OIFS=$IFS
# IFS=" "
# read -r hash func <<< "${line}"
# IFS=$OIFS
# [ "${func}" == ${1} ] && break
# done < $shafile
# # echo "hash=${hash} include=${include_file}"
# if [ ! -z "${hash}" ] ; then
# if [[ "$(echo "${hash} ${include_file}"| sha1sum -c - )" == *"OK"* ]] ; then
# source "${include_file}"
# else"title"
# echo "Error - include file : ${include_file} ... missing or corrupt"
# echo "${hash} ${include_file}"
# exit
# fi
# else
# echo "No hash to check file : ${include_file}"
# exit
# fi
# }