-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcheck-ebuild-update
executable file
·443 lines (403 loc) · 11.6 KB
/
check-ebuild-update
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#!/bin/bash
# License: MIT or GPL2+
# Checks if a newer vanilla ebuild from various sources so this overlay can
# apply modifications to them. For example we check the Gentoo overlay
# to see if there is a latest stable and apply multilib modifications to
# them.
# This script was created to eliminate some human error and bias.
# More recent package versions will have up to date security fixes if any.
# The results will clearly print which packages are outdated. This
# can be used to compare the version differential. Large differences
# may indicate the package may need to be pruned or it requires special
# attention for vulnerability checks, or it may indicate that the
# project has transfered ownership or to a new place.
# The pattern is that the longer the package has not updated, the more
# critical or high vulnerabilities it may accumulate over time. This
# script will help catch these packages.
# Still work in progress
# _pYYYMMDD is broken if using timestamp because there is no standard timezone
# for YYMMDD in the gentoo spec, so there could be off by one errors.
# The overlay assumes local time PDT/PST for _YYMMDD.
# The technical spec: https://wiki.gentoo.org/wiki/Package_Manager_Specification
if [[ -f .check-ebuild-update.config ]] ; then
source .check-ebuild-update.config
fi
PORTAGE_DIR=${PORTAGE_DIR:-"/usr/portage"}
STABLE_ARCH=${STABLE_ARCH:-"amd64"}
SCRAPERS_FILE=${SCRAPERS_FILE:-"check-ebuild-update-scrapers"}
DEBUG=${DEBUG:-"0"}
REPO_TZ=${REPO_TZ:-"America/Los_Angeles"}
CACHE_EXPIRE=${CACHE_EXPIRE:-86400} # 1 day
CACHE_DIR=${CACHE_DIR:-"/tmp/check-ebuild-update"}
setup_cache() {
mkdir -p "${CACHE_DIR}"
}
check_prereqs() {
if [[ ! -d "${PORTAGE_DIR}" ]] ; then
echo "Your PORTAGE_DIR cannot be found"
exit 1
fi
if [[ "${PORTAGE_DIR}" != "/usr/portage" ]] ; then
echo \
"Your PORTAGE_DIR is not /usr/portage. You must check the cut commands are\n\
working properly."
exit 1
fi
if grep --help | grep -q -P -e "--perl-regexp" ; then
:;
else
echo "You need grep compiled with Perl regular expressions."
exit 1
fi
if ! which git 2>/dev/null 1>/dev/null ; then
echo "You need git"
exit 1
fi
if ! which html2text 2>/dev/null 1>/dev/null ; then
echo "You need html2text"
exit 1
fi
if ! which wget 2>/dev/null 1>/dev/null ; then
echo "You need wget"
exit 1
fi
if ! which xmlstarlet 2>/dev/null 1>/dev/null ; then
echo "You need xmlstarlet"
exit 1
fi
}
# version tests
# x < y
is_x_lt_y() {
local x="${1}"
local y="${2}"
local result=$(echo -e "${x}\n${y}" | sort -V | tr "\n" " " \
| cut -f 1 -d $' ')
if [[ "${result}" == "${x}" ]] ; then
return 0
else
return 1
fi
}
is_x_le_y() {
local x="${1}"
local y="${2}"
local result=$(echo -e "${x}\n${y}" | sort -V | tr "\n" " " \
| cut -f 1 -d $' ')
if [[ "${result}" == "${x}" || "${x}" == "${y}" ]] ; then
return 0
else
return 1
fi
}
is_x_gt_y() {
local x="${1}"
local y="${2}"
local result=$(echo -e "${x}\n${y}" | sort -V | tr "\n" " " \
| cut -f 1 -d $' ')
if [[ "${result}" != "${x}" ]] ; then
return 0
else
return 1
fi
}
is_x_ge_y() {
local x="${1}"
local y="${2}"
local result=$(echo -e "${x}\n${y}" | sort -V | tr "\n" " " \
| cut -f 1 -d $' ')
if [[ "${result}" != "${x}" || "${x}" == "${y}" ]] ; then
return 0
else
return 1
fi
}
is_x_eq_y() {
local x="${1}"
local y="${2}"
if [[ "${x}" == "${y}" ]] ; then
return 0
else
return 1
fi
}
is_x_ne_y() {
local x="${1}"
local y="${2}"
if [[ "${x}" != "${y}" ]] ; then
return 0
else
return 1
fi
}
is_x_op_y() {
local x="${1}"
local op="${2}"
local y="${3}"
if [[ "${op}" == "-lt" ]] ; then
is_x_lt_y "${x}" "${y}"
elif [[ "${op}" == "-le" ]] ; then
is_x_le_y "${x}" "${y}"
elif [[ "${op}" == "-gt" ]] ; then
is_x_gt_y "${x}" "${y}"
elif [[ "${op}" == "-ge" ]] ; then
is_x_ge_y "${x}" "${y}"
elif [[ "${op}" == "-eq" ]] ; then
is_x_eq_y "${x}" "${y}"
elif [[ "${op}" == "-ne" ]] ; then
is_x_ne_y "${x}" "${y}"
fi
}
get_stable_versions() {
arch="${1}"
for ebuild in $(find "${PORTAGE_DIR}/${category}/${pn}" \
-name "*.ebuild" 2>/dev/null \
| tr " " "\n" ) ; do
if grep -q -P -e "KEYWORDS=\".*(?<!\~)${arch}" "${ebuild}"
then
echo "${ebuild}"
fi
done
}
get_newest_pv() {
local uri="${1}"
local r=$(git ls-remote --tags "${uri}" \
| sed -e "s|refs/tags/|;|g" \
| cut -f 2 -d ";" \
| sed -e "s|^v||g" -e "s|[\^\{\}]+||g" \
| grep -v -G -e "[\^]" \
| sed -r -e "s#-(alpha|beta|rc|pre)\.?#_\1#g" \
| sed -e "s|_preview|_pre|" \
| esort \
| tr " " "\n" \
| tail -n 1)
if echo "${r}" | grep -G -e "^[^0-9]" ; then
echo "${category}/${pn} has tag that is not a version r=${r}"
exit 1
fi
if [[ -z "${r}" ]] ; then
echo "${category}/${pn} has an empty pv"
exit 1
fi
echo "${r}"
}
# gets all tags without prefixed v
# used when more variations of alpha/beta/pre or non standard versioning encountered
get_tags() {
local uri="${1}"
local r=$(git ls-remote --tags "${uri}" \
| sed -e "s|refs/tags/|;|g" \
| cut -f 2 -d ";" \
| grep -v -G -e "[\^]" \
| sed -r -e "s|^v||g" -e "s|[\^\{\}]+||g" \
| sed -r -e "s#-(alpha|beta|rc|pre)\.?#_\1#g" \
| sed -e "s|_preview|_pre|")
if [[ -z "${r}" ]] ; then
echo "${category}/${pn} has no tags"
exit 1
fi
echo "${r}"
}
# Demote _beta, _alpha, _rc, _pre, etc for sort -V
# You need to call `| tr " " "\n"` immediately afterwards.
demote_prereleases() {
ARG=$(</dev/stdin)
echo -e $(echo -e "${ARG}" \
| sed -r -e 's#([0-9]+)$#\1___#g' \
| sed -r -e "s#_(rc|beta|alpha|pre|p)#z\1#")
}
# strip hinter
strip_hinter() {
ARG=$(</dev/stdin)
echo -e $(echo -e "${ARG}" \
| sed -r -e 's#([0-9]+)___$#\1#g' \
| sed -r -e "s#z(rc|beta|alpha|pre|p)#_\1#")
}
# You need to call `| tr " " "\n"` immediately afterwards.
esort() {
ARG=$(</dev/stdin)
echo -e $(echo -e "${ARG}" \
| demote_prereleases \
| tr " " "\n" \
| sort -V \
| strip_hinter)
}
get_head_suffix() {
local domain="${1}"
local org_project="${2}"
local branch="${3}"
# github reports local timestamp on www (Firefox) but on wget it is UTC/zulu
echo $(TZ="America/Los_Angeles" date -d "$(wget -q -O - \
https://${domain}/${org_project}/commit/$(git ls-remote --heads \
https://${domain}/${org_project}.git \
| grep -F -e "${branch}" \
| cut -f 1 -d $'\t') \
| grep -F -e "relative-time" \
| grep -G -o -e "datetime=\".*\" " \
| sed -e "s|datetime=\"||g" -e "s|\" ||g")" +"%Y%m%d")
}
get_head_suffix_rss() {
local url="${1}"
wget -q -O - "${1}" \
| grep -F -e "pubDate" \
| sed -r -e "s|[</]+pubDate[>]||g" \
| head -n 1 \
| sed -r -e "s|^[ ]+||g"
}
source "${SCRAPERS_FILE}"
edebug() {
local message="${1}"
if [[ -n "${DEBUG}" && "${DEBUG}" == "1" ]] ; then
echo "${message}"
fi
}
gen_save_pv() {
mkdir -p "${CACHE_DIR}/${type}/${category}/${pn}"
rm -rf "${CACHE_DIR}/${type}/${category}/${pn}/${oiledmachine_pv}"
"${fn}" \
> "${CACHE_DIR}/${type}/${category}/${pn}/${oiledmachine_pv}"
cat "${CACHE_DIR}/${type}/${category}/${pn}/${oiledmachine_pv}"
}
get_pv() {
local fn="${1}"
local type="${2}" # can be gentoo or repos
# can't use SLOT because it uses ver_cut and variables
if [[ -f "${CACHE_DIR}/${type}/${category}/${pn}/${oiledmachine_pv}" ]] ; then
local datec=$(stat -c "%W" \
"${CACHE_DIR}/${type}/${category}/${pn}/${oiledmachine_pv}")
local now=$(date +"%s")
if (( ${now} < ${datec} + ${CACHE_EXPIRE} )) ; then
cat "${CACHE_DIR}/${type}/${category}/${pn}/${oiledmachine_pv}"
else
gen_save_pv
fi
else
gen_save_pv
fi
}
scan_repos() {
echo "Checking projects"
for ebuild in $(find . -name "*.ebuild") ; do
local category=$(echo "${ebuild}" | cut -f 2 -d "/")
local ebuild_filename=$(basename "${ebuild}")
local pn=$(echo "${ebuild}" | cut -f 3 -d "/")
local oiledmachine_pv=$(echo "${ebuild_filename}" \
| sed -r -e "s|${pn}-||g" -e "s|\.ebuild$||")
local repo_pv
edebug "Inspecting ${category}/${pn}"
for p in $(grep -E -e "^repo_latest_version_get_(${category}-)?" \
"${SCRAPERS_FILE}" \
| sed -r -e "s|\(\) \{||g" \
-e "s|repo_latest_version_get_(${category}-)?||" \
-e "s|_pv||g") ; do
[[ "${p}" != "${pn}" ]] && continue
if grep -q -F -e \
"repo_latest_version_get_${category}-${pn}_pv" \
"${SCRAPERS_FILE}" ; then
repo_pv=$(get_pv repo_latest_version_get_${category}-${pn}_pv "repos")
edebug "${repo_pv} > ${oiledmachine_pv}"
if is_x_op_y ${repo_pv} "-gt" \
"${oiledmachine_pv}"
then
echo \
"Found newer ${pn} repo_pv=${repo_pv} oiledmachine_pv=${oiledmachine_pv}"
fi
elif [[ "${pn}" == "tulua++" ]] ; then
repo_pv=$(get_pv repo_latest_version_get_tuluaxx_pv)
edebug "${repo_pv} > ${oiledmachine_pv}"
if is_x_op_y ${repo_pv} "-gt" \
"${oiledmachine_pv}"
then
echo \
"Found newer ${pn} repo_pv=${repo_pv} oiledmachine_pv=${oiledmachine_pv}"
fi
elif [[ "${pn}" == "noto-color-emoji" \
|| "${pn}" == "noto-color-emoji-bin" ]] ; then
repo_pv=$(get_pv repo_latest_version_get_${pn}_pv "repos")
edebug "${repo_pv} > ${oiledmachine_pv}"
oiledmachine_pv_date=$(echo "${oiledmachine_pv}" \
| sed -r -e "s#_beta[0-9]+##g" \
| sed -r -e "s#(_|-)#-#g" \
| cut -f 2 -d "-" \
| sed -r -e "s|[^0-9]||g")
if is_x_op_y ${repo_pv} "-gt" \
"${oiledmachine_pv_date}"
then
echo \
"Found newer ${pn} repo_pv=${repo_pv} oiledmachine_pv_date=${oiledmachine_pv_date}"
fi
elif [[ "${pn}" == "${p}" ]] ; then
repo_pv=$(get_pv repo_latest_version_get_${pn}_pv "repos")
edebug "${repo_pv} > ${oiledmachine_pv}"
if is_x_op_y ${repo_pv} "-gt" "${oiledmachine_pv}"
then
echo \
"Found newer ${pn} repo_pv=${repo_pv} oiledmachine_pv=${oiledmachine_pv}"
fi
else
edebug "Skipped ${category}/${pn}"
fi
done
done
}
filter_by_slot() {
local stable_versions=$(get_stable_versions "${STABLE_ARCH}")
if [[ "${category}/${pn}" == "dev-lang/lua" ]] ; then
echo "${stable_versions}" \
| grep -F -e "^"$(echo "${oiledmachine_pv}" \
| cut -f 1-2 -d ".")
elif [[ "${category}/${pn}" == "dev-util/premake" ]] ; then
echo "${stable_versions}" \
| grep -F -e "^"$(echo "${oiledmachine_pv}" \
| cut -f 1 -d ".")
elif [[ "${category}/${pn}" == "media-gfx/blender" ]] ; then
echo "${stable_versions}" \
| grep -F -e "^"$(echo "${oiledmachine_pv}" \
| cut -f 1-2 -d ".")
elif [[ "${category}/${pn}" == "net-libs/nodejs" ]] ; then
echo "${stable_versions}" \
| grep -F -e "^"$(echo "${oiledmachine_pv}" \
| cut -f 1 -d ".")
else
echo -e "${stable_versions}"
fi
}
gen_gentoo_ver() {
echo "${bn_newest}" | sed -r -e "s|${pn}-||g" -e "s|\.ebuild$||"
}
scan_gentoo_overlay() {
echo "Checking the Gentoo overlay"
for ebuild in $(find . -name "*.ebuild") ; do
local category=$(echo "${ebuild}" | cut -f 2 -d "/")
local ebuild_filename=$(basename "${ebuild}")
local pn=$(echo "${ebuild}" | cut -f 3 -d "/")
local oiledmachine_pv=$(echo "${ebuild_filename}" \
| sed -r -e "s|${pn}-||g" -e "s|\.ebuild$||")
local versions=$(filter_by_slot $(get_stable_versions \
"${STABLE_ARCH}"))
local newest=$(echo -e "${versions}" | tail -n 1)
if (( ${#newest} > 0 )) ; then
edebug "Inspecting ${category}/${pn}"
local bn_newest=$(basename "${newest}")
local gentoo_pv=$(get_pv gen_gentoo_ver "gentoo")
edebug "${gentoo_pv} > ${oiledmachine_pv}"
if is_x_op_y $(echo "${gentoo_pv}" | cut -f 1 -d "-") \
"-gt" \
$(echo "${oiledmachine_pv}" | cut -f 1 -d "-")
then
echo -e \
"Found ${pn} is newer on the Gentoo overlay oiledmachine_pv=${oiledmachine_pv} \
gentoo_pv=${gentoo_pv}"
fi
else
edebug "Skipped ${category}/${pn}"
fi
done
}
main() {
check_prereqs
setup_cache
scan_gentoo_overlay
scan_repos
}
main