cookutils view lighttpd/index.cgi @ rev 1089

lighttpd/index.cgi: [ For maintainers ]: you can use regexp now to list packages
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Aug 25 17:30:05 2018 +0300 (2018-08-25)
parents 461c3da71257
children 77291d41f21a
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 ~) pretitle="Tag \"$cmd\" - ";;
99 *) pretitle="$pkg - ";;
100 esac
101 else
102 command="$(cat $command)"
103 [ -n "$command" ] && pretitle="$command - "
104 fi
105 [ -z "$favicon" ] && favicon='/slitaz-cooker.png'
107 echo -e 'Content-Type: text/html; charset=UTF-8\n'
109 cat <<EOT
110 <!DOCTYPE html>
111 <html lang="en">
112 <head>
113 <title>$pretitle$title</title>
114 <link rel="stylesheet" href="/$css">
115 <link rel="icon" type="image/png" href="$favicon">
116 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
117 <!-- mobile -->
118 <meta name="viewport" content="width=device-width, initial-scale=1.0">
119 <meta name="theme-color" content="#222">
120 <!-- rss -->
121 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
122 <script>
123 // Get part of the main page
124 function getPart(part) {
125 var partRequest = new XMLHttpRequest();
126 partRequest.onreadystatechange = function() {
127 if (this.readyState == 4 && this.status == 200) {
128 response = this.responseText;
129 var partElement = document.getElementById(part);
130 if (response !== null) partElement.innerHTML = response;
131 }
132 };
133 partRequest.open('GET', '?part=' + part, true);
134 partRequest.responseType = '';
135 partRequest.send();
136 }
137 </script>
138 </head>
139 <body>
140 <div id="container">
141 <header>
142 <h1><a href="$base/">$title</a></h1>
143 <div class="network">
144 <a href="http://www.slitaz.org/">Home</a>
145 <a href="http://bugs.slitaz.org/">Bugs</a>
146 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
147 <a href="http://roadmap.slitaz.org/">Roadmap</a>
148 <a href="http://pizza.slitaz.me/">Pizza</a>
149 <a href="http://tank.slitaz.org/">Tank</a>
150 |
151 <a href="/cross/">Cross</a>
152 <a href="/i486.cgi">i486</a>
153 <a href="$base/cookiso.cgi">ISO</a>
154 <select onChange="window.location.href=this.value" style="display: none">
155 <option value=".">Go to…</option>
156 <option value="http://www.slitaz.org/">Home</option>
157 <option value="http://bugs.slitaz.org/">Bug tracker</option>
158 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
159 <option value="http://roadmap.slitaz.org/">Roadmap</option>
160 <option value="http://pizza.slitaz.me/">Pizza</option>
161 <option value="http://tank.slitaz.org/">Tank</option>
162 <option disabled>---------</option>
163 <option value="cross/">Cross</option>
164 <option value="i486.cgi">i486</option>
165 <option value="cookiso.cgi">ISO</option>
166 </select>
167 </div>
168 </header>
170 <main>
171 EOT
173 [ -n "$debug" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
174 }
177 # HTML page footer
179 page_footer() {
180 date_now=$(date +%s)
181 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
182 wait_sec=$(( 60 - $sec_now ))
183 cat <<EOT
184 </main>
186 <footer>
187 <a href="http://www.slitaz.org/">SliTaz Website</a>
188 <a href="http://tank.slitaz.org/graphs.php">Server status</a>
189 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
190 <a href="$base/?theme">Theme</a>
191 </footer>
192 </div>
193 <script src="/cooker.js"></script>
194 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
195 </body>
196 </html>
197 EOT
198 }
201 show_note() {
202 echo "<div class='bigicon-$1'>$2</div>"
203 }
206 not_found() {
207 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
208 echo "HTTP/1.1 404 Not Found"
209 page_header
210 echo "<h2>Not Found</h2>"
211 case $2 in
212 pkg)
213 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
214 *)
215 show_note e "The requested file “$file” was not found." ;;
216 esac
217 page_footer
218 }
221 manage_modified() {
222 local file="$1" option="$2" nul day mon year time hh mm ss date_s
223 if [ ! -f "$file" ]; then
224 if [ "$option" == 'silently-absent' ]; then
225 echo "HTTP/1.1 404 Not Found"
226 return
227 else
228 not_found "$file" "$2"
229 exit
230 fi
231 fi
232 [ "$option" == 'no-last-modified' ] && return
233 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
234 echo "$HTTP_IF_MODIFIED_SINCE" | \
235 while read nul day mon year time nul; do
236 case $mon in
237 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
238 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
239 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
240 esac
241 hh=$(echo $time | cut -d: -f1)
242 mm=$(echo $time | cut -d: -f2)
243 ss=$(echo $time | cut -d: -f3)
244 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
245 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
246 # echo -e 'HTTP/1.1 304 Not Modified\n'
247 # exit
248 # fi
249 # TODO: improve caching control
250 done
251 fi
252 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
253 echo "Cache-Control: public, max-age=3600"
254 }
257 # Proxy to the Repology
258 # Problems:
259 # 1. Function "latest packaged version" widely used here and it has no JSON API, but only SVG badge.
260 # 2. So, all version comparisons can be only visual and not automated.
261 # 3. Of the thousands of badges present on the web page, many of them are broken (maybe server
262 # drops requests), while our server displays status icons well.
263 # 4. Default badges are wide and not customizable.
264 # Solution:
265 # 1. Make local cache. Update it on demand, but no more than once a day (Repology caches info
266 # on a hourly basis). Use cached values when they are not expired.
267 # 2. Extract and save version(s) from the SVG badges. Values can be compared in the scripts as well
268 # as custom badges that may also be provided.
270 repology_get() {
271 local found versions day=$(date +%j) # %j is the number of the day in the year
272 found=$(awk -F$'\t' -vpkg="$1" -vday="$day" '{
273 if ($1 == pkg && $2 == day) { print $3; exit; }
274 }' $repologydb)
275 if [ -n "$found" ]; then
276 echo "$found"
277 else
278 # set HOST_WGET in cook.conf
279 versions=$($HOST_WGET -q -T 20 -O- https://repology.org/badge/latest-versions/$1.svg \
280 | sed '/<text /!d; /fill/d; /latest/d; s|.*>\(.*\)<.*|\1|; s|, | |g') # space separated list
281 if [ -n "$versions" ]; then
282 sed -i "/^$1 /d" $repologydb
283 echo -e "$1\t$day\t$versions" >> $repologydb
284 echo $versions
285 fi
286 fi
287 }
290 # Query '?pct=<package>': update percentage
292 if [ -n "$(GET pct)" ]; then
293 pkg="$(GET pct)"
294 state="$(cat $command)"
295 if [ "$state" == "cook:$pkg" ]; then
296 set -- $(grep "^$state" $cooktime)
297 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
298 echo "${pct:-?}"
299 else
300 echo 'reload'
301 fi
302 exit 0
303 fi
306 # Query '?poke': poke cooker
308 if [ -n "$(GET poke)" ]; then
309 touch $CACHE/cooker-request
310 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
311 exit
312 fi
315 # Query '?recook=<package>': query to recook package
317 if [ -n "$(GET recook)" ]; then
318 pkg="$(GET recook)"
319 case "$HTTP_USER_AGENT" in
320 *SliTaz*)
321 grep -qs "^$pkg$" $CACHE/recook-packages ||
322 echo "$pkg" >> $CACHE/recook-packages
323 esac
324 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
325 exit
326 fi
329 # Query '/i/<log>/<pkg>': show indicator icon
330 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
332 if [ "$pkg" == 'i' ]; then
333 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
334 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
335 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
336 else
337 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
338 fi
339 exit
340 fi
343 # Query '/s/<pkg>': show status indicator icon
344 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
346 if [ "$pkg" == 's' ]; then
347 # argument <pkg> is in $cmd variable
348 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
349 # packages.info updates with each new package, so we'll find actual info here
350 if grep -q "^$cmd"$'\t' $PKGS/packages.info; then
351 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
352 else
353 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
354 fi
355 exit
356 fi
359 # Query '?theme[=<theme>]': change UI theme
361 if [ -n "$(GET theme)" ]; then
362 theme="$(GET theme)"
363 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
364 case $theme in
365 theme)
366 current=$(COOKIE theme)
367 page_header
368 cat <<EOT
369 <section>
370 <h2>Change theme</h2>
371 <p>Current theme: “${current:-default}”. Select other:</p>
372 <ul>
373 $(
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 )
378 </ul>
379 </section>
380 EOT
381 page_footer
382 exit 0
383 ;;
384 default|emerald|sky|goldenrod|midnight|like2016|terminal)
385 ref="$(GET ref)"
386 [ -n "$ref" ] || ref="$base/"
387 # Expires in a year
388 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
389 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
390 exit 0
391 ;;
392 esac
393 fi
396 #case "$QUERY_STRING" in
397 # stuff*)
398 # file="$wok/$(GET stuff)"
399 # manage_modified "$file"
400 # ;;
401 #
402 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
403 # type=${QUERY_STRING%%=*}
404 # pkg=$(GET $type)
405 # case "$type" in
406 # description)
407 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
408 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
409 # ;;
410 # log)
411 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
412 # manage_modified "$LOGS/$pkg"
413 # ;;
414 # *)
415 # manage_modified "$wok/$pkg/receipt" pkg
416 # ;;
417 # esac
418 # ;;
419 #esac
422 # RSS feed generator
423 # URI: ?rss[&limit={1..100}]
425 if [ -n "$(GET rss)" ]; then
426 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
427 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
428 cooker_url="http://$HTTP_HOST$base/"
429 cat <<EOT
430 Content-Type: application/rss+xml
432 <?xml version="1.0" encoding="utf-8" ?>
433 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
434 <channel>
435 <title>$title</title>
436 <description>The SliTaz packages cooker feed</description>
437 <link>$cooker_url</link>
438 <lastBuildDate>$pubdate</lastBuildDate>
439 <pubDate>$pubdate</pubDate>
440 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
441 EOT
442 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
443 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $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|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
517 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
518 -e '/^File: / s|(dir)|Top|g' \
519 -e '/^File: / s|Next: \([^,]*\)|<a class="button icon next" href="#\1">Next: \1</a>|' \
520 -e '/^File: / s|Prev: \([^,]*\)|<a class="button icon prev" href="#\1">Prev: \1</a>|' \
521 -e '/^File: / s|Up: \([^,]*\)|<a class="button icon up" href="#\1">Up: \1</a>|' \
522 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
523 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
524 -e '/^Tag Table:$/,/^End Tag Table$/d' \
525 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
526 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
527 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
528 -e 's|^\* Menu:|<b>Menu:</b>|' \
529 -e "s|^|</pre>|"
530 }
533 # Put some colors into log and DB files.
535 syntax_highlighter() {
536 case $1 in
537 log)
538 # If variables not defined - define them with some rare values
539 : ${_src=#_#_#}
540 : ${_install=#_#_#}
541 : ${_fs=#_#_#}
542 : ${_stuff=#_#_#}
543 # Use one-letter html tags to save some bytes :)
544 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informative (green)</i>
545 sed \
546 -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
547 -e 's#OK$#<i>OK</i>#' \
548 -e 's#\([Dd]one\)$#<i>\1</i>#' \
549 -e 's#Success$#<i>Success</i>#' \
550 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
551 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
552 -e 's#: \(YES.*\)#: <i>\1</i>#' \
553 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
554 -e 's#\(enabled\)$#<i>\1</i>#' \
555 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
556 -e 's#: \(NO.*\)#: <u>\1</u>#' \
557 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
558 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
559 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
560 -e 's#\(disabled\)$#<u>\1</u>#' \
561 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
562 \
563 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
564 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
565 -e 's# y$# <i>y</i>#' \
566 -e 's# n$# <u>n</u>#' \
567 -e 's#(NEW) *$#<b>(NEW)</b>#' \
568 \
569 -e 's#.*(pkg/local).*#<i>\0</i>#' \
570 -e 's#.*(web/cache).*#<u>\0</u>#' \
571 \
572 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
573 -e 's#ERROR:#<b>ERROR:</b>#g' \
574 \
575 -e 's#^.*multiple definition of.*#<b>\0</b>#' \
576 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
577 -e 's#^.*[^A-Za-z:/-][Ff]atal.*#<b>\0</b>#' \
578 -e '/non-fatal/ s|</*b>||g' \
579 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
580 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
581 -e 's#^.*No package .* found.*#<b>\0</b>#' \
582 -e 's#^.*Unable to find.*#<b>\0</b>#' \
583 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
584 -e 's#Segmentation fault#<b>\1</b>#' \
585 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
586 -e 's#\(found\.*\)$#<i>\1</i>#' \
587 \
588 -e 's#^.*WARNING:.*#<u>\0</u>#' \
589 -e 's#^.*warning:.*#<u>\0</u>#' \
590 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
591 -e 's#^.*terminated.*#<b>\0</b>#' \
592 -e 's#\(missing\)#<b>\1</b>#g' \
593 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
594 -e 's#^.*unrecognized option.*#<u>\0</u>#' \
595 -e 's#^.*does not.*#<u>\0</u>#' \
596 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
597 -e 's#^.*note:.*#<u>\0</u>#' \
598 \
599 -e 's#^.* will not .*#<u>\0</u>#' \
600 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
601 -e 's#^.* Warning: .*#<u>\0</u>#' \
602 \
603 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
604 -e "s#^Making.*#<em>\0</em>#" \
605 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
606 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
607 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
608 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
609 -e 's|^Switching to the .*|<span class="switch">‣‣‣ \0</span>|' \
610 \
611 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
612 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
613 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
614 -e 's|^<u><b>\(.*inlining failed.*\)</b></u>|<u>\1</u>|' \
615 \
616 -e "s|$_src|<var>\${src}</var>|g;
617 s|$_install|<var>\${install}</var>|g;
618 s|$_fs|<var>\${fs}</var>|g;
619 s|$_stuff|<var>\${stuff}</var>|g" \
620 \
621 -e "s|\[\([01]\)m\[3\([1-7]\)m|<span class='c\2\1'>|g;
622 s|\[\([01]\);3\([1-7]\)m|<span class='c\2\1'>|g;
623 s|\[3\([1-7]\)m|<span class='c\10'>|g;
624 s|\[\([01]\);0m|<span class='c0\1'>|g;
625 s|\[0m|</span>|g;
626 s|\[m|</span>|g;
627 s|\[0;10m|</span>|g;
628 s|\[K||g;" \
629 \
630 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
631 s|\[39m|</span>|;
632 #s|\[1m|<span class='c01'>|g;
633 s|\[1m|<span style='font-weight:bold'>|g; s|(B|</span>|g;
634 s|\[m||g;
635 " \
636 -e "s!^|\(+.*\)!|<span class='c20'>\1</span>!;
637 s!^|\(-.*\)!|<span class='c10'>\1</span>!;
638 s!^|\(@@.*@@\)\$!|<span class='c30'>\1</span>!;"
639 \
641 ;;
643 files)
644 # Highlight the Busybox's `ls` output
645 awk '{
646 part1 = substr($0, 0, 16);
647 part2 = substr($0, 17, 9);
648 part3 = substr($0, 26, 9);
649 part4 = substr($0, 35);
650 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
651 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
652 print part1 part2 part3 part4;
653 }' | \
654 sed "s|\[0m/|/\[0m|g;
655 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
656 s|\[\([01]\);0m|<a class='c0\1'>|g;
657 s|\[0m|</a>|g;
658 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
659 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
660 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
661 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
662 s|^\(-rwsr-xr-x\)|<span class='c51'>\1</span>|;
663 s|^\([lrwxs-][lrwxs-]*\)|<span class='c11'>\1</span>|;
664 "
665 ;;
666 esac
667 }
670 show_code() {
671 echo -n "<pre><code class=\"language-$1\">"
672 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
673 echo '</code></pre>'
674 }
677 datalist() {
678 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
679 BEGIN{printf("<datalist id=\"packages\">")}
680 {printf("<option>%s",$1)}
681 END {printf("</datalist>")}
682 '
683 }
686 mklog() {
687 awk '
688 BEGIN { printf("<pre class=\"log dog\">\n") }
689 { print }
690 END { print "</pre>" }'
691 }
694 summary() {
695 log="$1"
696 pkg="$(basename ${log%%.log*})"
698 if [ -f "$log" ]; then
699 if grep -q "cook:$pkg$" $command; then
700 show_note i "The Cooker is currently building $pkg"
701 elif fgrep -q "Summary for:" $log; then
702 sed '/^Summary for:/,$!d' $log | awk '
703 BEGIN { print "<section>" }
704 function row(line) {
705 split(line, s, " : ");
706 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
707 }
708 function row2(line, rowNum) {
709 split(line, s, " : ");
710 if (rowNum == 1) {
711 print "<thead>";
712 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]);
713 print "</thead><tbody>";
714 }
715 else
716 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]);
717 }
718 {
719 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
720 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
721 if ($0 ~ "---") {
722 seen2++;
723 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
724 next
725 }
726 if (seen2) row2($0, seen2); else row($0);
727 }
728 END { print "</tbody></table></section>" }
729 '
730 elif fgrep -q "Debug information" $log; then
731 echo -e '<section>\n<h3>Debug information</h3>'
732 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
733 if [ -n "$2" ]; then
734 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
735 else
736 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
737 fi | mklog
738 echo '</section>'
739 fi
740 else
741 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
742 fi
743 }
746 active() {
747 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
748 }
751 pkg_info() {
752 local log active bpkg short_desc=''
753 log="$LOGS/$pkg.log"
755 echo -n "<div id=\"hdr\"><a href=\"$base/${requested_pkg:-$pkg}\">"
756 if [ -e $wok/$pkg/.icon.png ]; then
757 echo -n "<img src=\"$base/$pkg/browse/.icon.png\"/>"
758 else
759 echo -n "<img src=\"/tazpkg.png\"/>"
760 fi
761 echo -n "</a>"
762 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
763 # Get short description for existing packages
764 [ -f $PKGS/packages.info ] &&
765 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
766 # If package does not exist (not created yet or broken), get short description
767 # (but only for "main" package) from receipt
768 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
769 echo "<br/>$short_desc</h2></div>"
770 echo '<div id="info">'
771 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
773 # In the receipts $EXTRAVERSION is defined using $kvers, get it here [copy from 'cook' set_paths()]
774 if [ -f "$wok/linux/receipt" ]; then
775 kvers=$(. $wok/linux/receipt; echo $VERSION)
776 kbasevers=$(echo $kvers | cut -d. -f1,2)
777 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
778 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
779 kbasevers=$(echo $kvers | cut -d. -f1,2)
780 fi
782 unset WEB_SITE WANTED
783 . $wok/$pkg/receipt
785 [ -n "$WEB_SITE" ] &&
786 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
788 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/receipt" ] &&
789 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
791 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
792 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
794 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
795 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
797 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
799 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
800 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
802 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
803 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
805 [ -d "$wok/$pkg/install/usr/share/info" ] &&
806 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
808 if [ -n "$LFS" ]; then
809 printf "<a class='button icon doc' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
810 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
811 printf "LFS</a>\n"
812 fi
814 ls $log* >/dev/null 2>&1 &&
815 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
817 echo '</div>'
818 }
821 mktable() {
822 sed 's# : #|#' | awk -vc="$1" '
823 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
824 { printf("<tr><td>%s</td>", $1);
825 if (NF == 2) printf("<td>%s</td>", $2);
826 printf("</tr>\n", $2) }
827 END { print "</table>" }'
828 }
831 section() {
832 local i=$(basename "$1")
833 echo -e '\n\n<section>'
834 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
835 echo "<h2>${3%|*}</h2>"
836 mktable "$i"
837 echo '</section>'
838 }
841 show_desc() {
842 echo "<section><h3>Description of “$1”</h3>"
843 if [ -n "$md2html" ]; then
844 $md2html $2
845 else
846 show_code markdown < $2
847 fi
848 echo "</section>"
849 }
852 # Return all the names of packages bundled in this receipt
854 all_names() {
855 # Get package names from $SPLIT variable
856 local split=$(echo $SPLIT \
857 | awk '
858 BEGIN { RS = " "; FS = ":"; }
859 { print $1; }' \
860 | tr '\n' ' ')
861 local split_space=" $split "
862 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
863 # For receipts v1: $SPLIT may present in the $WANTED package,
864 # but split packages have their own receipts
865 echo $PACKAGE
866 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
867 # $PACKAGE included somewhere in $SPLIT (probably in the end).
868 # We should build packages in the order defined in the $SPLIT.
869 echo $split
870 else
871 # We'll build the $PACKAGE, then all defined in the $SPLIT.
872 echo $PACKAGE $split
873 fi
874 }
877 toolchain_version() {
878 echo "<tr><td><a href='$base/$1'>$1</a></td>"
879 awk -F$'\t' -vpkg="$1" '
880 BEGIN { version = description = "---"; }
881 {
882 if ($1 == pkg) { version = $2; description = $4; }
883 }
884 END { printf("<td>%s</td><td>%s</td></tr>", version, description); }
885 ' $PKGS/packages.info
886 }
889 files_header() {
890 echo '<section><h3>Available downloads:</h3>'
891 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
892 }
895 # Update statistics used in web interface.
896 # There is no need to recalculate the statistics every time the page is displayed.
897 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
899 update_webstat() {
900 # for receipts:
901 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
902 rcooked=$(ls -d $WOK/*/taz | wc -l)
903 runbuilt=$(($rtotal - $rcooked))
904 rblocked=$(wc -l < $blocked)
905 rbroken=$(wc -l < $broken)
907 # for packages:
908 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
909 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
910 punbuilt=$(($ptotal - $pcooked))
911 pblocked=$(
912 while read i; do
913 sed "/^$i\t/!d" $CACHE/split.db
914 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
915 pbroken=$(
916 while read i; do
917 sed "/^$i\t/!d" $CACHE/split.db
918 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
920 cat > $webstat <<EOT
921 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
922 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
923 EOT
924 }
927 # Generate part of the main page
929 part() {
930 echo -n "<div id='$1'>"
932 case $1 in
933 summary)
934 echo '<h2>Summary</h2>'
936 mktable <<EOT
937 Cooker state : $(running_command)
938 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
939 Commits to cook : $(wc -l < $commits)
940 Current cooklist : $(wc -l < $cooklist)
941 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
942 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
943 EOT
945 # If command is "cook:*", update gauge and percentage periodically.
946 # If different package is cooking, reload the page (with new settings)
947 cmd="$(cat $command)"
948 case "$cmd" in
949 cook:*)
950 pkg=${cmd#*:}
951 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
952 ;;
953 esac
954 ;;
955 webstat)
956 # Do we need to update the statistics?
957 if [ -n "$nojs" -a "$activity" -nt "$webstat" ]; then update_webstat; fi
958 . $webstat
960 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
962 cat <<EOT
963 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
965 <table class="webstat"><thead>
966 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
967 </thead><tbody>
968 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
969 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
970 </tbody></table>
971 EOT
972 if [ -z "$nojs" ]; then echo "<script>getPart('$1')</script>"; fi
973 ;;
974 activity)
975 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
976 s|\[ Done|<span class="r c20">Done|;
977 s|\[ Failed|<span class="r c10">Failed|;
978 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
979 s| \]|</span>|;
980 s|%2B|\+|g' | \
981 section $activity 12 "Activity|More activity"
982 ;;
983 cooknotes)
984 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
985 section $cooknotes 12 "Cooknotes|More notes"
986 ;;
987 commits)
988 [ -s "$commits" ] && head -n20 $commits | \
989 section $commits 20 "Commits|More commits"
990 ;;
991 cooklist)
992 [ -s "$cooklist" ] && head -n 20 $cooklist | \
993 section $cooklist 20 "Cooklist|Full cooklist"
994 ;;
995 broken)
996 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
997 section $broken 20 "Broken|All broken packages"
998 ;;
999 blocked)
1000 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
1001 section $blocked 12 "Blocked|All blocked packages"
1002 ;;
1003 pkgs)
1004 cd $PKGS
1005 # About BusyBox's `ls`
1006 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
1007 # It supported the option `-e`, output with `-let` options like this:
1008 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
1009 # 1 2 3 4 5 6 7 8 9 10 11
1010 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
1011 # configure it or return the option back. It supported the long option
1012 # `--full-time` instead, but output is different:
1013 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
1014 # 1 2 3 4 5 6 7 8 9
1015 if ls -let >/dev/null 2>&1; then
1016 ls -let *.tazpkg \
1017 | awk '
1018 (NR<=20){
1019 sub(/:[0-9][0-9]$/, "", $9);
1020 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
1021 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
1022 }' \
1023 | section $activity 1000 "Latest cook"
1024 else
1025 ls -lt --full-time *.tazpkg \
1026 | awk '
1027 (NR<=20){
1028 sub(/:[0-9][0-9]$/, "", $7);
1029 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
1030 }' \
1031 | section $activity 1000 "Latest cook"
1032 fi
1033 ;;
1034 esac
1035 echo "</div>"
1039 # Query '?part=<part>': get part of the main page
1041 if [ -n "$(GET part)" ]; then
1042 part="$(GET part)"
1043 case $part in
1044 summary|webstat|activity|cooknotes|commits|cooklist|broken|blocked|pkgs)
1045 nojs='yes'
1046 part $part
1047 ;;
1048 esac
1049 exit 0
1050 fi
1056 # Load requested page
1059 if [ -z "$pkg" ]; then
1061 page_header
1062 if [ -n "$QUERY_STRING" ]; then
1064 [ "$QUERY_STRING" != 'commits.log' ] &&
1065 for list in activity cooknotes cooklist commits; do
1066 [ -n "$(GET $list)" ] || continue
1067 case $list in
1068 cooklist) nb="- Packages: $(wc -l < $cooklist)";;
1069 commits) nb="- Packages: $(wc -l < $commits)";;
1070 esac
1071 echo '<section id="content2">'
1072 echo "<h2>DB: $list $nb</h2>"
1073 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
1074 s|\[ Done|<span class="r c20">Done|;
1075 s|\[ Failed|<span class="r c10">Failed|;
1076 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1077 s| \]|</span>|' | mktable $list
1078 echo '</section>'
1079 done
1081 if [ -n "$(GET broken)" ]; then
1082 echo '<section id="content2">'
1083 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
1084 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
1085 echo '</section>'
1086 fi
1088 case "$QUERY_STRING" in
1089 *.log)
1090 log=$LOGS/$QUERY_STRING
1091 name=$(basename $log)
1092 if [ -f "$log" ]; then
1093 echo "<h2>Log for: ${name%.log}</h2>"
1094 if fgrep -q "Summary" $log; then
1095 echo '<pre class="log">'
1096 grep -A 20 'Summary' $log | syntax_highlighter log
1097 echo '</pre>'
1098 fi
1099 echo '<pre class="log">'
1100 syntax_highlighter log < $log
1101 echo '</pre>'
1102 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
1103 # Display button only for SliTaz web browser
1104 case "$HTTP_USER_AGENT" in
1105 *SliTaz*)
1106 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1107 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
1108 show_note i "The package database has been requested for re-creation"
1109 else
1110 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
1111 fi
1112 fi
1113 ;;
1114 esac
1115 fi
1116 else
1117 show_note e "No log file: $log"
1118 fi
1119 ;;
1120 toolchain)
1121 cat <<EOT
1122 <div id="content2">
1123 <section>
1124 <h2>SliTaz GNU/Linux toolchain</h2>
1126 <table>
1127 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1128 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1129 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
1130 <tr><td>Host system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
1131 <tr><td>Target system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
1132 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
1133 $(toolchain_version slitaz-toolchain)
1134 $(toolchain_version binutils)
1135 $(toolchain_version linux-api-headers)
1136 $(toolchain_version gcc)
1137 $(toolchain_version glibc)
1138 </table>
1140 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
1141 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
1142 </p>
1144 </section>
1145 </div>
1146 EOT
1147 ;;
1148 maintainer*)
1149 maintainer=$(GET maintainer); maintainer=${maintainer/maintainer/}
1150 regexp=$(GET regexp); regexp=${regexp/regexp/}
1151 [ -n "$regexp" ] && maintainer=''
1152 cat <<EOT
1153 <section>
1154 <h2>For maintainers</h2>
1155 <p>Check packages version either for specified maintainer or using regular expression:</p>
1156 <form>
1157 <select name="maintainer">
1158 <option value=''>--- select maintainer ---
1159 EOT
1160 cut -d$'\t' -f1 $maintdb | sort -u \
1161 | awk -vm=$maintainer '{
1162 selected=$0==m?"selected":""
1163 printf("<option %s value=\"%s\">%s\n", selected, $0, $0)
1164 }'
1165 cat <<EOT
1167 </select>
1168 or
1169 <input type="text" name="regexp" value="$regexp"/>
1170 <button type="submit">Go</button>
1171 </form>
1172 EOT
1173 if [ -n "$maintainer" -o -n "$regexp" ]; then
1174 tmp_status=$(mktemp)
1175 cat <<EOT
1176 <table class="maint">
1177 <thead><tr><th>Package</th><th>Version</th><th>Repology</th></tr></thead>
1178 EOT
1180 if [ -n "$maintainer" ]; then
1181 awk -vm=$maintainer '{if ($1 == m) print $2}' $maintdb
1182 fi
1183 if [ -n "$regexp" ]; then
1184 cd $wok; ls | grep "$regexp"
1185 fi
1186 } | while read pkg; do
1187 unset VERSION; REPOLOGY=$pkg
1188 . $wok/$pkg/receipt
1189 ver=$(awk -F$'\t' -vpkg="$pkg" '{if ($1 == pkg) {print $2; exit}}' $PKGS/packages.info)
1190 if [ "$REPOLOGY" == '-' ]; then
1191 unset repo_info1 repo_info2
1192 echo '-' >>$tmp_status
1193 else
1194 repo_ver=$(repology_get $REPOLOGY)
1195 if [ "$repo_ver" == '-' ]; then
1196 echo '-' >>$tmp_status
1197 icon='more'
1198 else
1199 if echo " $repo_ver " | fgrep -q " ${ver:-$VERSION} "; then
1200 icon='actual'
1201 else
1202 icon='update'
1203 fi
1204 echo $icon >>$tmp_status
1205 fi
1206 repo_info1="<a class='icon $icon' href='https://repology.org/metapackage/$REPOLOGY' target='_blank'"
1207 repo_info2="rel='noopener noreferrer' title='latest packaged version(s)'>${repo_ver// /, }</a>"
1208 fi
1209 cat <<EOT
1210 <tr>
1211 <td><img src="$base/s/$pkg"> <a href="$pkg">$pkg</a></td>
1212 <td>${ver:-$VERSION}</td>
1213 <td>$repo_info1 $repo_info2</td>
1214 </tr>
1215 EOT
1216 done
1218 pkg_total=$( wc -l < $tmp_status)
1219 pkg_actual=$( fgrep actual $tmp_status | wc -l)
1220 pkg_outdated=$(fgrep update $tmp_status | wc -l)
1221 pkg_unknown=$( fgrep '-' $tmp_status | wc -l)
1223 pct_actual=$(( $pkg_actual * 100 / $pkg_total ))
1224 pct_outdated=$(( $pkg_outdated * 100 / $pkg_total ))
1225 pct_unknown=$(( $pkg_unknown * 100 / $pkg_total ))
1227 [ "$pkg_actual" -eq 0 ] && pkg_actual=''
1228 [ "$pkg_outdated" -eq 0 ] && pkg_outdated=''
1229 [ "$pkg_unknown" -eq 0 ] && pkg_unknown=''
1231 cat <<EOT
1232 </table>
1234 <div class="meter" style="width:100%;text-align:center"><div
1235 style="display:inline-block;background-color:#090;width:$pct_actual%">$pkg_actual</div><div
1236 style="display:inline-block;background-color:#f90;width:$pct_outdated%">$pkg_outdated</div><div
1237 style="display:inline-block;background-color:#ccc;width:$pct_unknown%">$pkg_unknown</div></div>
1238 EOT
1239 rm $tmp_status
1240 fi
1241 cat <<EOT
1242 </section>
1243 EOT
1244 ;;
1245 esac
1246 page_footer
1247 exit 0
1248 fi
1251 # We may have a toolchain.cgi script for cross cooker's
1252 if [ -f "toolchain.cgi" ]; then
1253 toolchain="toolchain.cgi"
1254 else
1255 toolchain="?toolchain"
1256 fi
1258 # Main page with summary. Count only packages included in ARCH,
1259 # use 'cooker arch-db' to manually create arch.$ARCH files.
1261 cat <<EOT
1262 <div id="content2">
1264 <section>
1265 <form method="get" action="" class="search r">
1266 <input type="hidden" name="search" value="pkg"/>
1267 <button type="submit" title="Search">Search</button>
1268 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
1269 </form>
1270 EOT
1272 unset nojs
1273 part summary
1274 part webstat
1276 cat <<EOT
1277 <p>
1278 Service logs:
1279 <a href="?cookorder.log">cookorder</a> ·
1280 <a href="?commits.log">commits</a> ·
1281 <a href="?pkgdb.log">pkgdb</a>
1282 </p>
1283 EOT
1285 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1286 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1287 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1288 else
1289 show_note i 'Cooker will be launched in the next 5 minutes.'
1290 fi
1291 fi
1293 cat <<EOT
1294 <a class="button icon maintainers" href="?maintainer">For maintainers</a>
1295 </section>
1296 EOT
1298 part activity
1299 part cooknotes
1300 part commits
1301 part cooklist
1302 part broken
1303 part blocked
1304 part pkgs
1306 echo '</div>'
1307 datalist
1308 page_footer
1309 exit 0
1310 fi
1313 # show tag
1315 if [ "$pkg" == '~' -a -n "$cmd" ]; then
1316 tag="$cmd"
1317 page_header
1318 cat <<EOT
1319 <div id="content2">
1320 <section>
1321 <h2>Tag “$tag”</h2>
1323 <table>
1324 <thead>
1325 <tr><th>Name</th><th>Description</th><th>Category</th></tr>
1326 </thead>
1327 <tbody>
1328 EOT
1329 sort $PKGS/packages.info \
1330 | awk -F$'\t' -vtag=" $tag " -vbase="$base" '{
1331 if (index(" " $6 " ", tag)) {
1332 url = base "/" $1 "/";
1333 gsub("+", "%2B", url);
1334 printf("<tr><td><img src=\"%s/s/%s\"> ", base, $1);
1335 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1337 }'
1338 echo '</tbody></table></section></div>'
1339 page_footer
1340 exit 0
1341 fi
1344 case "$cmd" in
1345 '')
1346 page_header
1348 requested_pkg="$pkg"
1349 # Package info.
1350 if [ ! -f "$wok/$pkg/receipt" ]; then
1351 # Let's look at the cases when the package was not found
1353 # Maybe query is the exact name of split package? -> proceed to main package
1354 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1355 if (index(" " $2 " ", pkg)) {print $1; exit}
1356 }' $splitdb)
1358 # No, so let's find any matches among packages names (both main and split)
1359 if [ -z "$mainpkg" ]; then
1360 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1361 # Nothing matched
1362 if [ -z "$pkgs" ]; then
1363 echo "<h2>Not Found</h2>"
1364 show_note e "The requested package <b>$pkg</b> was not found on this server."
1365 page_footer; exit 0
1366 fi
1367 # Search results page
1368 echo "<section><h2>Package names matching “$pkg”</h2>"
1369 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1370 query="$pkg"
1371 for pkg in $pkgs; do
1372 # Find main package
1373 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1374 if (index(" " $2 " ", pkg)) {print $1; exit}
1375 }' $splitdb)
1376 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1378 unset SHORT_DESC CATEGORY
1379 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1380 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1382 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1383 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1384 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1385 done
1386 echo '</tbody></table></section>'
1387 page_footer; exit 0
1388 fi
1389 pkg="$mainpkg"
1390 fi
1392 log=$LOGS/$pkg.log
1393 pkg_info
1395 # Check for a log file and display summary if it exists.
1396 summary "$log"
1399 # Repology badge
1400 [ "$REPOLOGY" == '-' ] || cat <<EOT
1401 <section>
1402 <h3>Repology</h3>
1403 <a href="https://repology.org/metapackage/${REPOLOGY:-$pkg}" target='_blank'
1404 rel='noopener noreferrer' title="latest packaged version(s) by Repology">
1405 <img src="https://repology.org/badge/latest-versions/${REPOLOGY:-$pkg}.svg" alt="latest packaged version(s)">
1406 <img src="https://repology.org/badge/tiny-repos/${REPOLOGY:-$pkg}.svg" alt="Packaging status">
1407 </a>
1408 </section>
1409 EOT
1412 # Show tag list
1413 taglist=$(
1414 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1415 [ -s "$PKGS/packages.info" ] &&
1416 awk -F$'\t' -vpkg="$i" '{
1417 if ($1 == pkg) { print $6; exit; }
1418 }' "$PKGS/packages.info"
1419 done \
1420 | tr ' ' '\n' \
1421 | sort -u
1423 if [ -n "$taglist" ]; then
1424 echo -n '<section><h3>Tags</h3><p>'
1425 lasttag=$(echo "$taglist" | tail -n1)
1426 for tag in $taglist; do
1427 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1428 [ "$tag" != "$lasttag" ] && echo -n " · "
1429 done
1430 echo '</p></section>'
1431 fi
1434 # Informational table with dependencies
1435 pkg="$requested_pkg"
1436 inf="$(mktemp -d)"
1438 # 1/3: Build dependencies (from receipt and pkgdb)
1439 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1440 echo "$i" >> $inf/a
1441 done
1443 # 2/3: Runtime dependencies (from pkgdb)
1445 [ -s "$PKGS/packages.info" ] &&
1446 awk -F$'\t' -vp="$pkg" '{
1447 if ($1 == p) print $8
1448 }' "$PKGS/packages.info"
1449 } | tr ' ' '\n' | sort -u > $inf/b
1451 # 3/3: Required by (from pkgdb)
1453 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1454 [ -s "$PKGS/packages.info" ] &&
1455 awk -F$'\t' -vp=" $i " '{
1456 if (index(" " $8 " ", p)) print $1
1457 }' "$PKGS/packages.info"
1459 [ -s "$PKGS/bdeps.txt" ] &&
1460 awk -F$'\t' -vp=" $i " '{
1461 if (index(" " $2 " ", p)) print $1
1462 }' $PKGS/bdeps.txt
1463 done
1464 } | sort -u > $inf/c
1466 cat <<EOT
1467 <section>
1468 <h3>Related packages</h3>
1469 <table class="third">
1470 <thead>
1471 <tr>
1472 <th>Build dependencies</th>
1473 <th>Runtime dependencies</th>
1474 <th>Required by</th>
1475 </tr>
1476 </thead>
1477 <tbody>
1478 EOT
1480 awk -vinf="$inf" -vbase="$base" '
1481 function linki(i) {
1482 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1484 BEGIN{
1485 do {
1486 a = b = c = "";
1487 getline a < inf "/a";
1488 getline b < inf "/b";
1489 getline c < inf "/c";
1490 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1491 } while ( a b c )
1492 }'
1493 cat <<EOT
1494 </tbody>
1495 </table>
1496 </section>
1497 EOT
1498 # Clean
1499 rm -r $inf
1504 # Display <Recook> button only for SliTaz web browser
1505 case "$HTTP_USER_AGENT" in
1506 *SliTaz*)
1507 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1508 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1509 show_note i "The package “$pkg” has been requested for recook"
1510 else
1511 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1512 fi
1513 fi
1514 ;;
1515 esac
1516 ;;
1518 receipt)
1519 page_header
1520 pkg_info
1521 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1522 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1523 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1525 show_code bash < $wok/$pkg/receipt
1526 ;;
1528 stuff)
1529 page_header
1530 pkg_info
1531 file="$pkg/stuff/$arg"
1532 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1533 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1534 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1535 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1536 }'
1538 if [ -f "$wok/$file" ]; then
1539 case $file in
1540 *.desktop|*.theme) class="ini" ;;
1541 *.patch|*.diff|*.u) class="diff" ;;
1542 *.sh) class="bash" ;;
1543 *.conf*|*.ini)
1544 class="bash"
1545 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1546 ;;
1547 *.pl) class="perl" ;;
1548 *.c|*.h|*.awk) class="clike" ;;
1549 *.svg) class="svg" ;;
1550 *Makefile*) class="makefile" ;;
1551 *.po|*.pot) class="bash" ;;
1552 *.css) class="css" ;;
1553 *.htm|*.html) class="html" ;;
1554 *.js) class="js" ;;
1555 *.txt) class="asciidoc" ;;
1556 *)
1557 case $(head -n1 $wok/$file) in
1558 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1559 esac
1560 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1561 class="bash"
1562 fi
1563 if [ -z "$class" ]; then
1564 # Follow Busybox restrictions. Search for non-printable chars
1565 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1566 raw="true"
1567 fi
1568 fi
1569 ;;
1570 esac
1572 # Display image
1573 case $file in
1574 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1575 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1576 ;;
1577 esac
1579 # Display colored listing for all text-based documents (also for *.svg)
1580 case $file in
1581 *.png|*.jpg|*.jpeg|*.ico) ;;
1582 *)
1583 if [ -z "$raw" ]; then
1584 cat $wok/$file | show_code $class
1585 fi
1586 ;;
1587 esac
1589 # Display hex dump for binary files
1590 if [ -n "$raw" ]; then
1591 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1592 fi
1593 else
1594 show_note e "File “$file” absent!"
1595 fi
1596 ;;
1598 files)
1599 page_header
1600 pkg_info
1602 # find main package
1603 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1604 main=${wanted:-$pkg}
1605 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1607 splitsets=$(echo $SPLIT" " \
1608 | awk '
1609 BEGIN { RS = " "; FS = ":"; }
1610 { print $2; }' \
1611 | sort -u \
1612 | tr '\n' ' ' \
1613 | sed 's|^ *||; s| *$||')
1615 splitpkgs=$(echo $SPLIT" " \
1616 | awk '
1617 BEGIN { RS = " "; FS = ":"; }
1618 { print $1; }' \
1619 | tr '\n' ' ' \
1620 | sed 's|^ *||; s| *$||')
1622 # we need the version
1623 if [ -f "$WOK/linux/receipt" ]; then
1624 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1625 kbasevers=$(echo $kvers | cut -d. -f1,2)
1626 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1627 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1628 kbasevers=$(echo $kvers | cut -d. -f1,2)
1629 fi
1630 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1632 echo "<section><h3>Quick jump:</h3>"
1635 for part in head body; do
1637 for set in '' $splitsets; do
1638 pkgsofset=$(echo $SPLIT" " \
1639 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1640 BEGIN {
1641 RS = " "; FS = ":";
1642 if (!set) print main;
1643 if (!set && dev) print dev;
1646 if ($2 == set) print $1;
1647 }' \
1648 | sort -u)
1650 set_description=''
1651 [ -n "$splitsets" ] &&
1652 case "$set" in
1653 '')
1654 set_description=' (default set)'
1655 set_title='Default set'
1656 ;;
1657 *)
1658 set_description=" (set “$set”)"
1659 set_title="Set “$set”"
1660 ;;
1661 esac
1663 install="$wok/$main/install"
1664 [ -n "$set" ] && install="$install-$set"
1666 case $part in
1667 head)
1668 [ -n "$splitsets" ] &&
1669 case "$set" in
1670 '') echo "<ul><li>Default set:";;
1671 *) echo "<li>Set “$set”:";;
1672 esac
1673 echo -e '\t<ul>'
1674 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1675 cat <<EOT
1676 <li id='li-repeats$set' style='display:none'>
1677 <a href='#repeats$set'>repeatedly packaged files</a></li>
1678 <li id='li-empty$set' style='display:none'>
1679 <a href='#empty$set'>unpackaged empty folders</a></li>
1680 <li id='li-outoftree$set' style='display:none'>
1681 <a href='#outoftree$set'>out-of-tree files</a></li>
1682 <li id='li-orphans$set' style='display:none'>
1683 <a href='#orphans$set'>unpackaged files</a>
1684 <span id='orphansTypes$set'></span></li>
1685 EOT
1686 echo -e '\t</ul>'
1687 [ -n "$splitsets" ] && echo "</li>"
1688 ;;
1689 body)
1690 all_files=$(mktemp)
1691 cd $install; find ! -type d | sed 's|\.||' > $all_files
1693 # ------------------------------------------------------
1694 # Packages content
1695 # ------------------------------------------------------
1696 packaged=$(mktemp)
1697 for p in $pkgsofset; do
1698 namever="$(awk -F$'\t' -vp="$p" '{
1699 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
1700 }' $PKGS/packages.info)"
1701 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1702 indir=$p
1703 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1704 indir=$main
1705 fi
1706 dir="$wok/$indir/taz/$p-$ver/fs"
1708 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1710 echo
1711 echo "<section id='$p'>"
1712 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
1713 echo ' <pre class="files">'
1714 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1715 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1716 cd $dir
1717 find . -print0 \
1718 | sort -z \
1719 | xargs -0 ls -ldp --color=always \
1720 | syntax_highlighter files \
1721 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
1722 | awk 'BEGIN { FS="\""; }
1723 { gsub("+", "%2B", $2); print; }'
1724 else
1725 echo 'No files'
1726 fi
1727 echo '</pre>'
1728 echo '</section>'
1730 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1731 done
1732 # ------------------------------------------------------
1733 # /Packages content
1734 # ------------------------------------------------------
1736 # ------------------------------------------------------
1737 # Repeatedly packaged files
1738 # ------------------------------------------------------
1739 repeats=$(mktemp)
1740 sort $packaged | uniq -d > $repeats
1741 if [ -s "$repeats" ]; then
1742 echo
1743 echo "<script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>"
1744 echo "<section id='repeats$set'>"
1745 echo " <h3>Repeatedly packaged files$set_description:</h3>"
1746 cd $install
1748 IFS=$'\n'
1749 echo -n ' <pre class="files">'
1750 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1751 while read i; do
1752 find .$i -exec ls -ldp --color=always '{}' \; \
1753 | syntax_highlighter files \
1754 | sed 's|>\./|>/|'
1755 done < $repeats
1756 echo '</pre>'
1757 echo '</section>'
1758 unset IFS
1759 fi
1760 rm $repeats
1761 # ------------------------------------------------------
1762 # /Repeatedly packaged files
1763 # ------------------------------------------------------
1765 # ------------------------------------------------------
1766 # Unpackaged empty folders
1767 # ------------------------------------------------------
1768 emptydirs=$(mktemp)
1769 cd $install
1770 IFS=$'\n'
1771 find -type d \
1772 | sed 's|\.||' \
1773 | while read d; do
1774 [ -z "$(ls "$install$d")" ] || continue
1775 # empty dir determined by empty `ls`
1776 echo $d
1777 done \
1778 | while read d; do
1779 notfound='yes'
1780 for p in $(cd $wok/$main/taz; ls); do
1781 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1782 notfound=''
1783 break
1784 fi
1785 done
1786 [ -n "$notfound" ] &&
1787 ls -ldp --color=always .$d \
1788 | syntax_highlighter files \
1789 | sed 's|>\./|>/|'
1790 done > $emptydirs
1791 unset IFS
1792 if [ -s "$emptydirs" ]; then
1793 echo
1794 echo "<script>document.getElementById('li-empty$set').style.display = 'list-item'</script>"
1795 echo "<section id='empty$set'>"
1796 echo " <h3>Unpackaged empty folders$set_description:</h3>"
1797 echo -n ' <pre class="files">'
1798 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1799 cat $emptydirs
1800 echo '</pre>'
1801 echo '</section>'
1802 fi
1803 rm $emptydirs
1804 # ------------------------------------------------------
1805 # /Unpackaged empty folders
1806 # ------------------------------------------------------
1808 # ------------------------------------------------------
1809 # Out-of-tree files
1810 # ------------------------------------------------------
1811 outoftree=$(mktemp)
1812 awk -F$'\n' -vall="$all_files" '
1814 if (FILENAME == all) files_all[$1] = "1";
1815 else files_pkg[$1] = "1";
1817 END {
1818 for (i in files_pkg) {
1819 if (! files_all[i]) print i;
1822 ' "$all_files" "$packaged" > $outoftree
1824 if [ -d "$install" -a -s "$outoftree" ]; then
1825 echo
1826 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
1827 echo "<section id='outoftree$set'>"
1828 echo " <h3>Out-of-tree files$set_description:</h3>"
1829 echo -n ' <pre class="files">'
1830 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1831 IFS=$'\n'
1832 while read outoftree_line; do
1833 # Find the package out-of-tree file belongs to
1834 for i in $pkgsofset; do
1835 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
1836 cd $wok/$main/taz/$i-$ver/fs
1837 ls -ldp --color=always ".$outoftree_line" \
1838 | syntax_highlighter files \
1839 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
1840 | awk 'BEGIN { FS="\""; }
1841 { gsub("+", "%2B", $2); print; }'
1842 fi
1843 done
1844 done < $outoftree
1845 unset IFS
1846 echo '</pre>'
1847 echo '</section>'
1848 fi
1849 rm $outoftree
1850 # ------------------------------------------------------
1851 # /Out-of-tree files
1852 # ------------------------------------------------------
1854 # ------------------------------------------------------
1855 # Unpackaged files
1856 # ------------------------------------------------------
1857 orphans=$(mktemp)
1858 awk -F$'\n' -vall="$all_files" '
1860 if (FILENAME == all) files_all[$1] = "1";
1861 else files_pkg[$1] = "1";
1863 END {
1864 for (i in files_all) {
1865 if (! files_pkg[i]) print i;
1868 ' "$all_files" "$packaged" | sort > $orphans
1869 if [ -d "$install" -a -s "$orphans" ]; then
1870 echo
1871 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
1872 echo "<section id='orphans$set'>"
1873 echo " <h3>Unpackaged files$set_description:</h3>"
1874 table=$(mktemp)
1875 awk '
1876 function tag(text, color) {
1877 printf("<span class=\"c%s1\">%s</span> ", color, text);
1878 printf("%s\n", $0);
1880 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
1881 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
1882 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
1883 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ ||
1884 /\/cache\/.*\.gem$/ {
1885 tag("---", 0); next }
1886 /\.pod$/ { tag("pod", 5); next }
1887 /\/share\/man\// { tag("man", 5); next }
1888 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1889 /\/share\/devhelp\// { tag("doc", 5); next }
1890 /\/share\/icons\// { tag("ico", 2); next }
1891 /\/share\/locale\// { tag("loc", 4); next }
1892 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1893 /\/Makefile.*$/ { tag("dev", 3); next }
1894 /\/share\/help\// || /\/share\/appdata\// ||
1895 /\/share\/metainfo\// { tag("gnm", 6); next }
1896 { tag("???", 1) }
1897 ' "$orphans" > $table
1899 # Summary table
1900 orphans_types='()'
1901 for i in head body; do
1902 case $i in
1903 head) echo -n '<table class="summary"><tr>';;
1904 body) echo -n '<th> </th></tr><tr>';;
1905 esac
1906 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1907 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1908 case $i in
1909 head) echo -n "<th class='$class'>$tag</th>";;
1910 body)
1911 tagscount="$(grep ">$tag<" $table | wc -l)"
1912 printf '<td>%s</td>' "$tagscount"
1913 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1914 ;;
1915 esac
1916 done
1917 done
1918 echo '<td> </td></tr></table>'
1919 orphans_types="${orphans_types/( /(}"
1920 [ "$orphans_types" != '()' ] &&
1921 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
1923 suffix=''; [ -n "$set" ] && suffix="-$set"
1924 echo -n ' <pre class="files">'
1925 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1926 IFS=$'\n'
1927 while read orphan_line; do
1928 echo -n "${orphan_line/span> */span>} "
1929 cd $install
1930 ls -ldp --color=always ".${orphan_line#*</span> }" \
1931 | syntax_highlighter files \
1932 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
1933 | awk 'BEGIN { FS="\""; }
1934 { gsub("+", "%2B", $2); print; }'
1935 done < $table
1936 unset IFS
1937 echo '</pre>'
1938 echo '</section>'
1939 rm $table
1940 fi
1941 rm $orphans
1942 # ------------------------------------------------------
1943 # /Unpackaged files
1944 # ------------------------------------------------------
1946 rm $all_files $packaged
1947 ;;
1948 esac
1949 done # /set
1951 case "$part" in
1952 head)
1953 [ -n "$splitsets" ] && echo "</ul>"
1954 echo "</section>"
1955 ;;
1956 esac
1957 done # /part
1959 ;;
1961 description)
1962 page_header
1963 pkg_info
1964 descs="$(ls $WOK/$pkg/description*.txt)"
1965 if [ -n "$descs" ]; then
1966 echo '<div id="content2">'
1967 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1968 for i in $descs; do
1969 case $i in
1970 */description.txt) continue ;;
1971 *) package=$(echo $i | cut -d. -f2) ;;
1972 esac
1973 show_desc "$package" "$i"
1974 done
1975 echo '</div>'
1976 else
1977 show_note w "No description of $pkg"
1978 fi
1979 ;;
1981 log)
1982 page_header
1983 pkg_info
1984 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1986 echo '<div class="btnList">'
1987 acc='l' # access key for the latest log is 'L'
1988 while read log; do
1989 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1990 timestamp=$(stat -c %Y $log)
1991 class=''
1992 if [ "$arg" == "$timestamp" ]; then
1993 class=' log'
1994 logfile="$log"
1995 fi
1996 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1997 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1998 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1999 case $acc in
2000 l) acc=0;;
2001 *) acc=$((acc+1));;
2002 esac
2003 done <<EOT
2004 $(find $LOGS -name "$pkg.log*" | sort)
2005 $(find $LOGS -name "$pkg-pack.log")
2006 EOT
2007 echo '</div>'
2009 if [ -z "$logfile" ]; then
2010 show_note e "Requested log is absent"
2011 page_footer
2012 exit 0
2013 fi
2015 # Define cook variables for syntax highlighter
2016 if [ -s "$WOK/$pkg/receipt" ]; then
2017 . "$WOK/$pkg/receipt"
2018 _wok='/home/slitaz/wok'
2019 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
2020 _install="$_wok/$pkg/install"
2021 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
2022 _stuff="$_wok/$pkg/stuff"
2023 fi
2025 # if [ ! -f "gzlog/$pkg.$arg" ]; then
2026 # {
2027 # summary "$logfile" links
2029 # syntax_highlighter log < $logfile | awk '
2030 # BEGIN { print "<pre class=\"log\">"; }
2031 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
2032 # END { print "</pre>"; }
2033 # '
2035 # page_footer
2036 # } | gzip > gzlog/$pkg.$arg
2037 # fi
2039 blog=$(basename $logfile)
2040 summary "$logfile" links
2042 # disable next `sed` for the 'like2016' theme
2043 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
2044 cat $logfile | syntax_highlighter log | \
2045 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
2046 awk '
2047 BEGIN { print "<pre class=\"log\">"; }
2048 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
2049 END { print "</pre>"; }
2051 ;;
2054 man|doc|info)
2055 page_header
2056 pkg_info
2057 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
2059 dir="wok/$pkg/install/usr/share/$cmd/"; dir2=''
2060 if [ "$cmd" == 'doc' ]; then
2061 dir2="wok/$pkg/install/usr/share/gtk-doc/"
2062 subdirs="$(ls -p $dir | sed '/\/$/!d')"
2063 [ $(echo "$subdirs" | wc -l) -eq 1 ] && dir="$dir$subdirs"
2064 if [ -z "$arg" ]; then
2065 try=$(for i in $dir $dir2; do find $i -name 'index.htm*'; done | sed q)
2066 [ -n "$try" ] && arg="$try"
2067 fi
2068 fi
2070 while read i; do
2071 [ -s "$i" ] || continue
2072 case "$i" in
2073 *.jp*g|*.png|*.gif|*.svg|*.css) continue
2074 esac
2075 i=${i#$dir}; i=${i#$dir2}
2076 [ -n "$arg" ] || arg="$i"
2077 class=''; [ "$arg" == "$i" ] && class=" doc"
2078 case "$cmd" in
2079 man)
2080 case $i in
2081 man*) lang='';;
2082 *) lang="${i%%/*}: ";;
2083 esac
2084 man=$(basename $i .gz)
2085 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
2086 ;;
2087 doc)
2088 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$i</a>"
2089 ;;
2090 info)
2091 info=$(basename $i)
2092 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
2093 ;;
2094 esac
2095 done <<EOT
2096 $(for i in $dir $dir2; do find $i -type f; done | sort)
2097 EOT
2098 echo '</div>'
2100 [ -f "$arg" ] || arg="$dir/$arg"
2101 if [ -f "$arg" ]; then
2102 tmp="$(mktemp)"
2103 docat "$arg" > $tmp
2104 [ -s "$tmp" ] &&
2105 case "$cmd" in
2106 info)
2107 echo '<div id="content2" class="texinfo"><pre class="first">'
2108 info2html < "$tmp"
2109 echo '</pre></div>'
2110 ;;
2111 doc)
2112 case "$arg" in
2113 *.sgml|*.devhelp2) class='xml';;
2114 *.py) class='python';; # pycurl package
2115 *.css) class='css';;
2116 *.sh) class='bash';;
2117 *.rb|*/Rakefile*|*/Gemfile*) class='ruby';;
2118 *.rdoc) class='asciidoc';;
2119 *)
2120 first=$(head -n1 "$tmp")
2121 if [ "${first:0:1}" == '#' ]; then
2122 class='bash' # first line begins with '#'
2123 else
2124 class='asciidoc'
2125 fi;;
2126 esac
2127 case "$arg" in
2128 *.htm*)
2129 case $arg in
2130 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
2131 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
2132 esac
2133 # make the iframe height so long to contain its contents without scrollbar
2134 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
2135 ;;
2136 *.pdf)
2137 case $arg in
2138 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
2139 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
2140 esac
2141 cat <<EOT
2142 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
2143 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
2144 </object>
2145 EOT
2146 ;;
2147 *.md|*.markdown)
2148 echo '<section>'
2149 $md2html "$tmp" | sed 's|class="|class="language-|g'
2150 echo '</section>'
2151 ;;
2152 *)
2153 show_code $class < "$tmp"
2154 ;;
2155 esac
2156 ;;
2157 man)
2158 #export TEXTDOMAIN='man2html'
2159 echo "<div id='content2'>"
2161 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
2162 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
2163 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
2165 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
2166 # Process the pre-formatted man-cat page
2167 # (for example see sudo package without groff in build dependencies)
2168 sed -i '
2169 s|M-bM-^@M-^S|—|g;
2170 s|M-bM-^@M-^\\|<b>|g;
2171 s|M-bM-^@M-^]|</b>|g
2172 s|M-bM-^@M-^X|<u>|g;
2173 s|M-bM-^@M-^Y|</u>|g;
2174 s|M-BM-||g;
2175 s|++oo|•|g;
2176 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
2177 ' "$tmp"
2178 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 \
2179 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 \
2180 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
2181 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
2182 done
2183 echo '<pre class="catman">'
2184 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
2185 echo '</pre>'
2186 else
2187 echo "$html"
2188 fi
2189 echo "</div>"
2190 ;;
2191 esac
2192 rm -f $tmp
2193 else
2194 show_note e "File “$arg” does not exist!"
2195 fi
2196 ;;
2198 download)
2199 page_header
2200 pkg_info
2201 show=0
2203 . $wok/$pkg/receipt
2205 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
2206 files_header
2207 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
2208 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
2209 echo "<td>Sources for building the package “$pkg”</td></tr>"
2210 show=1
2211 fi
2213 if [ -d "$wok/$pkg/taz" ]; then
2214 [ "$show" -eq 1 ] || files_header
2216 common_version=$VERSION
2217 for i in $(all_names); do
2218 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
2219 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
2221 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
2222 [ -f "$PKGS/$filename" ] &&
2223 cat <<EOT
2224 <tr>
2225 <td><a href="$base/get/$filename">$filename</a></td>
2226 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
2227 <td>$SHORT_DESC</td>
2228 </tr>
2229 EOT
2230 done
2231 done
2232 show=1
2233 fi
2235 if [ "$show" -eq 1 ]; then
2236 echo '</tbody></table></section>'
2237 else
2238 show_note w "Sorry, there's nothing to download…"
2239 fi
2240 ;;
2242 esac
2245 page_footer
2246 exit 0