cookutils view lighttpd/index.cgi @ rev 1112

lighttpd/index.cgi: ask real file size
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Dec 03 13:15:17 2018 +0200 (2018-12-03)
parents 4c3c5f4f177d
children 41c25139be4d
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker CGI + Lighttpd web interface.
4 #
6 # Make request URI relative to the script name
7 base="$(dirname "$SCRIPT_NAME")"; [ "$base" == '/' ] && base=''
8 REQUEST_URI=$(echo "$REQUEST_URI" | sed "s|^$base/*|/|; s|\?.*||")
10 # Split the URI request to /pkg/cmd/arg
11 export pkg=$(echo "$REQUEST_URI" | cut -d/ -f2)
12 export cmd=$(echo "$REQUEST_URI" | cut -d/ -f3)
13 export arg=$(echo "$REQUEST_URI" | sed 's|^/[^/]*/[^/]*/||')
16 . /usr/lib/slitaz/httphelper.sh
18 case $QUERY_STRING in
19 *debug*)
20 debug='yes'
21 QUERY_STRING="$(echo "$QUERY_STRING" | sed 's|debug||; s|^&||; s|&&|\&|; s|&$||')"
22 ;;
23 esac
25 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
26 [ -f "./cook.conf" ] && . ./cook.conf
27 wok="$WOK"
28 title=${title:-SliTaz Cooker}
29 # Cooker DB files.
30 activity="$CACHE/activity"
31 commits="$CACHE/commits"
32 cooklist="$CACHE/cooklist"
33 cookorder="$CACHE/cookorder"
34 command="$CACHE/command"; touch $command
35 blocked="$CACHE/blocked"
36 broken="$CACHE/broken"
37 cooknotes="$CACHE/cooknotes"
38 cooktime="$CACHE/cooktime"
39 wokrev="$CACHE/wokrev"
40 webstat="$CACHE/webstat" # note, file should be previously created with write permissions for www
41 splitdb="$CACHE/split.db"
42 maintdb="$CACHE/maint.db"
43 repologydb="$CACHE/repology.db" # note, file should be previously created with write permissions for www
45 # Path to markdown to html convertor
46 cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
47 if [ -n "$(which cmark 2>/dev/null)" ]; then
48 md2html="$(which cmark) $cmark_opts"
49 elif [ -x "./cmark" ]; then
50 md2html="./cmark $cmark_opts"
51 elif [ -n "$(which sundown 2>/dev/null)" ]; then
52 md2html=$(which sundown)
53 elif [ -x "./sundown" ]; then
54 md2html="./sundown"
55 fi
60 # Search form redirection
61 if [ -n "$(GET search)" ]; then
62 echo -e "HTTP/1.1 301 Moved Permanently\nLocation: $base/$(GET q)\n\n"
63 exit 0
64 fi
67 # Show the running command and its progression
69 running_command() {
70 state="$(cat $command)"
71 local pct=''
72 if [ -n "$state" ];then
73 echo -n "$state</td></tr><tr><td>Completion</td>"
74 set -- $(grep "^$state" $cooktime)
75 [ -n "$1" -a $2 -ne 0 ] && pct=$((($(date +%s)-$3)*100/$2))
76 [ -n "$pct" ] && max="max='100'"
77 echo -n "<td><progress id='gauge' $max value='$pct' title='Click to stop updating' onclick='stopUpdating()'>"
78 echo -n "</progress> <span id='pct'>${pct:-?}%</span>"
79 [ "$2" -gt 60 ] &&
80 echo -n "</td></tr><tr><td>Estimated end time</td><td>$(date +%H:%M -ud @$(($2+$3)))"
81 else
82 echo 'not running'
83 fi
84 }
87 # HTML page header
89 page_header() {
90 local theme t='' css pretitle='' command
91 theme=$(COOKIE theme)
92 [ "$theme" == 'default' ] && theme=''
93 [ -n "$theme" ] && theme="-$theme"
94 css="cooker$theme.css"
96 if [ -n "$pkg" ]; then
97 case "$pkg" in
98 ~) if [ -z "$cmd" ]; then pretitle="Tag cloud - "; else pretitle="Tag \"$cmd\" - "; fi;;
99 =) if [ -z "$cmd" ]; then pretitle="Badges - "; else pretitle="Badge \"$cmd\" - "; fi;;
100 *) pretitle="$pkg - ";;
101 esac
102 else
103 command="$(cat $command)"
104 [ -n "$command" ] && pretitle="$command - "
105 fi
106 [ -z "$favicon" ] && favicon='/slitaz-cooker.png'
108 echo -e 'Content-Type: text/html; charset=UTF-8\n'
110 cat <<EOT
111 <!DOCTYPE html>
112 <html lang="en">
113 <head>
114 <title>$pretitle$title</title>
115 <link rel="stylesheet" href="/$css">
116 <link rel="icon" type="image/png" href="$favicon">
117 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
118 <!-- mobile -->
119 <meta name="viewport" content="width=device-width, initial-scale=1.0">
120 <meta name="theme-color" content="#222">
121 <!-- rss -->
122 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
123 <script>
124 // Get part of the main page
125 function getPart(part) {
126 var partRequest = new XMLHttpRequest();
127 partRequest.onreadystatechange = function() {
128 if (this.readyState == 4 && this.status == 200) {
129 response = this.responseText;
130 var partElement = document.getElementById(part);
131 if (response !== null) partElement.innerHTML = response;
132 }
133 };
134 partRequest.open('GET', '?part=' + part, true);
135 partRequest.responseType = '';
136 partRequest.send();
137 }
138 </script>
139 </head>
140 <body>
141 <div id="container">
142 <header>
143 <h1><a href="$base/">$title</a></h1>
144 <div class="network">
145 <a href="http://www.slitaz.org/">Home</a>
146 <a href="http://bugs.slitaz.org/">Bugs</a>
147 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
148 <a href="http://roadmap.slitaz.org/">Roadmap</a>
149 <a href="http://pizza.slitaz.me/">Pizza</a>
150 <a href="http://tank.slitaz.org/">Tank</a>
151 |
152 <a href="/cross/">Cross</a>
153 <a href="/i486.cgi">i486</a>
154 <a href="$base/cookiso.cgi">ISO</a>
155 <select onChange="window.location.href=this.value" style="display: none">
156 <option value=".">Go to…</option>
157 <option value="http://www.slitaz.org/">Home</option>
158 <option value="http://bugs.slitaz.org/">Bug tracker</option>
159 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
160 <option value="http://roadmap.slitaz.org/">Roadmap</option>
161 <option value="http://pizza.slitaz.me/">Pizza</option>
162 <option value="http://tank.slitaz.org/">Tank</option>
163 <option disabled>---------</option>
164 <option value="cross/">Cross</option>
165 <option value="i486.cgi">i486</option>
166 <option value="cookiso.cgi">ISO</option>
167 </select>
168 </div>
169 </header>
171 <main>
172 EOT
174 [ -n "$debug" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
175 }
178 # HTML page footer
180 page_footer() {
181 date_now=$(date +%s)
182 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
183 wait_sec=$(( 60 - $sec_now ))
184 cat <<-EOT
185 </main>
187 <footer>
188 <a href="http://www.slitaz.org/">SliTaz Website</a>
189 <a href="http://tank.slitaz.org/graphs.php">Server status</a>
190 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
191 <a href="$base/?theme">Theme</a>
192 </footer>
193 </div>
194 <script src="/cooker.js"></script>
195 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
196 </body>
197 </html>
198 EOT
199 }
202 show_note() {
203 echo "<div class='bigicon-$1'>$2</div>"
204 }
207 not_found() {
208 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
209 echo "HTTP/1.1 404 Not Found"
210 page_header
211 echo "<h2>Not Found</h2>"
212 case $2 in
213 pkg)
214 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
215 *)
216 show_note e "The requested file “$file” was not found." ;;
217 esac
218 page_footer
219 }
222 manage_modified() {
223 local file="$1" option="$2" nul day mon year time hh mm ss date_s
224 if [ ! -f "$file" ]; then
225 if [ "$option" == 'silently-absent' ]; then
226 echo "HTTP/1.1 404 Not Found"
227 return
228 else
229 not_found "$file" "$2"
230 exit
231 fi
232 fi
233 [ "$option" == 'no-last-modified' ] && return
234 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
235 echo "$HTTP_IF_MODIFIED_SINCE" | \
236 while read nul day mon year time nul; do
237 case $mon in
238 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
239 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
240 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
241 esac
242 hh=$(echo $time | cut -d: -f1)
243 mm=$(echo $time | cut -d: -f2)
244 ss=$(echo $time | cut -d: -f3)
245 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
246 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
247 # echo -e 'HTTP/1.1 304 Not Modified\n'
248 # exit
249 # fi
250 # TODO: improve caching control
251 done
252 fi
253 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
254 echo "Cache-Control: public, max-age=3600"
255 }
258 # Proxy to the Repology
259 # Problems:
260 # 1. Function "latest packaged version" widely used here and it has no JSON API, but only SVG badge.
261 # 2. So, all version comparisons can be only visual and not automated.
262 # 3. When the thousands of badges present on the web page, many of them are broken (maybe server
263 # drops requests), while our server displays status icons well.
264 # 4. Default badges are wide and not customizable.
265 # Solution:
266 # 1. Make local cache. Update it on demand, but no more than once a day (Repology caches info
267 # on a hourly basis). Use cached values when they are not expired.
268 # 2. Extract and save version(s) from the SVG badges. Values can be compared in the scripts as well
269 # as custom badges that may also be provided.
271 repology_get() {
272 local found versions day=$(date +%j) # %j is the number of the day in the year
273 found=$(awk -F$'\t' -vpkg="$1" -vday="$day" '{
274 if ($1 == pkg && $2 == day) { print $3; exit; }
275 }' $repologydb)
276 if [ -n "$found" ]; then
277 echo "$found"
278 else
279 # set HOST_WGET in cook.conf
280 versions=$($HOST_WGET -q -T 20 -O- https://repology.org/badge/latest-versions/$1.svg \
281 | sed '/<text /!d; /fill/d; /latest/d; s|.*>\(.*\)<.*|\1|; s|, | |g') # space separated list
282 if [ -n "$versions" ]; then
283 sed -i "/^$1 /d" $repologydb
284 echo -e "$1\t$day\t$versions" >> $repologydb
285 echo $versions
286 fi
287 fi
288 }
291 # Query '?pct=<package>': update percentage
293 if [ -n "$(GET pct)" ]; then
294 pkg="$(GET pct)"
295 state="$(cat $command)"
296 if [ "$state" == "cook:$pkg" ]; then
297 set -- $(grep "^$state" $cooktime)
298 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
299 echo "${pct:-?}"
300 else
301 echo 'reload'
302 fi
303 exit 0
304 fi
307 # Query '?poke': poke cooker
309 if [ -n "$(GET poke)" ]; then
310 touch $CACHE/cooker-request
311 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
312 exit
313 fi
316 # Query '?recook=<package>': query to recook package
318 if [ -n "$(GET recook)" ]; then
319 pkg="$(GET recook)"
320 case "$HTTP_USER_AGENT" in
321 *SliTaz*)
322 grep -qs "^$pkg$" $CACHE/recook-packages ||
323 echo "$pkg" >> $CACHE/recook-packages
324 esac
325 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
326 exit
327 fi
330 # Query '/i/<log>/<pkg>': show indicator icon
331 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
333 if [ "$pkg" == 'i' ]; then
334 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
335 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
336 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
337 else
338 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
339 fi
340 exit
341 fi
344 # Query '/s/<pkg>': show status indicator icon
345 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
347 if [ "$pkg" == 's' ]; then
348 # argument <pkg> is in $cmd variable
349 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
350 # packages.info updates with each new package, so we'll find actual info here
351 if grep -q "^$cmd"$'\t' $PKGS/packages-$ARCH.info; then
352 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
353 else
354 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
355 fi
356 exit
357 fi
360 # Query '?theme[=<theme>]': change UI theme
362 if [ -n "$(GET theme)" ]; then
363 theme="$(GET theme)"
364 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
365 case $theme in
366 theme)
367 current=$(COOKIE theme)
368 page_header
369 cat <<-EOT
370 <section>
371 <h2>Change theme</h2>
372 <p>Current theme: “${current:-default}”. Select other:</p>
373 <ul>$(
374 for i in default emerald sky goldenrod midnight like2016 terminal; do
375 [ "$i" == "${current:-default}" ] || echo "<li><a href=\"$base/?theme=$i&amp;ref=$ref\">$i</a></li>"
376 done
377 )</ul>
378 </section>
379 EOT
380 page_footer
381 exit 0
382 ;;
383 default|emerald|sky|goldenrod|midnight|like2016|terminal)
384 ref="$(GET ref)"
385 [ -n "$ref" ] || ref="$base/"
386 # Expires in a year
387 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
388 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
389 exit 0
390 ;;
391 esac
392 fi
395 #case "$QUERY_STRING" in
396 # stuff*)
397 # file="$wok/$(GET stuff)"
398 # manage_modified "$file"
399 # ;;
400 #
401 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
402 # type=${QUERY_STRING%%=*}
403 # pkg=$(GET $type)
404 # case "$type" in
405 # description)
406 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
407 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
408 # ;;
409 # log)
410 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
411 # manage_modified "$LOGS/$pkg"
412 # ;;
413 # *)
414 # manage_modified "$wok/$pkg/receipt" pkg
415 # ;;
416 # esac
417 # ;;
418 #esac
421 # RSS feed generator
422 # URI: ?rss[&limit={1..100}]
424 if [ -n "$(GET rss)" ]; then
425 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
426 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
427 cooker_url="http://$HTTP_HOST$base/"
428 cat <<-EOT
429 Content-Type: application/rss+xml
431 <?xml version="1.0" encoding="utf-8" ?>
432 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
433 <channel>
434 <title>$title</title>
435 <description>The SliTaz packages cooker feed</description>
436 <link>$cooker_url</link>
437 <lastBuildDate>$pubdate</lastBuildDate>
438 <pubDate>$pubdate</pubDate>
439 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
440 EOT
441 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
442 sed -e "/\?pkg=/s|http[^=]*=|$cooker_url|;" \
443 -e "s|\([0-9]\)</pubDate>|\1 GMT</pubDate>|" $rss
444 done
445 cat <<-EOT
446 </channel>
447 </rss>
448 EOT
449 exit 0
450 fi
453 ### OpenSearch ###
455 # Query '/os.xml': get OpenSearch Description
457 if [ "$pkg" == 'os.xml' ]; then
458 cat <<-EOT
459 Content-Type: application/xml; charset=UTF-8
461 <?xml version="1.0" encoding="UTF-8"?>
462 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
463 <ShortName>$title</ShortName>
464 <Description>SliTaz packages search</Description>
465 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
466 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
467 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
468 <Param name="oss" value="{searchTerms}"/>
469 </Url>
470 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
471 <InputEncoding>UTF-8</InputEncoding>
472 </OpenSearchDescription>
473 EOT
474 exit 0
475 fi
477 # Query '?oss[=<term>]': OpenSearch suggestions
479 if [ -n "$(GET oss)" ]; then
480 term="$(GET oss | tr -cd '[:alnum:]+-')"
481 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
482 cd $wok
483 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
484 BEGIN{printf("[\"%s\",[", term)}
485 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
486 END {printf("]]")}
487 '
488 exit 0
489 fi
494 #
495 # Functions
496 #
499 # Unpack to stdout
501 docat() {
502 case "$1" in
503 *gz) zcat ;;
504 *bz2) bzcat ;;
505 *xz) xzcat ;;
506 *) cat
507 esac < $1
508 }
511 # Tiny texinfo converter
513 info2html() {
514 sed \
515 -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;' \
516 -e "s|\`\([^']*\)'|<b>\1</b>|g" \
517 -e 's|"\([A-Za-z0-9]\)|“\1|g; s|"|”|g' \
518 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
519 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
520 -e '/^File: / s|(dir)|Top|g' \
521 -e '/^File: / s|Next: \([^,]*\)|<a class="button icon next" href="#\1">Next: \1</a>|' \
522 -e '/^File: / s|Prev: \([^,]*\)|<a class="button icon prev" href="#\1">Prev: \1</a>|' \
523 -e '/^File: / s|Up: \([^,]*\)|<a class="button icon up" href="#\1">Up: \1</a>|' \
524 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
525 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1<div class="buttonbar">\3 \4 \2</div>|' \
526 -e '/^<pre id=/ s|^\([^>]*>\)*\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1<div class="buttonbar">\2 \3 <a class="button icon next" href="#">Next</a></div>|' \
527 -e '/^Tag Table:$/,/^End Tag Table$/d' \
528 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
529 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
530 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
531 -e 's|^\* Menu:|<b>Menu:</b>|' \
532 -e "s|^|</pre>|"
533 }
536 # Put some colors into log and DB files.
538 syntax_highlighter() {
539 case $1 in
540 log)
541 # If variables not defined - define them with some rare values
542 : ${_src=#_#_#}
543 : ${_install=#_#_#}
544 : ${_fs=#_#_#}
545 : ${_stuff=#_#_#}
546 # Use one-letter html tags to save some bytes :)
547 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informative (green)</i>
548 sed \
549 -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
550 -e 's#OK$#<i>OK</i>#' \
551 -e 's#\([Dd]one\)$#<i>\1</i>#' \
552 -e 's#Success$#<i>Success</i>#' \
553 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
554 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
555 -e 's#: \(YES.*\)#: <i>\1</i>#' \
556 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
557 -e 's#\(enabled\)$#<i>\1</i>#' \
558 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
559 -e 's#: \(NO.*\)#: <u>\1</u>#' \
560 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
561 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
562 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
563 -e 's#\(disabled\)$#<u>\1</u>#' \
564 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
565 \
566 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
567 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
568 -e 's# y$# <i>y</i>#' \
569 -e 's# n$# <u>n</u>#' \
570 -e 's#(NEW) *$#<b>(NEW)</b>#' \
571 \
572 -e 's#.*(pkg/local).*#<i>\0</i>#' \
573 -e 's#.*(web/cache).*#<u>\0</u>#' \
574 \
575 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
576 -e 's#ERROR:#<b>ERROR:</b>#g' \
577 \
578 -e 's#^.*multiple definition of.*#<b>\0</b>#' \
579 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
580 -e 's#^.*[^A-Za-z:/-][Ff]atal.*#<b>\0</b>#' \
581 -e '/non-fatal/ s|</*b>||g' \
582 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
583 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
584 -e 's#^.*No package .* found.*#<b>\0</b>#' \
585 -e 's#^.*Unable to find.*#<b>\0</b>#' \
586 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
587 -e 's#Segmentation fault#<b>\1</b>#' \
588 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
589 -e 's#\(found\.*\)$#<i>\1</i>#' \
590 \
591 -e 's#^.*WARNING:.*#<u>\0</u>#' \
592 -e 's#^.*warning:.*#<u>\0</u>#' \
593 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
594 -e 's#^.*terminated.*#<b>\0</b>#' \
595 -e 's#\(missing\)#<b>\1</b>#g' \
596 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
597 -e 's#^.*unrecognized option.*#<u>\0</u>#' \
598 -e 's#^.*does not.*#<u>\0</u>#' \
599 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
600 -e 's#^.*note:.*#<u>\0</u>#' \
601 \
602 -e 's#^.* will not .*#<u>\0</u>#' \
603 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
604 -e 's#^.* Warning: .*#<u>\0</u>#' \
605 \
606 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
607 -e "s#^Making.*#<em>\0</em>#" \
608 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
609 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
610 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
611 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
612 -e 's|^Switching to the .*|<span class="switch">‣‣‣ \0</span>|' \
613 \
614 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
615 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
616 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
617 -e 's|^<u><b>\(.*inlining failed.*\)</b></u>|<u>\1</u>|' \
618 \
619 -e "s|$_src|<var>\${src}</var>|g;
620 s|$_install|<var>\${install}</var>|g;
621 s|$_fs|<var>\${fs}</var>|g;
622 s|$_stuff|<var>\${stuff}</var>|g" \
623 \
624 -e "s|\[\([01]\)m\[3\([1-7]\)m|<span class='c\2\1'>|g;
625 s|\[\([01]\);3\([1-7]\)m|<span class='c\2\1'>|g;
626 s|\[3\([1-7]\)m|<span class='c\10'>|g;
627 s|\[\([01]\);0m|<span class='c0\1'>|g;
628 s|\[0m|</span>|g;
629 s|\[m|</span>|g;
630 s|\[0;10m|</span>|g;
631 s|\[K||g;" \
632 \
633 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
634 s|\[39m|</span>|;
635 #s|\[1m|<span class='c01'>|g;
636 s|\[1m|<span style='font-weight:bold'>|g; s|(B|</span>|g;
637 s|\[m||g;" \
638 \
639 -e "s!^|\(+.*\)!|<span class='c20'>\1</span>!;
640 s!^|\(-.*\)!|<span class='c10'>\1</span>!;
641 s!^|\(@@.*@@\)\$!|<span class='c30'>\1</span>!;" \
642 \
643 -e "s|^Successfully installed [^ ][^ ]*$|<i>\0</i>|;
644 s|^Successfully installed .*$|<b>\0</b>|;
645 s|^\(Requirement already satisfied: .*\) in|<i>\1</i> in|;
646 s|^Collecting .* (from .*$|<b>\0</b>|;
647 s|^ Could not find.*|<b>\0</b>|;
648 s|^No matching distribution found for.*|<b>\0</b>|;"
650 ;;
652 files)
653 # Highlight the Busybox's `ls` output
654 awk '{
655 part1 = substr($0, 0, 16);
656 part2 = substr($0, 17, 9);
657 part3 = substr($0, 26, 9);
658 part4 = substr($0, 35);
659 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
660 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
661 print part1 part2 part3 part4;
662 }' | \
663 sed "s|\[0m/|/\[0m|g;
664 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
665 s|\[\([01]\);0m|<a class='c0\1'>|g;
666 s|\[0m|</a>|g;
667 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
668 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
669 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
670 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
671 s|^\(-rwsr-xr-x\)|<span class='c51'>\1</span>|;
672 s|^\([lrwxs-][lrwxs-]*\)|<span class='c11'>\1</span>|;
673 "
674 ;;
675 esac
676 }
679 show_code() {
680 echo -n "<pre><code class=\"language-$1\">"
681 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
682 echo '</code></pre>'
683 }
686 datalist() {
687 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
688 BEGIN{printf("<datalist id=\"packages\">")}
689 {printf("<option>%s",$1)}
690 END {printf("</datalist>")}
691 '
692 }
695 mklog() {
696 awk '
697 BEGIN { printf("<pre class=\"log dog\">\n") }
698 { print }
699 END { print "</pre>" }'
700 }
703 summary() {
704 log="$1"
705 pkg="$(basename ${log%%.log*})"
707 if [ -f "$log" ]; then
708 if grep -q "cook:$pkg$" $command; then
709 show_note i "The Cooker is currently building $pkg" \
710 | sed 's|>|&<progress id="gauge" class="meter-small" max="100" value="0"></progress> |'
711 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
712 elif fgrep -q "Summary for:" $log; then
713 sed '/^Summary for:/,$!d' $log | awk '
714 BEGIN { print "<section>" }
715 function row(line) {
716 split(line, s, " : ");
717 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
718 }
719 function row2(line, rowNum) {
720 split(line, s, " : ");
721 if (rowNum == 1) {
722 print "<thead>";
723 printf("\t<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", s[1], s[2], s[3], s[4], s[5]);
724 print "</thead><tbody>";
725 }
726 else
727 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", s[1], s[2], s[3], s[4], s[5]);
728 }
729 {
730 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
731 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
732 if ($0 ~ "---") {
733 seen2++;
734 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
735 next
736 }
737 if (seen2) row2($0, seen2); else row($0);
738 }
739 END { print "</tbody></table></section>" }
740 '
741 elif fgrep -q "Debug information" $log; then
742 # second line of log is "Cook: <package> <version>"
743 echo -e "<section>\n<h3>Debug information for $(sed '2!d; s|.*: ||' $log)</h3>"
744 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
745 if [ -n "$2" ]; then
746 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
747 else
748 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
749 fi | mklog
750 echo '</section>'
751 fi
752 else
753 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
754 fi
755 }
758 active() {
759 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
760 }
763 pkg_info() {
764 local log active bpkg short_desc=''
765 log="$LOGS/$pkg.log"
767 echo -n "<div id=\"hdr\"><a href=\"$base/${requested_pkg:-$pkg}\">"
768 if [ -e $wok/$pkg/.icon.png ]; then
769 echo -n "<img src=\"$base/$pkg/browse/.icon.png\" alt=\"$pkg icon\"/>"
770 else
771 echo -n "<img src=\"/tazpkg.png\" alt=\"package icon\"/>"
772 fi
773 echo -n "</a>"
774 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
775 # Get short description for existing packages
776 [ -f $PKGS/packages-$ARCH.info ] &&
777 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages-$ARCH.info)"
778 # If package does not exist (not created yet or broken), get short description
779 # (but only for "main" package) from receipt
780 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
781 echo "<br/>$short_desc</h2></div>"
782 echo '<div id="info">'
783 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
785 # In the receipts $EXTRAVERSION is defined using $kvers, get it here [copy from 'cook' set_paths()]
786 if [ -f "$wok/linux/receipt" ]; then
787 kvers=$(. $wok/linux/receipt; echo $VERSION)
788 kbasevers=$(echo $kvers | cut -d. -f1,2)
789 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
790 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
791 kbasevers=$(echo $kvers | cut -d. -f1,2)
792 fi
794 unset WEB_SITE WANTED
795 . $wok/$pkg/receipt
797 [ -n "$WEB_SITE" ] &&
798 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
800 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/receipt" ] &&
801 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
803 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
804 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
806 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
807 echo "<a class='button icon download' href='$base/$pkg/download'>downloads</a>"
809 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
811 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
812 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
814 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
815 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
817 [ -d "$wok/$pkg/install/usr/share/info" ] &&
818 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
820 if [ -n "$LFS" ]; then
821 printf "<a class='button icon lfs' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
822 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
823 printf "LFS</a>\n"
824 fi
826 ls $log* >/dev/null 2>&1 &&
827 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
829 echo '</div>'
830 }
833 mktable() {
834 sed 's# : #|#' | awk -vc="$1" '
835 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
836 { printf("<tr><td>%s</td>", $1);
837 if (NF == 2) printf("<td>%s</td>", $2);
838 printf("</tr>\n", $2) }
839 END { print "</table>" }'
840 }
843 section() {
844 local i=$(basename "$1")
845 echo -e '\n\n<section>'
846 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
847 echo "<h2>${3%|*}</h2>"
848 mktable "$i"
849 echo '</section>'
850 }
853 show_desc() {
854 echo "<section><h3>Description of “$1”</h3>"
855 if [ -n "$md2html" ]; then
856 $md2html $2
857 else
858 show_code markdown < $2
859 fi
860 echo "</section>"
861 }
864 # Return all the names of packages bundled in this receipt
866 all_names() {
867 # Get package names from $SPLIT variable
868 local split=$(echo $SPLIT \
869 | awk '
870 BEGIN { RS = " "; FS = ":"; }
871 { print $1; }' \
872 | tr '\n' ' ')
873 local split_space=" $split "
874 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
875 # For receipts v1: $SPLIT may present in the $WANTED package,
876 # but split packages have their own receipts
877 echo $PACKAGE
878 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
879 # $PACKAGE included somewhere in $SPLIT (probably in the end).
880 # We should build packages in the order defined in the $SPLIT.
881 echo $split
882 else
883 # We'll build the $PACKAGE, then all defined in the $SPLIT.
884 echo $PACKAGE $split
885 fi
886 }
889 toolchain_version() {
890 echo "<tr><td><a href='$base/$1'>$1</a></td>"
891 awk -F$'\t' -vpkg="$1" '
892 BEGIN { version = description = "---"; }
893 {
894 if ($1 == pkg) { version = $2; description = $4; }
895 }
896 END { printf("<td>%s</td><td>%s</td></tr>", version, description); }
897 ' $PKGS/packages-$ARCH.info
898 }
901 files_header() {
902 echo '<section><h3>Available downloads:</h3>'
903 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
904 }
907 # Update statistics used in web interface.
908 # There is no need to recalculate the statistics every time the page is displayed.
909 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
911 update_webstat() {
912 # for receipts:
913 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
914 rcooked=$(ls -d $WOK/*/taz | wc -l)
915 runbuilt=$(($rtotal - $rcooked))
916 rblocked=$(wc -l < $blocked)
917 rbroken=$(wc -l < $broken)
919 # for packages:
920 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
921 pcooked=$(wc -l < $PKGS/packages-$ARCH.info)
922 punbuilt=$(($ptotal - $pcooked))
923 pblocked=$(
924 while read i; do
925 sed "/^$i\t/!d" $CACHE/split.db
926 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
927 pbroken=$(
928 while read i; do
929 sed "/^$i\t/!d" $CACHE/split.db
930 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
932 cat > $webstat <<-EOT
933 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
934 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
935 EOT
936 }
939 # Show badges for specified package
941 show_badges() {
942 local t p s # title problem solution
944 case $layout in
945 table)
946 echo "<section><h2>Badges</h2><table class=\"badges\"><thead><tr><th></th><th>Problem</th><th>Solution</th></tr></thead><tbody>"
947 ;;
948 list)
949 echo "<section><h2>Badges list</h2><p>Click on badge to get list of packages</p><table class=\"badges\"><thead><tr><th></th><th>Problem</th></tr></thead><tbody>"
950 ;;
951 esac
953 for badge in $@; do
954 case $badge in
955 bdbroken)
956 t="Broken bdeps"
957 p="This package cannot be built because its creation depends on broken packages"
958 s="Fix broken build dependencies"
959 ;;
960 broken)
961 t="Broken package"
962 p="Package is broken"
963 s="Fix package build: analyze <a href=\"$base/$PACKAGE/log/\">logs</a>, upgrade the version, search for patches"
964 ;;
965 any)
966 t="“Any” arch"
967 p="This package contains only architecture-less <a href=\"$base/$PACKAGE/files\">files</a>, it does not make sense to make it several times in each build environment"
968 s="Add the line <code>HOST_ARCH=\"any\"</code> to <a href=\"$base/$PACKAGE/receipt\">receipt</a>"
969 ;;
970 noany)
971 t="No “any” arch"
972 p="This package contains architecture dependent <a href=\"$base/$PACKAGE/files\">files</a>"
973 s="Remove the line <code>HOST_ARCH=\"any\"</code> from <a href=\"$base/$PACKAGE/receipt\">receipt</a>"
974 ;;
975 libtool)
976 t="Libtool isn't fixed"
977 p="This package uses <code>libtool</code> that likes to add unnecessary dependencies to programs and libraries"
978 s="Add the <code>fix libtool</code> command to the <a href=\"$base/$PACKAGE/receipt\">receipt</a> between the <code>configure</code> and <code>make</code> commands invocation"
979 ;;
980 nolibtool)
981 t="Libtool is absent"
982 p="This package does not use <code>libtool</code>, nothing to fix"
983 s="Remove the command <code>fix libtool</code> from <a href=\"$base/$PACKAGE/receipt\">receipt</a>"
984 ;;
985 own)
986 t="Ownership problems"
987 p="Some files of this package have <a href=\"$base/$PACKAGE/files\">ownership problems</a>"
988 s="Correct the ownership or add problem files to the “<a href=\"$base/$PACKAGE/stuff/overrides\">overrides</a>” list if you believe it is OK"
989 ;;
990 ownover)
991 t="Ownership overridden"
992 p="This package contains files with <a href=\"$base/$PACKAGE/files\">ownership problems</a> that have been overridden"
993 s="<abbr title=\"For your information\">FYI</abbr> only, you may want to revise <a href=\"$base/$PACKAGE/stuff/overrides\">the list</a>"
994 ;;
995 perm)
996 t="Permissions problems"
997 p="Some files of this package have <a href=\"$base/$PACKAGE/files\">unusual permissions</a>"
998 s="Correct the permissions or add problem files to the “<a href=\"$base/$PACKAGE/stuff/overrides\">overrides</a>” list if you believe it is OK"
999 ;;
1000 permover)
1001 t="Permissions overridden"
1002 p="This package contains files with <a href=\"$base/$PACKAGE/files\">unusual permissions</a> that have been recorded"
1003 s="<abbr title=\"For your information\">FYI</abbr> only, you may want to revise <a href=\"$base/$PACKAGE/stuff/overrides\">the list</a>"
1004 ;;
1005 symlink)
1006 t="Broken symlink"
1007 p="This package contains one or more <a href=\"$base/$PACKAGE/files\">broken symlinks</a>"
1008 s="Fix the symlinks destination; you may use <code>fix symlinks</code> when symlinks have absolute path"
1009 ;;
1010 ss)
1011 t="Site script"
1012 p="This autotools-based building system uses site script; most of the paths (like <var>prefix</var>, <var>sysconfdir</var> and <var>mandir</var>) are defined there with correct default values"
1013 s="You may remove your paths from <code>configure</code> invocation"
1014 ;;
1015 fadd)
1016 t="Files have been added"
1017 p="Some files absent in <var>\$install</var> was <a href=\"$base/$PACKAGE/files#outoftree\">directly added</a> to <var>\$fs</var>"
1018 s="Rework your <code>compile_rules()</code> to add all the required files to <var>\$install</var> there"
1019 ;;
1020 frem)
1021 t="Files have been removed"
1022 p="Some files existing in <var>\$install</var> <a href=\"$base/$PACKAGE/files#orphans\">not belonging to any package</a>"
1023 s="Revise <code>genpkg_rules()</code> or add files to “<a href=\"$base/$PACKAGE/stuff/overrides\">overrides</a>” list"
1024 ;;
1025 fdup)
1026 t="Files are duplicated"
1027 p="Some files existing in <var>\$install</var> was added to <a href=\"$base/$PACKAGE/files#repeats\">more than one</a> package"
1028 s="Check your copy rules in <code>genpkg_rules()</code>"
1029 ;;
1030 old)
1031 t="Oldie"
1032 p="According to Repology, this package may be <a href=\"https://repology.org/metapackage/${REPOLOGY:-$pkg}\" target=\"_blank\" rel=\"noopener noreferrer\">outdated</a>"
1033 s="Update the package"
1034 ;;
1035 win)
1036 t="Winner"
1037 p="This package has no problems"
1038 s="Well done, keep it up!"
1039 ;;
1040 orphan)
1041 t="Orphaned package"
1042 p="It seems that no other package depends on this one"
1043 s="See if anyone needs it"
1044 ;;
1045 patch)
1046 t="Patch"
1047 p="Patch has been applied"
1048 s="<abbr title=\"For your information\">FYI</abbr> only, you may want to revise <a href=\"$base/$PACKAGE/stuff/patches/series\">the list of patches</a>"
1049 ;;
1050 no-badge)
1051 t="No badge"
1052 p="Packages without badges"
1053 s=""
1054 ;;
1055 esac
1056 case $layout in
1057 table)
1058 echo "<tr><td><span class=\"badge $badge\" title=\"$t\"/></td><td>$p</td><td>$s</td></tr>"
1059 ;;
1060 list)
1061 p=$(echo $p | sed 's|<a [^>]*>\([^<]*\)</a>|\1|g')
1062 s=$(echo $s | sed 's|<a [^>]*>\([^<]*\)</a>|\1|g|')
1063 echo "<tr><td><a href=\"$badge\"><span class=\"badge $badge\" title=\"$t\"/></a></td><td>$p</td></tr>"
1064 ;;
1065 *)
1066 echo -n "<span class=\"badge $badge\" title=\"$t\"/>"
1067 ;;
1068 esac
1069 done
1071 case $layout in
1072 table|list)
1073 echo "</tbody></table></section>"
1074 ;;
1075 esac
1079 # Generate part of the main page
1081 part() {
1082 echo -n "<div id='$1'>"
1084 case $1 in
1085 summary)
1086 echo '<h2>Summary</h2>'
1088 mktable <<EOT
1089 Cooker state : $(running_command)
1090 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
1091 Commits to cook : $(wc -l < $commits)
1092 Current cooklist : $(wc -l < $cooklist)
1093 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
1094 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
1095 EOT
1097 # If command is "cook:*", update gauge and percentage periodically.
1098 # If different package is cooking, reload the page (with new settings)
1099 cmd="$(cat $command)"
1100 case "$cmd" in
1101 cook:*)
1102 pkg=${cmd#*:}
1103 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
1104 ;;
1105 esac
1106 ;;
1107 webstat)
1108 # Do we need to update the statistics?
1109 if [ -n "$nojs" -a "$activity" -nt "$webstat" ]; then update_webstat; fi
1110 . $webstat
1112 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
1114 cat <<-EOT
1115 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
1117 <table class="webstat">
1118 <thead>
1119 <tr>
1120 <th> </th>
1121 <th>Total </th>
1122 <th>Cooked </th>
1123 <th>Unbuilt </th>
1124 <th>Blocked </th>
1125 <th>Broken </th>
1126 </tr>
1127 </thead>
1128 <tbody>
1129 <tr>
1130 <td>Receipts</td>
1131 <td>$rtotal</td>
1132 <td>$rcooked</td>
1133 <td>$runbuilt</td>
1134 <td>$rblocked</td>
1135 <td>$rbroken</td>
1136 </tr>
1137 <tr>
1138 <td>Packages</td>
1139 <td>$ptotal</td>
1140 <td>$pcooked</td>
1141 <td>$punbuilt</td>
1142 <td>$pblocked</td>
1143 <td>$pbroken</td>
1144 </tr>
1145 </tbody>
1146 </table>
1147 EOT
1148 if [ -z "$nojs" ]; then echo "<script>getPart('$1')</script>"; fi
1149 ;;
1150 activity)
1151 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
1152 s|\[ Done|<span class="r c20">Done|;
1153 s|\[ Failed|<span class="r c10">Failed|;
1154 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1155 s| \]|</span>|;
1156 s|%2B|\+|g' \
1157 | while read line; do
1158 case "$line" in
1159 *data-badges=*)
1160 badges="$(echo "$line" | sed "s|.*data-badges='\([^']*\)'.*|\1|")"
1161 echo "$line" | sed "s|</a>|</a> $(show_badges "$badges")|"
1162 ;;
1163 *)
1164 echo "$line"
1165 ;;
1166 esac
1167 done | section $activity 12 "Activity|More activity" \
1168 ;;
1169 cooknotes)
1170 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
1171 section $cooknotes 12 "Cooknotes|More notes"
1172 ;;
1173 commits)
1174 [ -s "$commits" ] && head -n20 $commits | \
1175 section $commits 20 "Commits|More commits"
1176 ;;
1177 cooklist)
1178 [ -s "$cooklist" ] && head -n 20 $cooklist | \
1179 section $cooklist 20 "Cooklist|Full cooklist"
1180 ;;
1181 broken)
1182 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
1183 section $broken 20 "Broken|All broken packages"
1184 ;;
1185 blocked)
1186 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
1187 section $blocked 12 "Blocked|All blocked packages"
1188 ;;
1189 pkgs)
1190 cd $PKGS
1191 # About BusyBox's `ls`
1192 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
1193 # It supported the option `-e`, output with `-let` options like this:
1194 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
1195 # 1 2 3 4 5 6 7 8 9 10 11
1196 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
1197 # configure it or return the option back. It supported the long option
1198 # `--full-time` instead, but output is different:
1199 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
1200 # 1 2 3 4 5 6 7 8 9
1201 if ls -let >/dev/null 2>&1; then
1202 ls -let *.tazpkg \
1203 | awk '
1204 (NR<=20){
1205 sub(/:[0-9][0-9]$/, "", $9);
1206 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
1207 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
1208 }' \
1209 | section $activity 1000 "Latest cook"
1210 else
1211 ls -lt --full-time *.tazpkg \
1212 | awk '
1213 (NR<=20){
1214 sub(/:[0-9][0-9]$/, "", $7);
1215 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
1216 }' \
1217 | section $activity 1000 "Latest cook"
1218 fi
1219 ;;
1220 esac
1221 echo "</div>"
1225 # Query '?part=<part>': get part of the main page
1227 if [ -n "$(GET part)" ]; then
1228 part="$(GET part)"
1229 case $part in
1230 summary|webstat|activity|cooknotes|commits|cooklist|broken|blocked|pkgs)
1231 nojs='yes'
1232 part $part
1233 ;;
1234 esac
1235 exit 0
1236 fi
1242 # Load requested page
1245 if [ -z "$pkg" ]; then
1247 page_header
1248 if [ -n "$QUERY_STRING" ]; then
1250 [ "$QUERY_STRING" != 'commits.log' ] &&
1251 for list in activity cooknotes cooklist commits; do
1252 [ -n "$(GET $list)" ] || continue
1253 case $list in
1254 cooklist) nb="- Packages: $(wc -l < $cooklist)";;
1255 commits) nb="- Packages: $(wc -l < $commits)";;
1256 esac
1257 echo '<section id="content2">'
1258 echo "<h2>DB: $list $nb</h2>"
1260 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
1261 s|\[ Done|<span class="r c20">Done|;
1262 s|\[ Failed|<span class="r c10">Failed|;
1263 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1264 s| \]|</span>|;
1265 s|%2B|\+|g' \
1266 | while read line; do
1267 case "$line" in
1268 *data-badges=*)
1269 badges="$(echo "$line" | sed "s|.*data-badges='\([^']*\)'.*|\1|")"
1270 echo "$line" | sed "s|</a>|</a> $(show_badges "$badges")|"
1271 ;;
1272 *)
1273 echo "$line"
1274 ;;
1275 esac
1276 done \
1277 | mktable $list
1279 echo '</section>'
1280 done
1282 if [ -n "$(GET broken)" ]; then
1283 echo '<section id="content2">'
1284 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
1285 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
1286 echo '</section>'
1287 fi
1289 case "$QUERY_STRING" in
1290 *.log)
1291 log=$LOGS/$QUERY_STRING
1292 name=$(basename $log)
1293 if [ -f "$log" ]; then
1294 echo "<h2>Log for: ${name%.log}</h2>"
1295 if fgrep -q "Summary" $log; then
1296 echo '<pre class="log">'
1297 grep -A 20 'Summary' $log | syntax_highlighter log
1298 echo '</pre>'
1299 fi
1300 echo '<pre class="log">'
1301 syntax_highlighter log < $log
1302 echo '</pre>'
1303 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
1304 # Display button only for SliTaz web browser
1305 case "$HTTP_USER_AGENT" in
1306 *SliTaz*)
1307 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1308 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
1309 show_note i "The package database has been requested for re-creation"
1310 else
1311 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
1312 fi
1313 fi
1314 ;;
1315 esac
1316 fi
1317 else
1318 show_note e "No log file: $log"
1319 fi
1320 ;;
1321 toolchain)
1322 cat <<-EOT
1323 <div id="content2">
1324 <section>
1325 <h2>SliTaz GNU/Linux toolchain</h2>
1327 <table>
1328 <tr>
1329 <td>Build date</td>
1330 <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td>
1331 </tr>
1332 <tr>
1333 <td>Build duration</td>
1334 <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td>
1335 </tr>
1336 <tr>
1337 <td>Architecture</td>
1338 <td colspan="2">$ARCH</td>
1339 </tr>
1340 <tr>
1341 <td>Host system</td>
1342 <td colspan="2">$BUILD_SYSTEM</td>
1343 </tr>
1344 <tr>
1345 <td>Target system</td>
1346 <td colspan="2">$HOST_SYSTEM</td>
1347 </tr>
1348 <tr>
1349 <th>Package</th>
1350 <th>Version</th>
1351 <th>Description</th>
1352 </tr>
1353 $(toolchain_version slitaz-toolchain)
1354 $(toolchain_version binutils)
1355 $(toolchain_version linux-api-headers)
1356 $(toolchain_version gcc)
1357 $(toolchain_version glibc)
1358 </table>
1360 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
1361 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
1362 </p>
1364 </section>
1365 </div>
1366 EOT
1367 ;;
1368 maintainer*)
1369 maintainer=$(GET maintainer); maintainer=${maintainer/maintainer/}
1370 regexp=$(GET regexp); regexp=${regexp/regexp/}
1371 [ -n "$regexp" ] && maintainer=''
1372 cat <<-EOT
1373 <section>
1374 <h2>For maintainers</h2>
1375 <p>Here you can <a href="=/">explore the badges</a>.</p>
1376 <p>Or see some <a href="?maintainer&amp;stats">repository statistics</a>.</p>
1377 <p>Or check packages version either for specified maintainer or using regular expressions:</p>
1378 <form>
1379 <select name="maintainer">
1380 <option value=''>--- select maintainer ---
1381 EOT
1382 cut -d$'\t' -f1 $maintdb | sort -u \
1383 | awk -vm=$maintainer '{
1384 selected=$0==m?"selected":""
1385 printf("<option %s value=\"%s\">%s\n", selected, $0, $0)
1386 }'
1387 cat <<-EOT
1388 </select>
1389 or
1390 <input type="text" name="regexp" value="$regexp"/>
1391 <button type="submit">Go</button>
1392 </form>
1393 EOT
1394 if [ -n "$maintainer" -o -n "$regexp" ]; then
1395 tmp_status=$(mktemp)
1396 cat <<-EOT
1397 <table class="maint">
1398 <thead><tr><th>Package</th><th>Version</th><th>Repology</th></tr></thead>
1399 EOT
1401 if [ -n "$maintainer" ]; then
1402 awk -vm=$maintainer '{if ($1 == m) print $2}' $maintdb
1403 fi
1404 if [ -n "$regexp" ]; then
1405 cd $wok; ls | grep "$regexp"
1406 fi
1407 } | while read pkg; do
1408 unset VERSION; REPOLOGY=$pkg
1409 . $wok/$pkg/receipt
1410 ver=$(awk -F$'\t' -vpkg="$pkg" '{if ($1 == pkg) {print $2; exit}}' $PKGS/packages-$ARCH.info)
1411 if [ "$REPOLOGY" == '-' ]; then
1412 unset repo_info1 repo_info2
1413 echo '-' >>$tmp_status
1414 else
1415 repo_ver=$(repology_get $REPOLOGY)
1416 if [ "$repo_ver" == '-' ]; then
1417 echo '-' >>$tmp_status
1418 icon='more'
1419 else
1420 if echo " $repo_ver " | fgrep -q " ${ver:-$VERSION} "; then
1421 icon='actual'
1422 else
1423 icon='update'
1424 fi
1425 echo $icon >>$tmp_status
1426 fi
1427 repo_info1="<a class='icon $icon' href='https://repology.org/metapackage/$REPOLOGY' target='_blank'"
1428 repo_info2="rel='noopener noreferrer' title='latest packaged version(s)'>${repo_ver// /, }</a>"
1429 fi
1430 cat <<-EOT
1431 <tr>
1432 <td><img src="$base/s/$pkg" alt="$pkg"> <a href="$pkg">$pkg</a></td>
1433 <td>${ver:-$VERSION}</td>
1434 <td>$repo_info1 $repo_info2</td>
1435 </tr>
1436 EOT
1437 done
1439 pkg_total=$( wc -l < $tmp_status)
1440 pkg_actual=$( fgrep actual $tmp_status | wc -l)
1441 pkg_outdated=$(fgrep update $tmp_status | wc -l)
1442 pkg_unknown=$( fgrep '-' $tmp_status | wc -l)
1444 pct_actual=$(( $pkg_actual * 100 / $pkg_total ))
1445 pct_outdated=$(( $pkg_outdated * 100 / $pkg_total ))
1446 pct_unknown=$(( $pkg_unknown * 100 / $pkg_total ))
1448 [ "$pkg_actual" -eq 0 ] && pkg_actual=''
1449 [ "$pkg_outdated" -eq 0 ] && pkg_outdated=''
1450 [ "$pkg_unknown" -eq 0 ] && pkg_unknown=''
1452 cat <<-EOT
1453 </table>
1455 <div class="meter" style="width:100%;text-align:center"><div
1456 style="display:inline-block;background-color:#090;width:$pct_actual%">$pkg_actual</div><div
1457 style="display:inline-block;background-color:#f90;width:$pct_outdated%">$pkg_outdated</div><div
1458 style="display:inline-block;background-color:#ccc;width:$pct_unknown%">$pkg_unknown</div></div>
1459 EOT
1460 rm $tmp_status
1461 fi
1462 cat <<-EOT
1463 </section>
1464 EOT
1465 ;;
1466 esac
1467 page_footer
1468 exit 0
1469 fi
1472 # We may have a toolchain.cgi script for cross cooker's
1473 if [ -f "toolchain.cgi" ]; then
1474 toolchain="toolchain.cgi"
1475 else
1476 toolchain="?toolchain"
1477 fi
1479 # Main page with summary. Count only packages included in ARCH,
1480 # use 'cooker arch-db' to manually create arch.$ARCH files.
1482 cat <<-EOT
1483 <div id="content2">
1485 <section>
1486 <form method="get" action="" class="search r">
1487 <input type="hidden" name="search" value="pkg"/>
1488 <button type="submit" title="Search">Search</button>
1489 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
1490 </form>
1491 EOT
1493 unset nojs
1494 part summary
1495 part webstat
1497 cat <<-EOT
1498 <p>
1499 Service logs:
1500 <a href="?cookorder.log">cookorder</a> ·
1501 <a href="?commits.log">commits</a> ·
1502 <a href="?pkgdb.log">pkgdb</a>
1503 </p>
1504 EOT
1506 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1507 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1508 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1509 else
1510 show_note i 'Cooker will be launched in the next 5 minutes.'
1511 fi
1512 fi
1514 cat <<-EOT
1515 <a class="button icon maintainers" href="?maintainer">For maintainers</a>
1516 <a class="button icon tag" href="~/">Tags</a>
1517 </section>
1518 EOT
1520 part activity
1521 part cooknotes
1522 part commits
1523 part cooklist
1524 part broken
1525 part blocked
1526 part pkgs
1528 echo '</div>'
1529 datalist
1530 page_footer
1531 exit 0
1532 fi
1535 # show tag
1537 if [ "$pkg" == '~' ]; then
1538 page_header
1539 echo '<div id="content2"><section>'
1541 if [ -n "$cmd" ]; then
1542 tag="$cmd"
1543 cat <<-EOT
1544 <h2>Tag “$tag”</h2>
1546 <table>
1547 <thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead>
1548 <tbody>
1549 EOT
1550 sort $PKGS/packages-$ARCH.info \
1551 | awk -F$'\t' -vtag=" $tag " -vbase="$base/" '{
1552 if (index(" " $6 " ", tag)) {
1553 url = base $1 "/";
1554 gsub("+", "%2B", url);
1555 printf("<tr><td><img src=\"%ss/%s\" alt=\"%s\"> ", base, $1, $1);
1556 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1558 }'
1559 echo '</tbody></table>'
1560 else
1561 # Fast and nice tag cloud
1562 echo '<h2>Tag cloud</h2><p class="tags">'
1563 # Some magic in tag sizes :-) It's because of non-linear distribution
1564 # of tags. Currently 1x198 (each of 198 tags marks one package);
1565 # 2x79 (each of 79 other tags marks two packages); 3x28 (and so on);
1566 # 4x23; 5x14; 6x5; 7x9; 8x11; 9x4; 10x3; 11x5; 12x6; 13x3; 14x1; 15x1;
1567 # 16x2; 18x1; 20x3; 22x3; 23, 24, 27, 33, 39, 42, 45, 57, 59, 65, 90x1.
1568 awk -F$'\t' -vbase="$base/~/" '
1570 split($6, tags, " ");
1571 for (i in tags) { tag[tags[i]]++; if (tag[tags[i]] > max) max = tag[tags[i]]; }
1573 END {
1574 for (i in tag) {
1575 j = tag[i];
1576 size = (j == 1) ? 0 : (j == 2) ? 1 : (j < 5) ? 2 : (j < 9) ? 3 : (j < 18) ? 4 : 5;
1577 printf("<a href=\"%s\" class=\"tag%s\">%s<sup>%s</sup></a>\n", base i, size, i, tag[i]);
1580 ' $PKGS/packages-$ARCH.info | sort -f # sort alphabetically case insensitive
1581 fi
1582 echo '</p></section></div>'
1583 page_footer
1584 exit 0
1585 fi
1588 # show badges
1590 if [ "$pkg" == '=' ]; then
1591 page_header
1592 echo '<div id="content2">'
1594 if [ -n "$cmd" ]; then
1595 badge="$cmd"
1596 case "$badge" in
1597 no-badge)
1598 cat <<-EOT
1599 <section>
1600 <h2 class="badge $badge"> Packages without badges</h2>
1602 <table>
1603 <thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead>
1604 <tbody>
1605 EOT
1607 ls $WOK \
1608 | while read pkg; do
1609 [ -s $WOK/$pkg/.badges ] && continue
1610 awk -F$'\t' -vpkg="$pkg" -vbase="$base/" '{
1611 if ($1 == pkg) {
1612 url = base $1 "/";
1613 gsub("+", "%2B", url);
1614 printf("<tr><td><img src=\"%ss/%s\" alt=\"%s\"> ", base, $1, $1);
1615 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1617 }' $PKGS/packages-$ARCH.info
1618 done
1619 ;;
1620 *)
1621 cat <<-EOT
1622 <section>
1623 <h2 class="badge $badge"> Badge “$badge”</h2>
1625 <table>
1626 <thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead>
1627 <tbody>
1628 EOT
1630 ls $WOK \
1631 | while read pkg; do
1632 [ -e $WOK/$pkg/.badges ] || continue
1633 if grep -q "^${badge}$" $WOK/$pkg/.badges; then
1634 if grep -q "^$pkg " $PKGS/packages-$ARCH.info; then
1635 awk -F$'\t' -vpkg="$pkg" -vbase="$base/" '{
1636 if ($1 == pkg) {
1637 url = base $1 "/";
1638 gsub("+", "%2B", url);
1639 printf("<tr><td><img src=\"%ss/%s\" alt=\"%s\"> ", base, $1, $1);
1640 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1642 }' $PKGS/packages-$ARCH.info
1643 else
1644 # broken packages absent in packages-<arch>.info; use receipt (slower)
1646 . $WOK/$pkg/receipt
1647 echo -n "<tr><td><img src=\"$base/s/$pkg\" alt=\"$pkg\"> "
1648 echo -n "<a href=\"$base/$pkg/\">$pkg</a></td>"
1649 echo "<td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1651 fi
1652 fi
1653 done
1654 ;;
1655 esac
1656 echo '</tbody></table></section>'
1657 else
1658 layout='list' show_badges bdbroken broken any noany libtool nolibtool own ownover perm permover symlink ss fadd frem fdup old orphan patch win no-badge
1659 fi
1660 echo '</div>'
1661 page_footer
1662 exit 0
1663 fi
1666 case "$cmd" in
1667 '')
1668 page_header
1670 requested_pkg="$pkg"
1671 # Package info.
1672 if [ ! -f "$wok/$pkg/receipt" ]; then
1673 # Let's look at the cases when the package was not found
1675 # Maybe query is the exact name of split package? -> proceed to main package
1676 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1677 if (index(" " $2 " ", pkg)) {print $1; exit}
1678 }' $splitdb)
1680 # No, so let's find any matches among packages names (both main and split)
1681 if [ -z "$mainpkg" ]; then
1682 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1683 # Nothing matched
1684 if [ -z "$pkgs" ]; then
1685 echo "<h2>Not Found</h2>"
1686 show_note e "The requested package <b>$pkg</b> was not found on this server."
1687 page_footer; exit 0
1688 fi
1689 # Search results page
1690 echo "<section><h2>Package names matching “$pkg”</h2>"
1691 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1692 query="$pkg"
1693 for pkg in $pkgs; do
1694 # Find main package
1695 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1696 if (index(" " $2 " ", pkg)) {print $1; exit}
1697 }' $splitdb)
1698 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1700 unset SHORT_DESC CATEGORY
1701 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1702 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1704 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1705 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1706 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1707 done
1708 echo '</tbody></table></section>'
1709 page_footer; exit 0
1710 fi
1711 pkg="$mainpkg"
1712 fi
1714 log=$LOGS/$pkg.log
1715 pkg_info
1717 # Check for a log file and display summary if it exists.
1718 summary "$log"
1721 # Show Cooker badges
1722 if [ -s $wok/$pkg/.badges ]; then
1723 layout='table' show_badges $(cat $wok/$pkg/.badges)
1724 fi
1727 # Repology badge
1728 [ "$REPOLOGY" == '-' ] || cat <<-EOT
1729 <section>
1730 <h3>Repology</h3>
1731 <a href="https://repology.org/metapackage/${REPOLOGY:-$pkg}" target='_blank'
1732 rel='noopener noreferrer' title="latest packaged version(s) by Repology">
1733 <img src="https://repology.org/badge/latest-versions/${REPOLOGY:-$pkg}.svg" alt="latest packaged version(s)">
1734 <img src="https://repology.org/badge/tiny-repos/${REPOLOGY:-$pkg}.svg" alt="Packaging status">
1735 </a>
1736 </section>
1737 EOT
1740 # Show tag list
1741 taglist=$(
1742 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1743 [ -s "$PKGS/packages-$ARCH.info" ] &&
1744 awk -F$'\t' -vpkg="$i" '{
1745 if ($1 == pkg) { print $6; exit; }
1746 }' "$PKGS/packages-$ARCH.info"
1747 done \
1748 | tr ' ' '\n' \
1749 | sort -u
1751 if [ -n "$taglist" ]; then
1752 echo -n '<section><h3>Tags</h3><p>'
1753 lasttag=$(echo "$taglist" | tail -n1)
1754 for tag in $taglist; do
1755 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1756 [ "$tag" != "$lasttag" ] && echo -n " · "
1757 done
1758 echo '</p></section>'
1759 fi
1762 # Informational table with dependencies
1763 pkg="$requested_pkg"
1764 inf="$(mktemp -d)"
1766 # 1/3: Build dependencies (from receipt and pkgdb)
1767 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1768 echo "$i" >> $inf/a
1769 done
1771 # 2/3: Runtime dependencies (from pkgdb)
1773 [ -s "$PKGS/packages-$ARCH.info" ] &&
1774 awk -F$'\t' -vp="$pkg" '{
1775 if ($1 == p) print $8
1776 }' "$PKGS/packages-$ARCH.info"
1777 } | tr ' ' '\n' | sort -u > $inf/b
1779 # 3/3: Required by (from pkgdb)
1781 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1782 [ -s "$PKGS/packages-$ARCH.info" ] &&
1783 awk -F$'\t' -vp=" $i " '{
1784 if (index(" " $8 " ", p)) print $1
1785 }' "$PKGS/packages-$ARCH.info"
1787 [ -s "$PKGS/bdeps.txt" ] &&
1788 awk -F$'\t' -vp=" $i " '{
1789 if (index(" " $2 " ", p)) print $1
1790 }' $PKGS/bdeps.txt
1791 done
1792 } | sort -u > $inf/c
1794 cat <<-EOT
1795 <section>
1796 <h3>Related packages</h3>
1797 <table class="third">
1798 <thead>
1799 <tr>
1800 <th>Build dependencies</th>
1801 <th>Runtime dependencies</th>
1802 <th>Required by</th>
1803 </tr>
1804 </thead>
1805 <tbody>
1806 EOT
1808 awk -vinf="$inf" -vbase="$base" '
1809 function linki(i) {
1810 if (i) return sprintf("<img src=\"%s/s/%s\" alt=\"%s\"> <a href=\"%s/%s\">%s</a>", base, i, i, base, i, i);
1812 BEGIN{
1813 do {
1814 a = b = c = "";
1815 getline a < inf "/a";
1816 getline b < inf "/b";
1817 getline c < inf "/c";
1818 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1819 } while ( a b c )
1820 }'
1821 cat <<-EOT
1822 </tbody>
1823 </table>
1824 </section>
1825 EOT
1826 # Clean
1827 rm -r $inf
1832 # Display <Recook> button only for SliTaz web browser
1833 case "$HTTP_USER_AGENT" in
1834 *SliTaz*)
1835 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1836 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1837 show_note i "The package “$pkg” has been requested for recook"
1838 else
1839 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1840 fi
1841 fi
1842 ;;
1843 esac
1844 ;;
1846 receipt)
1847 page_header
1848 pkg_info
1849 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1850 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1851 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1853 show_code bash < $wok/$pkg/receipt
1854 ;;
1856 stuff)
1857 page_header
1858 pkg_info
1859 file="$pkg/stuff/$arg"
1860 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1861 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1862 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1863 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1864 }'
1866 if [ -f "$wok/$file" ]; then
1867 case $file in
1868 *.desktop|*.theme) class="ini" ;;
1869 *.patch|*.diff|*.u) class="diff" ;;
1870 */patches/series) class="bash";;
1871 *.sh) class="bash" ;;
1872 *.conf*|*.ini)
1873 class="bash"
1874 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1875 ;;
1876 *.pl) class="perl" ;;
1877 *.c|*.h|*.awk) class="clike" ;;
1878 *.svg) class="svg" ;;
1879 *Makefile*) class="makefile" ;;
1880 *.po|*.pot) class="bash" ;;
1881 *.css) class="css" ;;
1882 *.htm|*.html) class="html" ;;
1883 *.js) class="js" ;;
1884 *.txt) class="asciidoc" ;;
1885 *)
1886 case $(head -n1 $wok/$file) in
1887 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1888 esac
1889 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1890 class="bash"
1891 fi
1892 if [ -z "$class" ]; then
1893 # Follow Busybox restrictions. Search for non-printable chars
1894 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1895 raw="true"
1896 fi
1897 fi
1898 ;;
1899 esac
1901 # Display image
1902 case $file in
1903 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1904 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto' alt=''/>"
1905 ;;
1906 esac
1908 # Display colored listing for all text-based documents (also for *.svg)
1909 case $file in
1910 *.png|*.jpg|*.jpeg|*.ico) ;;
1911 *)
1912 if [ -z "$raw" ]; then
1913 cat $wok/$file | show_code $class
1914 fi
1915 ;;
1916 esac
1918 # Display hex dump for binary files
1919 if [ -n "$raw" ]; then
1920 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1921 fi
1922 else
1923 show_note e "File “$file” absent!"
1924 fi
1925 ;;
1927 files)
1928 page_header
1929 pkg_info
1931 # find main package
1932 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1933 main=${wanted:-$pkg}
1934 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1936 splitsets=$(echo $SPLIT" " \
1937 | awk '
1938 BEGIN { RS = " "; FS = ":"; }
1939 { print $2; }' \
1940 | sort -u \
1941 | tr '\n' ' ' \
1942 | sed 's|^ *||; s| *$||')
1944 splitpkgs=$(echo $SPLIT" " \
1945 | awk '
1946 BEGIN { RS = " "; FS = ":"; }
1947 { print $1; }' \
1948 | tr '\n' ' ' \
1949 | sed 's|^ *||; s| *$||')
1951 # we need the version
1952 if [ -f "$WOK/linux/receipt" ]; then
1953 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1954 kbasevers=$(echo $kvers | cut -d. -f1,2)
1955 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1956 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1957 kbasevers=$(echo $kvers | cut -d. -f1,2)
1958 fi
1959 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1961 echo "<section><h3>Quick jump:</h3>"
1964 for part in head body; do
1966 for set in '' $splitsets; do
1967 pkgsofset=$(echo $SPLIT" " \
1968 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1969 BEGIN {
1970 RS = " "; FS = ":";
1971 if (!set) print main;
1972 if (!set && dev) print dev;
1975 if ($2 == set) print $1;
1976 }' \
1977 | sort -u)
1979 set_description=''
1980 [ -n "$splitsets" ] &&
1981 case "$set" in
1982 '')
1983 set_description=' (default set)'
1984 set_title='Default set'
1985 ;;
1986 *)
1987 set_description=" (set “$set”)"
1988 set_title="Set “$set”"
1989 ;;
1990 esac
1992 install="$wok/$main/install"
1993 [ -n "$set" ] && install="$install-$set"
1995 case $part in
1996 head)
1997 [ -n "$splitsets" ] &&
1998 case "$set" in
1999 '') echo "<ul><li>Default set:";;
2000 *) echo "<li>Set “$set”:";;
2001 esac
2002 echo -e '\t<ul>'
2003 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
2004 cat <<-EOT
2005 <li id='li-repeats$set' style='display:none'>
2006 <a href='#repeats$set'>repeatedly packaged files</a></li>
2007 <li id='li-empty$set' style='display:none'>
2008 <a href='#empty$set'>unpackaged empty folders</a></li>
2009 <li id='li-outoftree$set' style='display:none'>
2010 <a href='#outoftree$set'>out-of-tree files</a></li>
2011 <li id='li-orphans$set' style='display:none'>
2012 <a href='#orphans$set'>unpackaged files</a>
2013 <span id='orphansTypes$set'></span></li>
2014 EOT
2015 echo -e '\t</ul>'
2016 [ -n "$splitsets" ] && echo "</li>"
2017 ;;
2018 body)
2019 all_files=$(mktemp)
2020 cd $install; find ! -type d | sed 's|\.||' > $all_files
2022 # ------------------------------------------------------
2023 # Packages content
2024 # ------------------------------------------------------
2025 packaged=$(mktemp)
2026 for p in $pkgsofset; do
2027 namever="$(awk -F$'\t' -vp="$p" '{
2028 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
2029 }' $PKGS/packages-$ARCH.info)"
2030 if [ -d "$wok/$p/taz/$p-$ver" ]; then
2031 indir=$p
2032 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
2033 indir=$main
2034 fi
2035 dir="$wok/$indir/taz/$p-$ver/fs"
2037 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
2039 echo
2040 echo "<section id='$p'>"
2041 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
2042 echo ' <pre class="files">'
2043 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
2044 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2045 cd $dir
2046 find . -print0 \
2047 | sort -z \
2048 | xargs -0 ls -ldp --color=always \
2049 | syntax_highlighter files \
2050 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
2051 | awk 'BEGIN { FS="\""; }
2052 { gsub("+", "%2B", $2); print; }'
2053 else
2054 echo 'No files'
2055 fi
2056 echo '</pre>'
2057 echo '</section>'
2059 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
2060 done
2061 # ------------------------------------------------------
2062 # /Packages content
2063 # ------------------------------------------------------
2065 # ------------------------------------------------------
2066 # Repeatedly packaged files
2067 # ------------------------------------------------------
2068 repeats=$(mktemp)
2069 sort $packaged | uniq -d > $repeats
2070 if [ -s "$repeats" ]; then
2071 cat <<-EOT
2073 <script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>
2074 <section id='repeats$set'>
2075 <h3>Repeatedly packaged files$set_description:</h3>
2076 EOT
2077 cd $install
2079 IFS=$'\n'
2080 echo -n ' <pre class="files">'
2081 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2082 while read i; do
2083 find .$i -exec ls -ldp --color=always '{}' \; \
2084 | syntax_highlighter files \
2085 | sed 's|>\./|>/|'
2086 done < $repeats
2087 cat <<-EOT
2088 </pre>
2089 </section>
2090 EOT
2091 unset IFS
2092 fi
2093 rm $repeats
2094 # ------------------------------------------------------
2095 # /Repeatedly packaged files
2096 # ------------------------------------------------------
2098 # ------------------------------------------------------
2099 # Unpackaged empty folders
2100 # ------------------------------------------------------
2101 emptydirs=$(mktemp)
2102 cd $install
2103 IFS=$'\n'
2104 find -type d \
2105 | sed 's|\.||' \
2106 | while read d; do
2107 [ -z "$(ls "$install$d")" ] || continue
2108 # empty dir determined by empty `ls`
2109 echo $d
2110 done \
2111 | while read d; do
2112 notfound='yes'
2113 for p in $(cd $wok/$main/taz; ls); do
2114 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
2115 notfound=''
2116 break
2117 fi
2118 done
2119 [ -n "$notfound" ] &&
2120 ls -ldp --color=always .$d \
2121 | syntax_highlighter files \
2122 | sed 's|>\./|>/|'
2123 done > $emptydirs
2124 unset IFS
2125 if [ -s "$emptydirs" ]; then
2126 cat <<-EOT
2128 <script>document.getElementById('li-empty$set').style.display = 'list-item'</script>
2129 <section id='empty$set'>
2130 <h3>Unpackaged empty folders$set_description:</h3>
2131 EOT
2132 echo -n ' <pre class="files">'
2133 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2134 cat $emptydirs
2135 cat <<-EOT
2136 </pre>
2137 </section>
2138 EOT
2139 fi
2140 rm $emptydirs
2141 # ------------------------------------------------------
2142 # /Unpackaged empty folders
2143 # ------------------------------------------------------
2145 # ------------------------------------------------------
2146 # Out-of-tree files
2147 # ------------------------------------------------------
2148 outoftree=$(mktemp)
2149 awk -F$'\n' -vall="$all_files" '
2151 if (FILENAME == all) files_all[$1] = "1";
2152 else files_pkg[$1] = "1";
2154 END {
2155 for (i in files_pkg) {
2156 if (! files_all[i]) print i;
2159 ' "$all_files" "$packaged" > $outoftree
2161 if [ -d "$install" -a -s "$outoftree" ]; then
2162 echo
2163 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
2164 echo "<section id='outoftree$set'>"
2165 echo " <h3>Out-of-tree files$set_description:</h3>"
2166 echo -n ' <pre class="files">'
2167 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2168 IFS=$'\n'
2169 while read outoftree_line; do
2170 # Find the package out-of-tree file belongs to
2171 for i in $pkgsofset; do
2172 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
2173 cd $wok/$main/taz/$i-$ver/fs
2174 ls -ldp --color=always ".$outoftree_line" \
2175 | syntax_highlighter files \
2176 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
2177 | awk 'BEGIN { FS="\""; }
2178 { gsub("+", "%2B", $2); print; }'
2179 fi
2180 done
2181 done < $outoftree
2182 unset IFS
2183 echo '</pre>'
2184 echo '</section>'
2185 fi
2186 rm $outoftree
2187 # ------------------------------------------------------
2188 # /Out-of-tree files
2189 # ------------------------------------------------------
2191 # ------------------------------------------------------
2192 # Unpackaged files
2193 # ------------------------------------------------------
2194 orphans=$(mktemp)
2195 awk -F$'\n' -vall="$all_files" '
2197 if (FILENAME == all) files_all[$1] = "1";
2198 else files_pkg[$1] = "1";
2200 END {
2201 for (i in files_all) {
2202 if (! files_pkg[i]) print i;
2205 ' "$all_files" "$packaged" | sort > $orphans
2206 if [ -d "$install" -a -s "$orphans" ]; then
2207 echo
2208 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
2209 echo "<section id='orphans$set'>"
2210 echo " <h3>Unpackaged files$set_description:</h3>"
2211 table=$(mktemp)
2212 awk '
2213 function tag(text, color) {
2214 printf("<span class=\"c%s1\">%s</span> ", color, text);
2215 printf("%s\n", $0);
2217 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
2218 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
2219 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
2220 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ ||
2221 /\/cache\/.*\.gem$/ {
2222 tag("---", 0); next }
2223 /\.pod$/ { tag("pod", 5); next }
2224 /\/share\/man\// { tag("man", 5); next }
2225 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
2226 /\/share\/devhelp\// { tag("doc", 5); next }
2227 /\/share\/icons\// { tag("ico", 2); next }
2228 /\/share\/locale\// { tag("loc", 4); next }
2229 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
2230 /\/Makefile.*$/ { tag("dev", 3); next }
2231 /\/share\/help\// || /\/share\/appdata\// ||
2232 /\/share\/metainfo\// || /\/share\/application-registry\// ||
2233 /\/share\/mime-info\// || /\/share\/gnome\/help\// || /\/share\/omf\// {
2234 tag("gnm", 6); next }
2235 { tag("???", 1) }
2236 ' "$orphans" > $table
2238 # Summary table
2239 orphans_types='()'
2240 for i in head body; do
2241 case $i in
2242 head) echo -n '<table class="summary"><tr>';;
2243 body) echo -n '<th> </th></tr><tr>';;
2244 esac
2245 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
2246 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
2247 case $i in
2248 head) echo -n "<th class='$class'>$tag</th>";;
2249 body)
2250 tagscount="$(grep ">$tag<" $table | wc -l)"
2251 printf '<td>%s</td>' "$tagscount"
2252 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
2253 ;;
2254 esac
2255 done
2256 done
2257 echo '<td> </td></tr></table>'
2258 orphans_types="${orphans_types/( /(}"
2259 [ "$orphans_types" != '()' ] &&
2260 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
2262 suffix=''; [ -n "$set" ] && suffix="-$set"
2263 echo -n ' <pre class="files">'
2264 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2265 IFS=$'\n'
2266 while read orphan_line; do
2267 echo -n "${orphan_line/span> */span>} "
2268 cd $install
2269 ls -ldp --color=always ".${orphan_line#*</span> }" \
2270 | syntax_highlighter files \
2271 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
2272 | awk 'BEGIN { FS="\""; }
2273 { gsub("+", "%2B", $2); print; }'
2274 done < $table
2275 unset IFS
2276 echo '</pre>'
2277 echo '</section>'
2278 rm $table
2279 fi
2280 rm $orphans
2281 # ------------------------------------------------------
2282 # /Unpackaged files
2283 # ------------------------------------------------------
2285 rm $all_files $packaged
2286 ;;
2287 esac
2288 done # /set
2290 case "$part" in
2291 head)
2292 [ -n "$splitsets" ] && echo "</ul>"
2293 echo "</section>"
2294 ;;
2295 esac
2296 done # /part
2298 ;;
2300 description)
2301 page_header
2302 pkg_info
2303 descs="$(ls $WOK/$pkg/description*.txt)"
2304 if [ -n "$descs" ]; then
2305 echo '<div id="content2">'
2306 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
2307 for i in $descs; do
2308 case $i in
2309 */description.txt) continue ;;
2310 *) package=$(echo $i | cut -d. -f2) ;;
2311 esac
2312 show_desc "$package" "$i"
2313 done
2314 echo '</div>'
2315 else
2316 show_note w "No description of $pkg"
2317 fi
2318 ;;
2320 log)
2321 page_header
2322 pkg_info
2323 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
2325 echo '<div class="btnList">'
2326 acc='l' # access key for the latest log is 'L'
2327 while read log; do
2328 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
2329 timestamp=$(stat -c %Y $log)
2330 class=''
2331 if [ "$arg" == "$timestamp" ]; then
2332 class=' log'
2333 logfile="$log"
2334 fi
2335 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
2336 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
2337 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
2338 case $acc in
2339 l) acc=0;;
2340 *) acc=$((acc+1));;
2341 esac
2342 done <<EOT
2343 $(find $LOGS -name "$pkg.log*" | sort)
2344 $(find $LOGS -name "$pkg-pack.log")
2345 EOT
2346 echo '</div>'
2348 if [ -z "$logfile" ]; then
2349 show_note e "Requested log is absent"
2350 page_footer
2351 exit 0
2352 fi
2354 # Define cook variables for syntax highlighter
2355 if [ -s "$WOK/$pkg/receipt" ]; then
2356 . "$WOK/$pkg/receipt"
2357 _wok='/home/slitaz/wok'
2358 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
2359 _install="$_wok/$pkg/install"
2360 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
2361 _stuff="$_wok/$pkg/stuff"
2362 fi
2364 # if [ ! -f "gzlog/$pkg.$arg" ]; then
2365 # {
2366 # summary "$logfile" links
2368 # syntax_highlighter log < $logfile | awk '
2369 # BEGIN { print "<pre class=\"log\">"; }
2370 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
2371 # END { print "</pre>"; }
2372 # '
2374 # page_footer
2375 # } | gzip > gzlog/$pkg.$arg
2376 # fi
2378 blog=$(basename $logfile)
2379 summary "$logfile" links
2381 # disable next `sed` for the 'like2016' theme
2382 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
2383 cat $logfile | syntax_highlighter log | \
2384 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1' alt=''> \1|" | \
2385 awk '
2386 BEGIN { print "<pre class=\"log\">"; }
2387 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
2388 END { print "</pre>"; }
2390 ;;
2393 man|doc|info)
2394 page_header
2395 pkg_info
2396 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
2398 dir="wok/$pkg/install/usr/share/$cmd/"; dir2=''
2399 if [ "$cmd" == 'doc' ]; then
2400 dir2="wok/$pkg/install/usr/share/gtk-doc/"
2401 subdirs="$(ls -p $dir | sed '/\/$/!d')"
2402 [ $(echo "$subdirs" | wc -l) -eq 1 ] && dir="$dir$subdirs"
2403 if [ -z "$arg" ]; then
2404 try=$(for i in $dir $dir2; do find $i -name 'index.htm*'; done | sed q)
2405 [ -n "$try" ] && arg="$try"
2406 fi
2407 fi
2409 while read i; do
2410 [ -s "$i" ] || continue
2411 case "$i" in
2412 *.jp*g|*.png|*.gif|*.svg|*.css) continue
2413 esac
2414 i=${i#$dir}; i=${i#$dir2}
2415 [ -n "$arg" ] || arg="$i"
2416 class=''; [ "$arg" == "$i" ] && class=" doc"
2417 case "$cmd" in
2418 man)
2419 case $i in
2420 man*) lang='';;
2421 *) lang="${i%%/*}: ";;
2422 esac
2423 man=$(basename $i .gz)
2424 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
2425 ;;
2426 doc)
2427 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$i</a>"
2428 ;;
2429 info)
2430 info=$(basename $i)
2431 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
2432 ;;
2433 esac
2434 done <<EOT
2435 $(for i in $dir $dir2; do find $i -type f; done | sort)
2436 EOT
2437 echo '</div>'
2439 [ -f "$arg" ] || arg="$dir/$arg"
2440 if [ -f "$arg" ]; then
2441 tmp="$(mktemp)"
2442 docat "$arg" > $tmp
2443 [ -s "$tmp" ] &&
2444 case "$cmd" in
2445 info)
2446 echo '<div id="content2" class="texinfo"><pre class="first">'
2447 info2html < "$tmp"
2448 echo '</pre></div>'
2449 ;;
2450 doc)
2451 case "$arg" in
2452 *.sgml|*.devhelp2) class='xml';;
2453 *.py) class='python';; # pycurl package
2454 *.css) class='css';;
2455 *.sh) class='bash';;
2456 *.rb|*/Rakefile*|*/Gemfile*) class='ruby';;
2457 *.rdoc) class='asciidoc';;
2458 *)
2459 first=$(head -n1 "$tmp")
2460 if [ "${first:0:1}" == '#' ]; then
2461 class='bash' # first line begins with '#'
2462 else
2463 class='asciidoc'
2464 fi;;
2465 esac
2466 case "$arg" in
2467 *.htm*)
2468 case $arg in
2469 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
2470 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
2471 esac
2472 # make the iframe height so long to contain its contents without scrollbar
2473 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
2474 ;;
2475 *.pdf)
2476 case $arg in
2477 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
2478 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
2479 esac
2480 cat <<-EOT
2481 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
2482 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
2483 </object>
2484 EOT
2485 ;;
2486 *.md|*.markdown)
2487 echo '<section class="markdown">'
2488 case "$md2html" in
2489 *sundown)
2490 $md2html "$tmp" | sed 's|class="|class="language-|g'
2491 ;;
2492 *)
2493 $md2html "$tmp"
2494 ;;
2495 esac
2496 echo '</section>'
2497 ;;
2498 *)
2499 show_code $class < "$tmp"
2500 ;;
2501 esac
2502 ;;
2503 man)
2504 #export TEXTDOMAIN='man2html'
2505 echo "<div id='content2'>"
2507 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
2508 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
2509 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
2511 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
2512 # Process the pre-formatted man-cat page
2513 # (for example see sudo package without groff in build dependencies)
2514 sed -i '
2515 s|M-bM-^@M-^S|—|g;
2516 s|M-bM-^@M-^\\|<b>|g;
2517 s|M-bM-^@M-^]|</b>|g
2518 s|M-bM-^@M-^X|<u>|g;
2519 s|M-bM-^@M-^Y|</u>|g;
2520 s|M-BM-||g;
2521 s|++oo|•|g;
2522 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
2523 ' "$tmp"
2524 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z \
2525 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
2526 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
2527 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
2528 done
2529 echo '<pre class="catman">'
2530 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
2531 echo '</pre>'
2532 else
2533 echo "$html"
2534 fi
2535 echo "</div>"
2536 ;;
2537 esac
2538 rm -f $tmp
2539 else
2540 show_note e "File “$arg” does not exist!"
2541 fi
2542 ;;
2544 download)
2545 page_header
2546 pkg_info
2547 show=0
2549 . $wok/$pkg/receipt
2551 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
2552 files_header
2553 echo "<tr><td><a href='$base/src/$TARBALL' class='icon tarball'>$TARBALL</a></td>"
2554 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
2555 echo "<td>Sources for building the package “$pkg”</td></tr>"
2556 show=1
2557 fi
2559 tmp_table=$(mktemp)
2560 save_ARCH="$ARCH"
2562 for ARCH in i486 x86_64; do
2563 . $wok/$pkg/receipt
2564 for i in $(all_names | tr ' ' '\n'); do
2565 awk -F$'\t' -vpkg="$i" -vbase="$base" -vPKGS="$PKGS" '{
2566 if ($1 == pkg) {
2567 class = ($11 == "0") ? "any" : ($11 == "6") ? "64" : "32";
2568 arch = ($11 == "0") ? "any" : ($11 == "6") ? "x86_64" : "i486";
2569 file = $1 "-" $2 "-" arch ".tazpkg";
2570 desc = $4;
2571 "ls -lh " PKGS "/" file | getline; split($0, ls, " ");
2572 printf("<tr><td><a href=\"%s/get/%s\" ", base, file);
2573 printf("class=\"icon pkg%s\">%s</a></td>", class, file);
2574 printf("<td>%sB</td><td>%s</td></tr>\n", ls[5], desc);
2576 }' $PKGS/packages-$ARCH.info
2577 done
2578 done \
2579 | sort -u \
2580 > $tmp_table
2582 if [ -s "$tmp_table" ]; then
2583 [ "$show" -eq 0 ] && files_header
2584 cat $tmp_table
2585 show=1
2586 fi
2588 if [ "$show" -eq 1 ]; then
2589 echo '</tbody></table></section>'
2590 else
2591 show_note w "Sorry, there's nothing to download…"
2592 fi
2594 ARCH="$save_ARCH"
2595 rm $tmp_table
2596 ;;
2598 esac
2601 page_footer
2602 exit 0