106106BASE_PATH=" $( cd " $BASE_PATH " && pwd) "
107107WORK_DIR=" $( mktemp -d) "
108108OBJECT_LIST=" $WORK_DIR /objects.txt"
109- TREE_LIST =" $WORK_DIR /tree .txt"
109+ TREE_PATHS =" $WORK_DIR /catalog-paths .txt"
110110VERSION_ROWS=" $WORK_DIR /version-rows.tsv"
111111trap cleanup EXIT
112112
@@ -190,6 +190,101 @@ build_object_list()
190190 sort -u -o " $OBJECT_LIST " " $OBJECT_LIST "
191191}
192192
193+ filter_package_paths ()
194+ {
195+ local candidates=" $WORK_DIR /package-candidates.txt"
196+ local rc=0
197+
198+ grep -Ev ' source-|pool|dists' " $OBJECT_LIST " > " $candidates "
199+ rc=$?
200+ if [[ " $rc " -ne 0 && " $rc " -ne 1 ]]; then
201+ echo " ERROR: failed filtering package paths from object list" >&2
202+ exit 1
203+ fi
204+ if [[ " $rc " -eq 1 ]]; then
205+ : > " $candidates "
206+ fi
207+
208+ grep -E ' \.(rpm|deb|key|repo|exe|msi|zip|pkg)$' " $candidates " > " $TREE_PATHS "
209+ rc=$?
210+ if [[ " $rc " -ne 0 && " $rc " -ne 1 ]]; then
211+ echo " ERROR: failed selecting package file paths" >&2
212+ exit 1
213+ fi
214+ if [[ " $rc " -eq 1 ]]; then
215+ : > " $TREE_PATHS "
216+ fi
217+ }
218+
219+ absolutize_tree_hrefs ()
220+ {
221+ awk -v base=" $BASE_URL " '
222+ function absolutize(url) {
223+ if (url ~ /^https?:\/\//) {
224+ return url
225+ }
226+ if (url == "/") {
227+ return base "/"
228+ }
229+ if (substr(url, 1, 1) == "/") {
230+ return base url
231+ }
232+ return base "/" url
233+ }
234+ {
235+ line = $0
236+ out = ""
237+ while (match(line, /href="[^"]+"/)) {
238+ out = out substr(line, 1, RSTART - 1)
239+ href = substr(line, RSTART, RLENGTH)
240+ url = substr(href, 7, length(href) - 7)
241+ out = out "href=\"" absolutize(url) "\""
242+ line = substr(line, RSTART + RLENGTH)
243+ }
244+ print out line
245+ }'
246+ }
247+
248+ build_tree_html ()
249+ {
250+ local -a tree_pipe_status=()
251+
252+ BASE_URL=" ${BASE_URL%/ } "
253+ (
254+ cd " $WORK_DIR "
255+ tree --noreport --charset utf-8 --fromfile catalog-paths.txt -H " ${BASE_URL} /"
256+ ) | sed -e " s|${BASE_URL} /catalog-paths.txt/|${BASE_URL} /|g" \
257+ -e " s|${BASE_URL} /catalog-paths.txt|${BASE_URL} /|g" \
258+ -e " s|${BASE_URL} catalog-paths.txt/|${BASE_URL} /|g" \
259+ -e " s|${BASE_URL} catalog-paths.txt|${BASE_URL} /|g" \
260+ -e ' s|>catalog-paths.txt</a>|>/</a>|g' \
261+ -e ' s|\(https://[^/]*\)//|\1/|g' \
262+ | absolutize_tree_hrefs \
263+ | awk ' /<hr>/ { exit } { print } END { print "</body></html>" }' > " $WORK_DIR /tree.html"
264+ tree_pipe_status=(" ${PIPESTATUS[@]} " )
265+
266+ if [[ " ${tree_pipe_status[0]} " -ne 0 ]]; then
267+ echo " ERROR: tree failed to generate package index HTML" >&2
268+ exit 1
269+ fi
270+ if [[ " ${tree_pipe_status[1]} " -ne 0 ]]; then
271+ echo " ERROR: failed to normalize package index tree links" >&2
272+ exit 1
273+ fi
274+ if [[ " ${tree_pipe_status[2]} " -ne 0 ]]; then
275+ echo " ERROR: failed to absolutize package index tree links" >&2
276+ exit 1
277+ fi
278+ if [[ " ${tree_pipe_status[3]} " -ne 0 ]]; then
279+ echo " ERROR: failed to finalize package index tree HTML" >&2
280+ exit 1
281+ fi
282+ if [[ ! -s " $WORK_DIR /tree.html" ]]; then
283+ echo " ERROR: package index tree HTML is empty" >&2
284+ exit 1
285+ fi
286+ }
287+
193288render_index_html ()
194289{
195290 local latest=" $1 "
@@ -207,27 +302,25 @@ if [[ ! -s "$OBJECT_LIST" ]]; then
207302 exit 1
208303fi
209304
210- grep -Ev ' source-|pool|dists' " $OBJECT_LIST " | \
211- grep -E ' \.(rpm|deb|key|repo|exe|msi|zip|pkg)$' > " $TREE_LIST " || true
305+ filter_package_paths
212306
213307awk -v emit_mode=filter \
214308 -v min_catalog_major=" $MIN_CATALOG_MAJOR " \
215309 -f " $SCRIPT_DIR /build-catalog.awk" \
216- " $TREE_LIST " > " $WORK_DIR /tree-filtered.txt"
310+ " $TREE_PATHS " > " $WORK_DIR /tree-filtered.txt"
217311
218312if [[ -s " $WORK_DIR /tree-filtered.txt" ]]; then
219- mv " $WORK_DIR /tree-filtered.txt" " $TREE_LIST "
313+ mv " $WORK_DIR /tree-filtered.txt" " $TREE_PATHS "
220314else
221- : > " $TREE_LIST "
315+ : > " $TREE_PATHS "
222316fi
223317
224- if [[ ! -s " $TREE_LIST " ]]; then
318+ if [[ ! -s " $TREE_PATHS " ]]; then
225319 echo " ERROR: no package files found for index.html" >&2
226320 exit 1
227321fi
228322
229- tree --noreport --charset utf-8 --fromfile " $TREE_LIST " -H " $BASE_URL " | \
230- awk ' /<hr>/ { exit } { print } END { print "</body></html>" }' > " $WORK_DIR /tree.html"
323+ build_tree_html
231324
232325REPO_PATHS=" $( printf ' %s ' " ${LINUX_REPO_PATHS[@]} " ) "
233326awk -v emit_mode=versions \
0 commit comments