cookutils view lighttpd/index.cgi @ rev 994

modules/deps: clean files from missing legacy packages; lighttpd/index.cgi: display appropriate name/description for split packages, display fair table in "Related packages" section.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Nov 01 02:49:40 2017 +0200 (2017-11-01)
parents c7acc35d3a59
children c8e2be5291b8
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 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
19 [ -f "./cook.conf" ] && . ./cook.conf
20 wok="$WOK"
21 title=${title:-SliTaz Cooker}
22 # Cooker DB files.
23 activity="$CACHE/activity"
24 commits="$CACHE/commits"
25 cooklist="$CACHE/cooklist"
26 cookorder="$CACHE/cookorder"
27 command="$CACHE/command"; touch $command
28 blocked="$CACHE/blocked"
29 broken="$CACHE/broken"
30 cooknotes="$CACHE/cooknotes"
31 cooktime="$CACHE/cooktime"
32 wokrev="$CACHE/wokrev"
33 webstat="$CACHE/webstat"
34 splitdb="$CACHE/split.db"
36 # Path to markdown to html convertor
37 cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
38 if [ -n "$(which cmark 2>/dev/null)" ]; then
39 md2html="$(which cmark) $cmark_opts"
40 elif [ -x "./cmark" ]; then
41 md2html="./cmark $cmark_opts"
42 elif [ -n "$(which sundown 2>/dev/null)" ]; then
43 md2html=$(which sundown)
44 elif [ -x "./sundown" ]; then
45 md2html="./sundown"
46 fi
51 # Search form redirection
52 if [ -n "$(GET search)" ]; then
53 echo -e "HTTP/1.1 301 Moved Permanently\nLocation: $base/$(GET q)\n\n"
54 exit 0
55 fi
58 # Show the running command and it's progression
60 running_command() {
61 state="$(cat $command)"
62 local pct=''
63 if [ -n "$state" ];then
64 echo -n "$state</td></tr><tr><td>Completion</td>"
65 set -- $(grep "^$state" $cooktime)
66 [ -n "$1" -a $2 -ne 0 ] && pct=$((($(date +%s)-$3)*100/$2))
67 [ -n "$pct" ] && max="max='100'"
68 echo -n "<td><progress id='gauge' $max value='$pct' title='Click to stop updating' onclick='stopUpdating()'>"
69 echo -n "</progress> <span id='pct'>${pct:-?}%</span>"
70 [ "$2" -gt 60 ] &&
71 echo -n "</td></tr><tr><td>Estimated end time</td><td>$(date +%H:%M -ud @$(($2+$3)))"
72 else
73 echo 'not running'
74 fi
75 }
78 # HTML page header
80 page_header() {
81 local theme t='' css
82 theme=$(COOKIE theme)
83 [ "$theme" == 'default' ] && theme=''
84 [ -n "$theme" ] && theme="-$theme"
85 css="cooker$theme.css"
87 echo -e 'Content-Type: text/html; charset=UTF-8\n'
89 cat <<EOT
90 <!DOCTYPE html>
91 <html lang="en">
92 <head>
93 <title>$([ -n "$pkg" ] && echo "$pkg - ")$title</title>
94 <link rel="stylesheet" href="/$css">
95 <link rel="icon" type="image/png" href="/slitaz-cooker.png">
96 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
97 <!-- mobile -->
98 <meta name="viewport" content="width=device-width, initial-scale=1.0">
99 <meta name="theme-color" content="#222">
100 <!-- rss -->
101 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
102 </head>
103 <body>
104 <div id="container">
105 <header>
106 <h1><a href="$base/">$title</a></h1>
107 <div class="network">
108 <a href="http://www.slitaz.org/">Home</a>
109 <a href="http://bugs.slitaz.org/">Bugs</a>
110 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
111 <a href="http://roadmap.slitaz.org/">Roadmap</a>
112 <a href="http://pizza.slitaz.me/">Pizza</a>
113 <a href="http://tank.slitaz.org/">Tank</a>
114 |
115 <a href="/cross/">Cross</a>
116 <a href="/i486.cgi">i486</a>
117 <a href="$base/cookiso.cgi">ISO</a>
118 <select onChange="window.location.href=this.value" style="display: none">
119 <option value=".">Go to…</option>
120 <option value="http://www.slitaz.org/">Home</option>
121 <option value="http://bugs.slitaz.org/">Bug tracker</option>
122 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
123 <option value="http://roadmap.slitaz.org/">Roadmap</option>
124 <option value="http://pizza.slitaz.me/">Pizza</option>
125 <option value="http://tank.slitaz.org/">Tank</option>
126 <option disabled>---------</option>
127 <option value="cross/">Cross</option>
128 <option value="i486.cgi">i486</option>
129 <option value="cookiso.cgi">ISO</option>
130 </select>
131 </div>
132 </header>
134 <main>
135 EOT
137 [ -n "$(GET debug)" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
138 }
141 # HTML page footer
143 page_footer() {
144 date_now=$(date +%s)
145 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
146 wait_sec=$(( 60 - $sec_now ))
147 cat <<EOT
148 </main>
150 <footer>
151 <a href="http://www.slitaz.org/">SliTaz Website</a>
152 <a href="$base/">Cooker</a>
153 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
154 <a href="$base/?theme">Theme</a>
155 </footer>
156 </div>
157 <script src="/cooker.js"></script>
158 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
159 </body>
160 </html>
161 EOT
162 }
165 show_note() {
166 echo "<div class='bigicon-$1'>$2</div>"
167 }
170 not_found() {
171 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
172 echo "HTTP/1.1 404 Not Found"
173 page_header
174 echo "<h2>Not Found</h2>"
175 case $2 in
176 pkg)
177 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
178 *)
179 show_note e "The requested file “$file” was not found." ;;
180 esac
181 page_footer
182 }
185 manage_modified() {
186 local file="$1" option="$2" nul day mon year time hh mm ss date_s
187 if [ ! -f "$file" ]; then
188 if [ "$option" == 'silently-absent' ]; then
189 echo "HTTP/1.1 404 Not Found"
190 return
191 else
192 not_found "$file" "$2"
193 exit
194 fi
195 fi
196 [ "$option" == 'no-last-modified' ] && return
197 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
198 echo "$HTTP_IF_MODIFIED_SINCE" | \
199 while read nul day mon year time nul; do
200 case $mon in
201 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
202 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
203 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
204 esac
205 hh=$(echo $time | cut -d: -f1)
206 mm=$(echo $time | cut -d: -f2)
207 ss=$(echo $time | cut -d: -f3)
208 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
209 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
210 # echo -e 'HTTP/1.1 304 Not Modified\n'
211 # exit
212 # fi
213 # TODO: improve caching control
214 done
215 fi
216 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
217 echo "Cache-Control: public, max-age=3600"
218 }
221 # Query '?pct=<package>': update percentage
223 if [ -n "$(GET pct)" ]; then
224 pkg="$(GET pct)"
225 state="$(cat $command)"
226 if [ "$state" == "cook:$pkg" ]; then
227 set -- $(grep "^$state" $cooktime)
228 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
229 echo "${pct:-?}"
230 else
231 echo 'reload'
232 fi
233 exit 0
234 fi
237 # Query '?poke': poke cooker
239 if [ -n "$(GET poke)" ]; then
240 touch $CACHE/cooker-request
241 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
242 exit
243 fi
246 # Query '?recook=<package>': query to recook package
248 if [ -n "$(GET recook)" ]; then
249 pkg="$(GET recook)"
250 case "$HTTP_USER_AGENT" in
251 *SliTaz*)
252 grep -qs "^$pkg$" $CACHE/recook-packages ||
253 echo "$pkg" >> $CACHE/recook-packages
254 esac
255 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
256 exit
257 fi
260 # Query '/i/<log>/<pkg>': show indicator icon
261 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
263 if [ "$pkg" == 'i' ]; then
264 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
265 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
266 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
267 else
268 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
269 fi
270 exit
271 fi
274 # Query '/s/<pkg>': show status indicator icon
275 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
277 if [ "$pkg" == 's' ]; then
278 # argument <pkg> is in $cmd variable
280 # find main package
281 main=$(awk -F$'\t' -vpkg=" $cmd " '{
282 if (index(" " $2 " ", pkg)) {print $1; exit}
283 }' $splitdb)
284 # get version
285 ver="$(. $wok/$main/receipt; echo "$VERSION")"
287 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
288 if [ -e $PKGS/$cmd-$ver.tazpkg ]; then
289 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
290 else
291 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
292 fi
293 exit
294 fi
297 # Query '?theme[=<theme>]': change UI theme
299 if [ -n "$(GET theme)" ]; then
300 theme="$(GET theme)"
301 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
302 case $theme in
303 theme)
304 current=$(COOKIE theme)
305 page_header
306 cat <<EOT
307 <section>
308 <h2>Change theme</h2>
309 <p>Current theme: “${current:-default}”. Select other:</p>
310 <ul>
311 $(
312 for i in default emerald sky goldenrod midnight like2016 terminal; do
313 [ "$i" == "${current:-default}" ] || echo "<li><a href=\"$base/?theme=$i&amp;ref=$ref\">$i</a></li>"
314 done
315 )
316 </ul>
317 </section>
318 EOT
319 page_footer
320 exit 0
321 ;;
322 default|emerald|sky|goldenrod|midnight|like2016|terminal)
323 ref="$(GET ref)"
324 [ -n "$ref" ] || ref="$base/"
325 # Expires in a year
326 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
327 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
328 exit 0
329 ;;
330 esac
331 fi
334 #case "$QUERY_STRING" in
335 # stuff*)
336 # file="$wok/$(GET stuff)"
337 # manage_modified "$file"
338 # ;;
339 #
340 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
341 # type=${QUERY_STRING%%=*}
342 # pkg=$(GET $type)
343 # case "$type" in
344 # description)
345 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
346 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
347 # ;;
348 # log)
349 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
350 # manage_modified "$LOGS/$pkg"
351 # ;;
352 # *)
353 # manage_modified "$wok/$pkg/receipt" pkg
354 # ;;
355 # esac
356 # ;;
357 #esac
360 # RSS feed generator
361 # URI: ?rss[&limit={1..100}]
363 if [ -n "$(GET rss)" ]; then
364 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
365 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
366 cooker_url="http://$HTTP_HOST$base/"
367 cat <<EOT
368 Content-Type: application/rss+xml
370 <?xml version="1.0" encoding="utf-8" ?>
371 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
372 <channel>
373 <title>$title</title>
374 <description>The SliTaz packages cooker feed</description>
375 <link>$cooker_url</link>
376 <lastBuildDate>$pubdate</lastBuildDate>
377 <pubDate>$pubdate</pubDate>
378 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
379 EOT
380 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
381 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $rss
382 done
383 cat <<EOT
384 </channel>
385 </rss>
386 EOT
387 exit 0
388 fi
391 ### OpenSearch ###
393 # Query '/os.xml': get OpenSearch Description
395 if [ "$pkg" == 'os.xml' ]; then
396 cat <<EOT
397 Content-Type: application/xml; charset=UTF-8
399 <?xml version="1.0" encoding="UTF-8"?>
400 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
401 <ShortName>$title</ShortName>
402 <Description>SliTaz packages search</Description>
403 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
404 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
405 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
406 <Param name="oss" value="{searchTerms}"/>
407 </Url>
408 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
409 <InputEncoding>UTF-8</InputEncoding>
410 </OpenSearchDescription>
411 EOT
412 exit 0
413 fi
415 # Query '?oss[=<term>]': OpenSearch suggestions
417 if [ -n "$(GET oss)" ]; then
418 term="$(GET oss | tr -cd '[:alnum:]+-')"
419 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
420 cd $wok
421 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
422 BEGIN{printf("[\"%s\",[", term)}
423 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
424 END {printf("]]")}
425 '
426 exit 0
427 fi
432 #
433 # Functions
434 #
437 # Unpack to stdout
439 docat() {
440 case "$1" in
441 *gz) zcat ;;
442 *bz2) bzcat ;;
443 *xz) xzcat ;;
444 *) cat
445 esac < $1
446 }
449 # Tiny texinfo converter
451 info2html() {
452 sed \
453 -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g' \
454 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
455 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
456 -e '/^File: / s|(dir)|Top|g' \
457 -e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
458 -e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
459 -e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
460 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
461 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
462 -e '/^Tag Table:$/,/^End Tag Table$/d' \
463 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
464 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
465 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
466 -e 's|^\* Menu:|<b>Menu:</b>|' \
467 -e "s|^|</pre>|"
468 }
471 # Put some colors into log and DB files.
473 syntax_highlighter() {
474 case $1 in
475 log)
476 # If variables not defined - define them with some rare values
477 : ${_src=#_#_#}
478 : ${_install=#_#_#}
479 : ${_fs=#_#_#}
480 : ${_stuff=#_#_#}
481 # Use one-letter html tags to save some bytes :)
482 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informal (green)</i>
483 sed -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
484 -e 's#OK$#<i>OK</i>#' \
485 -e 's#\([Dd]one\)$#<i>\1</i>#' \
486 -e 's#Success$#<i>Success</i>#' \
487 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
488 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
489 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
490 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
491 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
492 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
493 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
494 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
495 \
496 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
497 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
498 -e 's# y$# <i>y</i>#' \
499 -e 's# n$# <u>n</u>#' \
500 -e 's#(NEW) *$#<b>(NEW)</b>#' \
501 \
502 -e 's#.*(pkg/local).*#<i>\0</i>#' \
503 -e 's#.*(web/cache).*#<u>\0</u>#' \
504 \
505 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
506 -e 's#ERROR:#<b>ERROR:</b>#g' \
507 \
508 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
509 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
510 -e '/non-fatal/ s|</*b>||g' \
511 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
512 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
513 -e 's#^.*No package .* found.*#<b>\0</b>#' \
514 -e 's#^.*Unable to find.*#<b>\0</b>#' \
515 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
516 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
517 -e 's#\(found\.*\)$#<i>\1</i>#' \
518 \
519 -e 's#^.*WARNING:.*#<u>\0</u>#' \
520 -e 's#^.*warning:.*#<u>\0</u>#' \
521 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
522 -e 's#^.*terminated.*#<b>\0</b>#' \
523 -e 's#\(missing\)#<b>\1</b>#g' \
524 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
525 -e 's#^.*unrecognized options.*#<u>\0</u>#' \
526 -e 's#^.*does not.*#<u>\0</u>#' \
527 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
528 -e 's#^.*note:.*#<u>\0</u>#' \
529 \
530 -e 's#^.* will not .*#<u>\0</u>#' \
531 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
532 -e 's#^.* Warning: .*#<u>\0</u>#' \
533 \
534 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
535 -e "s#^Making.*#<em>\0</em>#" \
536 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
537 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
538 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
539 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
540 \
541 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
542 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
543 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
544 \
545 -e "s|$_src|<var>\${src}</var>|g;
546 s|$_install|<var>\${install}</var>|g;
547 s|$_fs|<var>\${fs}</var>|g;
548 s|$_stuff|<var>\${stuff}</var>|g" \
549 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
550 s|\[39m|</span>|;
551 s|\[1m|<strong>|g; s|\[0m|</strong>|g" \
552 -e "s|^+.*|<i>\0</i>|;
553 s|^-.*|<b>\0</b>|; /----/s|</*b>||; /^<b>--[^-]/s|</*b>||;"
554 ;;
556 files)
557 # Highlight the Busybox's `ls` output
558 awk '{
559 part1 = substr($0, 0, 16);
560 part2 = substr($0, 17, 9);
561 part3 = substr($0, 26, 9);
562 part4 = substr($0, 35);
563 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
564 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
565 print part1 part2 part3 part4;
566 }' | \
567 sed "s|\[0m/|/\[0m|g;
568 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
569 s|\[\([01]\);0m|<a class='c0\1'>|g;
570 s|\[0m|</a>|g;
571 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
572 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
573 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
574 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
575 s|^\([lrwxs-]*\)|<span class='c11'>\1</span>|;
576 "
577 ;;
578 esac
579 }
582 show_code() {
583 echo -n "<pre><code class=\"language-$1\">"
584 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
585 echo '</code></pre>'
586 }
589 datalist() {
590 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
591 BEGIN{printf("<datalist id=\"packages\">")}
592 {printf("<option>%s",$1)}
593 END {printf("</datalist>")}
594 '
595 }
598 mklog() {
599 awk '
600 BEGIN { printf("<pre class=\"log dog\">\n") }
601 { print }
602 END { print "</pre>" }'
603 }
606 summary() {
607 log="$1"
608 pkg="$(basename ${log%%.log*})"
610 if [ -f "$log" ]; then
611 if grep -q "cook:$pkg$" $command; then
612 show_note i "The Cooker is currently building $pkg"
613 elif fgrep -q "Summary for:" $log; then
614 sed '/^Summary for:/,$!d' $log | awk '
615 BEGIN { print "<section>" }
616 function row(line) {
617 split(line, s, " : ");
618 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
619 }
620 function row2(line, rowNum) {
621 split(line, s, " : ");
622 if (rowNum == 1) {
623 print "<thead>";
624 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]);
625 print "</thead><tbody>";
626 }
627 else
628 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]);
629 }
630 {
631 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
632 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
633 if ($0 ~ "---") {
634 seen2++;
635 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
636 next
637 }
638 if (seen2) row2($0, seen2); else row($0);
639 }
640 END { print "</tbody></table></section>" }
641 '
642 elif fgrep -q "Debug information" $log; then
643 echo -e '<section>\n<h3>Debug information</h3>'
644 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
645 if [ -n "$2" ]; then
646 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
647 else
648 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
649 fi | mklog
650 echo '</section>'
651 fi
652 else
653 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
654 fi
655 }
658 active() {
659 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
660 }
663 pkg_info() {
664 local log active bpkg
665 log="$LOGS/$pkg.log"
667 echo -n "<h2><a href=\"$base/$requested_pkg\">$requested_pkg</a>"
668 [ -f $PKGS/packages.info ] && awk -F$'\t' -vp="$requested_pkg" '{if ($1 == p) { print ": " $4; exit; }}' $PKGS/packages.info
669 echo '</h2>'
670 echo '<div id="info">'
671 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
673 unset WEB_SITE WANTED
674 . $wok/$pkg/receipt
676 [ -n "$WEB_SITE" ] &&
677 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
679 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ] &&
680 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
682 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
683 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
685 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
686 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
688 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
690 [ -x ./man2html -a -d "$wok/$pkg/install/usr/share/man" ] &&
691 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
693 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
694 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
696 [ -d "$wok/$pkg/install/usr/share/info" ] &&
697 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
699 if [ -n "$LFS" ]; then
700 printf "<a class='button icon doc' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
701 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
702 printf "LFS</a>\n"
703 fi
705 [ -s "$log" ] &&
706 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
708 echo '</div>'
709 }
712 mktable() {
713 sed 's# : #|#' | awk -vc="$1" '
714 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
715 { printf("<tr><td>%s</td>", $1);
716 if (NF == 2) printf("<td>%s</td>", $2);
717 printf("</tr>\n", $2) }
718 END { print "</table>" }'
719 }
722 section() {
723 local i=$(basename "$1")
724 echo -e '\n\n<section>'
725 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
726 echo "<h2>${3%|*}</h2>"
727 mktable "$i"
728 echo '</section>'
729 }
732 show_desc() {
733 echo "<section><h3>Description of “$1”</h3>"
734 if [ -n "$md2html" ]; then
735 $md2html $2
736 else
737 show_code markdown < $2
738 fi
739 echo "</section>"
740 }
743 # Return all the names of packages bundled in this receipt
745 all_names() {
746 local split=" $SPLIT "
747 if [ "${split/ $PACKAGE /}" != "$split" ]; then
748 # $PACKAGE included somewhere in $SPLIT (probably in the end).
749 # We should build packages in the order defined in the $SPLIT.
750 echo $SPLIT
751 else
752 # We'll build the $PACKAGE, then all defined in the $SPLIT.
753 echo $PACKAGE $SPLIT
754 fi
755 }
758 toolchain_version() {
759 echo "<tr><td><a href='$base/$1'>$1</a></td><td>"
760 if [ -e "$WOK/$1/receipt" ]; then
761 grep ^VERSION $WOK/$1/receipt | cut -d '"' -f2
762 echo '</td><td>'
763 grep ^SHORT_DESC $WOK/$1/receipt | cut -d '"' -f2
764 else
765 echo -n '---</td><td>---'
766 fi
767 echo "</td></tr>"
768 }
771 files_header() {
772 echo '<section><h3>Available downloads:</h3>'
773 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
774 }
777 # Update statistics used in web interface.
778 # There is no need to recalculate the statistics every time the page is displayed.
779 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
781 update_webstat() {
782 echo '<div id="waitme">'
783 show_note i 'Please wait while statistics are being collected.'
784 echo "</div>"
786 # for receipts:
787 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
788 rcooked=$(ls -d $WOK/*/taz | wc -l)
789 runbuilt=$(($rtotal - $rcooked))
790 rblocked=$(wc -l < $blocked)
791 rbroken=$(wc -l < $broken)
793 # for packages:
794 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
795 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
796 punbuilt=$(($ptotal - $pcooked))
797 pblocked=$(
798 while read i; do
799 sed "/^$i\t/!d" $CACHE/split.db
800 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
801 pbroken=$(
802 while read i; do
803 sed "/^$i\t/!d" $CACHE/split.db
804 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
806 cat > $webstat <<EOT
807 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
808 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
809 EOT
811 echo '<script>document.getElementById("waitme").remove();</script>'
812 }
817 #
818 # Load requested page
819 #
821 if [ -z "$pkg" ]; then
823 page_header
824 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
826 for list in activity cooknotes cooklist; do
827 [ -n "$(GET $list)" ] || continue
828 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
829 echo '<section id="content2">'
830 echo "<h2>DB: $list $nb</h2>"
831 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
832 s|\[ Done|<span class="r c20">Done|;
833 s|\[ Failed|<span class="r c10">Failed|;
834 s| \]|</span>|' | mktable $list
835 echo '</section>'
836 done
838 if [ -n "$(GET broken)" ]; then
839 echo '<section id="content2">'
840 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
841 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
842 echo '</section>'
843 fi
845 case "$QUERY_STRING" in
846 *.log)
847 log=$LOGS/$QUERY_STRING
848 name=$(basename $log)
849 if [ -f "$log" ]; then
850 echo "<h2>Log for: ${name%.log}</h2>"
851 if fgrep -q "Summary" $log; then
852 echo '<pre class="log">'
853 grep -A 20 'Summary' $log | syntax_highlighter log
854 echo '</pre>'
855 fi
856 echo '<pre class="log">'
857 syntax_highlighter log < $log
858 echo '</pre>'
859 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
860 # Display button only for SliTaz web browser
861 case "$HTTP_USER_AGENT" in
862 *SliTaz*)
863 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
864 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
865 show_note i "The package database has been requested for re-creation"
866 else
867 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
868 fi
869 fi
870 ;;
871 esac
872 fi
873 else
874 show_note e "No log file: $log"
875 fi
876 ;;
877 toolchain)
878 cat <<EOT
879 <div id="content2">
880 <section>
881 <h2>SliTaz GNU/Linux toolchain</h2>
883 <table>
884 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
885 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
886 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
887 <tr><td>Build system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
888 <tr><td>Host system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
889 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
890 $(toolchain_version slitaz-toolchain)
891 $(toolchain_version binutils)
892 $(toolchain_version linux-api-headers)
893 $(toolchain_version gcc)
894 $(toolchain_version glibc)
895 </table>
897 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
898 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
899 </p>
901 </section>
902 </div>
903 EOT
904 ;;
905 esac
906 page_footer
907 exit 0
908 fi
911 # We may have a toolchain.cgi script for cross cooker's
912 if [ -f "toolchain.cgi" ]; then
913 toolchain="toolchain.cgi"
914 else
915 toolchain="?toolchain"
916 fi
918 # Main page with summary. Count only packages included in ARCH,
919 # use 'cooker arch-db' to manually create arch.$ARCH files.
921 cat <<EOT
922 <div id="content2">
924 <section>
925 <form method="get" action="" class="search r">
926 <input type="hidden" name="search" value="pkg"/>
927 <button type="submit" title="Search">Search</button>
928 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
929 </form>
931 <h2>Summary</h2>
932 EOT
934 mktable <<EOT
935 Cooker state : $(running_command)
936 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
937 Commits to cook : $(wc -l < $commits)
938 Current cooklist : $(wc -l < $cooklist)
939 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
940 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
941 EOT
943 # If command is "cook:*", update gauge and percentage periodically.
944 # If different package is cooking, reload the page (with new settings)
945 cmd="$(cat $command)"
946 case "$cmd" in
947 cook:*)
948 pkg=${cmd#*:}
949 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
950 ;;
951 esac
953 # Do we need to update the statistics?
954 [ "$webstat" -nt "$activity" ] || update_webstat
955 . $webstat
957 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
959 cat <<EOT
960 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
962 <table class="webstat"><thead>
963 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
964 </thead><tbody>
965 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
966 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
967 </tbody></table>
968 EOT
970 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
971 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
972 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
973 else
974 show_note i 'Cooker will be launched in the next 5 minutes.'
975 fi
976 fi
978 cat <<EOT
979 <p>
980 Service logs:
981 <a href="?cookorder.log">cookorder</a> ·
982 <a href="?commits.log">commits</a> ·
983 <a href="?pkgdb.log">pkgdb</a>
984 </p>
985 </section>
986 EOT
988 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
989 s|\[ Done|<span class="r c20">Done|;
990 s|\[ Failed|<span class="r c10">Failed|;
991 s| \]|</span>|;
992 s|%2B|\+|g' | \
993 section $activity 12 "Activity|More activity"
995 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
996 section $cooknotes 12 "Cooknotes|More notes"
998 [ -s "$commits" ] &&
999 section $commits 20 "Commits|More commits" < $commits
1001 [ -s "$cooklist" ] && head -n 20 $cooklist | \
1002 section $cooklist 20 "Cooklist|Full cooklist"
1004 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
1005 section $broken 20 "Broken|All broken packages"
1007 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
1008 section $blocked 12 "Blocked|All blocked packages"
1010 cd $PKGS
1011 ls -let *.tazpkg | awk '
1012 (NR<=20){
1013 sub(/:[0-9][0-9]$/, "", $9);
1014 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
1015 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
1016 }' | \
1017 section $activity 1000 "Latest cook"
1019 echo '</div>'
1020 datalist
1021 page_footer
1022 exit 0
1023 fi
1026 case "$cmd" in
1027 '')
1028 page_header
1030 requested_pkg="$pkg"
1031 # Package info.
1032 if [ ! -f "$wok/$pkg/receipt" ]; then
1033 # Let's look at the cases when the package was not found
1035 # Maybe query is the exact name of split package? -> proceed to main package
1036 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1037 if (index(" " $2 " ", pkg)) {print $1; exit}
1038 }' $splitdb)
1040 # No, so let's find any matches among packages names (both main and split)
1041 if [ -z "$mainpkg" ]; then
1042 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1043 # Nothing matched
1044 if [ -z "$pkgs" ]; then
1045 echo "<h2>Not Found</h2>"
1046 show_note e "The requested package <b>$pkg</b> was not found on this server."
1047 page_footer; exit 0
1048 fi
1049 # Search results page
1050 echo "<section><h2>Package names matching “$pkg”</h2>"
1051 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1052 query="$pkg"
1053 for pkg in $pkgs; do
1054 # Find main package
1055 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1056 if (index(" " $2 " ", pkg)) {print $1; exit}
1057 }' $splitdb)
1058 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1060 unset SHORT_DESC CATEGORY
1061 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1062 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1064 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1065 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1066 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1067 done
1068 echo '</tbody></table></section>'
1069 page_footer; exit 0
1070 fi
1071 pkg="$mainpkg"
1072 fi
1074 log=$LOGS/$pkg.log
1075 pkg_info
1077 # Check for a log file and display summary if it exists.
1078 summary "$log"
1083 # Informal table with dependencies
1084 pkg="$requested_pkg"
1085 inf="$(mktemp -d)"
1087 # 1/3: Build dependencies (from receipt)
1088 for i in $WANTED $BUILD_DEPENDS; do
1089 echo "$i" >> $inf/a
1090 done
1092 # 2/3: Runtime dependencies (from pkgdb)
1093 inf_col2="$(mktemp)"
1095 [ -s "$PKGS/packages.info" ] &&
1096 awk -F$'\t' -vp="$pkg" '{
1097 if ($1 == p) print $8
1098 }' "$PKGS/packages.info"
1099 } | tr ' ' '\n' | sort -u > $inf/b
1101 # 3/3: Required by (from pkgdb)
1102 inf_col3="$(mktemp)"
1104 for i in $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1105 [ -s "$PKGS/packages.info" ] &&
1106 awk -F$'\t' -vp=" $i " '{
1107 if (index(" " $8 " ", p)) print $1
1108 }' "$PKGS/packages.info"
1110 [ -s "$PKGS/bdeps.txt" ] &&
1111 awk -F$'\t' -vp=" $i " '{
1112 if (index(" " $2 " ", p)) print $1
1113 }' $PKGS/bdeps.txt
1114 done
1115 } | sort -u > $inf/c
1117 cat <<EOT
1118 <section>
1119 <h3>Related packages</h3>
1120 <table class="third">
1121 <thead>
1122 <tr>
1123 <th>Build dependencies</th>
1124 <th>Runtime dependencies</th>
1125 <th>Required by</th>
1126 </tr>
1127 </thead>
1128 <tbody>
1129 EOT
1131 awk -vinf="$inf" -vbase="$base" '
1132 function linki(i) {
1133 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1135 BEGIN{
1136 do {
1137 a = b = c = "";
1138 getline a < inf "/a";
1139 getline b < inf "/b";
1140 getline c < inf "/c";
1141 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1142 } while ( a b c )
1143 }'
1144 cat <<EOT
1145 </tbody>
1146 </table>
1147 </section>
1148 EOT
1149 # Clean
1150 rm -r $inf
1155 # Display <Recook> button only for SliTaz web browser
1156 case "$HTTP_USER_AGENT" in
1157 *SliTaz*)
1158 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1159 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1160 show_note i "The package “$pkg” has been requested for recook"
1161 else
1162 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1163 fi
1164 fi
1165 ;;
1166 esac
1167 ;;
1169 receipt)
1170 page_header
1171 pkg_info
1172 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1173 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1174 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1176 show_code bash < $wok/$pkg/receipt
1177 ;;
1179 stuff)
1180 page_header
1181 pkg_info
1182 file="$pkg/stuff/$arg"
1183 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1184 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1185 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1186 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1187 }'
1189 if [ -f "$wok/$file" ]; then
1190 case $file in
1191 *.desktop|*.theme) class="ini" ;;
1192 *.patch|*.diff|*.u) class="diff" ;;
1193 *.sh) class="bash" ;;
1194 *.conf*|*.ini)
1195 class="bash"
1196 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1197 ;;
1198 *.pl) class="perl" ;;
1199 *.c|*.h|*.awk) class="clike" ;;
1200 *.svg) class="svg" ;;
1201 *Makefile*) class="makefile" ;;
1202 *.po|*.pot) class="bash" ;;
1203 *.css) class="css" ;;
1204 *.htm|*.html) class="html" ;;
1205 *.js) class="js" ;;
1206 *.txt) class="asciidoc" ;;
1207 *)
1208 case $(head -n1 $wok/$file) in
1209 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1210 esac
1211 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1212 class="bash"
1213 fi
1214 if [ -z "$class" ]; then
1215 # Follow Busybox restrictions. Search for non-printable chars
1216 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1217 raw="true"
1218 fi
1219 fi
1220 ;;
1221 esac
1223 # Display image
1224 case $file in
1225 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1226 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1227 ;;
1228 esac
1230 # Display colored listing for all text-based documents (also for *.svg)
1231 case $file in
1232 *.png|*.jpg|*.jpeg|*.ico) ;;
1233 *)
1234 if [ -z "$raw" ]; then
1235 cat $wok/$file | show_code $class
1236 fi
1237 ;;
1238 esac
1240 # Display hex dump for binary files
1241 if [ -n "$raw" ]; then
1242 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1243 fi
1244 else
1245 show_note e "File “$file” absent!"
1246 fi
1247 ;;
1249 files)
1250 page_header
1251 pkg_info
1253 packaged=$(mktemp)
1255 # find main package
1256 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1257 main=${wanted:-$pkg}
1259 # identify split packages
1260 split="$main $(. $wok/$main/receipt; echo $SPLIT)"
1261 [ -d "$wok/$main-dev" ] && split="$split $main-dev"
1262 split="$(echo $split | tr ' ' '\n' | sort -u)"
1264 # finally we need the version
1265 if [ -f "$WOK/linux/receipt" ]; then
1266 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1267 kbasevers=$(echo $kvers | cut -d. -f1,2)
1268 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1269 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1270 kbasevers=$(echo $kvers | cut -d. -f1,2)
1271 fi
1272 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1275 echo "<section><h3>Quick jump:</h3><ul>"
1276 echo "$split" | sed 'p' | xargs printf "<li><a href='#%s'>%s</a></li>\n"
1277 echo "<li id='li-repeats' style='display:none'><a href='#repeats'>repeatedly packaged files</a></li>"
1278 echo "<li id='li-empty' style='display:none'><a href='#empty'>unpackaged empty folders</a></li>"
1279 echo "<li id='li-orphans' style='display:none'><a href='#orphans'>unpackaged files</a>"
1280 echo "<span id='orphansTypes'></span></li>"
1281 echo "</ul></section>"
1283 for p in $split; do
1284 namever="$p-$ver"
1285 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1286 indir=$p
1287 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1288 indir=$main
1289 fi
1290 dir="$wok/$indir/taz/$p-$ver/fs"
1292 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1294 echo "<section><h3 id='$p'>Contents of package “$namever” (${size:-empty}):</h3>"
1295 echo '<pre class="files">'
1296 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1297 echo -n '<span class="underline">permissions·lnk·user ·'
1298 echo -en 'group · size·date &amp; time ·name\n</span>'
1299 cd $dir
1300 find . -print0 | sort -z | xargs -0 ls -ldp --color=always | \
1301 syntax_highlighter files | \
1302 sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" | \
1303 awk 'BEGIN { FS="\""; }
1304 { gsub("+", "%2B", $2); print; }'
1305 else
1306 echo 'No files'
1307 fi
1308 echo '</pre></section>'
1309 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1310 done
1312 # find repeatedly packaged files
1313 repeats="$(sort $packaged | uniq -d)"
1314 if [ -n "$repeats" ]; then
1315 echo '<script>document.getElementById("li-repeats").style.display = "list-item"</script>'
1316 echo -n '<section><h3 id="repeats">Repeatedly packaged files:</h3><pre class="files">'
1317 echo "$repeats" | sed 's|^|<span class="c11">!!!</span> |'
1318 echo "</pre></section>"
1319 fi
1321 # find unpackaged empty folders
1322 emptydirs="$(
1323 cd $wok/$main/install
1324 find -type d | sed 's|\.||' | \
1325 while read d; do
1326 [ -z "$(ls "$wok/$main/install$d")" ] || continue
1327 echo $d
1328 done | \
1329 while read d; do
1330 notfound='yes'
1331 for p in $(cd $wok/$main/taz; ls); do
1332 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1333 notfound=''
1334 break
1335 fi
1336 done
1337 [ -n "$notfound" ] &&
1338 ls -ldp --color=always .$d | syntax_highlighter files | sed 's|>\./|>/|'
1339 done
1340 )"
1341 if [ -n "$emptydirs" ]; then
1342 echo '<script>document.getElementById("li-empty").style.display = "list-item"</script>'
1343 echo -n '<section><h3 id="empty">Unpackaged empty folders:</h3><pre class="files">'
1344 echo "$emptydirs"
1345 echo "</pre></section>"
1346 fi
1348 # find unpackaged files
1349 all_files=$(mktemp)
1350 cd $wok/$main/install; find ! -type d | sed 's|\.||' > $all_files
1351 orphans="$(sort $all_files $packaged | uniq -u)"
1352 if [ -d "$wok/$main/install" -a -n "$orphans" ]; then
1353 echo '<script>document.getElementById("li-orphans").style.display = "list-item"</script>'
1354 echo '<section><h3 id="orphans">Unpackaged files:</h3>'
1355 table=$(mktemp)
1356 echo "$orphans" | awk -vi="$base/$indir/browse/install" '
1357 function tag(text, color) {
1358 printf("<span class=\"c%s1\">%s</span> ", color, text);
1359 printf("<a class=\"c00\" href=\"%s\">%s</a>\n", i $0, $0);
1361 /\/perllocal.pod$/ || /\/\.packlist$/ || /\/share\/bash-completion\// ||
1362 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ || /\/fonts\.scale$/ || /\/fonts\.dir$/ {
1363 tag("---", 0); next }
1364 /\.pod$/ { tag("pod", 5); next }
1365 /\/share\/man\// { tag("man", 5); next }
1366 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1367 /\/share\/devhelp\// { tag("doc", 5); next }
1368 /\/share\/icons\// { tag("ico", 2); next }
1369 /\/share\/locale\// { tag("loc", 4); next }
1370 /\.h$/ || /\.a$/ || /\.la$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1371 /\/Makefile.*$/ { tag("dev", 3); next }
1372 /\/share\/help\// || /\/share\/appdata\// { tag("gnm", 6); next }
1373 { tag("???", 1) }
1374 ' > $table
1376 # Summary table
1377 orphans_types='()'
1378 for i in head body; do
1379 case $i in
1380 head) echo -n '<table class="summary"><tr>';;
1381 body) echo -n '<th> </th></tr><tr>';;
1382 esac
1383 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1384 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1385 case $i in
1386 head) echo -n "<th class='$class'>$tag</th>";;
1387 body)
1388 tagscount="$(grep ">$tag<" $table | wc -l)"
1389 printf '<td>%s</td>' "$tagscount"
1390 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1391 ;;
1392 esac
1393 done
1394 done
1395 echo '<td> </td></tr></table>'
1396 orphans_types="${orphans_types/( /(}"
1397 [ "$orphans_types" != '()' ] &&
1398 echo "<script>document.getElementById('orphansTypes').innerText = '${orphans_types// /, }';</script>"
1400 echo -n '<pre class="files">'
1401 cat $table
1402 echo '</pre></section>'
1403 rm $table
1404 fi
1405 rm $packaged $all_files
1406 ;;
1408 description)
1409 page_header
1410 pkg_info
1411 descs="$(ls $WOK/$pkg/description*.txt)"
1412 if [ -n "$descs" ]; then
1413 echo '<div id="content2">'
1414 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1415 for i in $descs; do
1416 case $i in
1417 */description.txt) continue ;;
1418 *) package=$(echo $i | cut -d. -f2) ;;
1419 esac
1420 show_desc "$package" "$i"
1421 done
1422 echo '</div>'
1423 else
1424 show_note w "No description of $pkg"
1425 fi
1426 ;;
1428 log)
1429 page_header
1430 pkg_info
1431 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1433 echo '<div class="btnList">'
1434 acc='l' # access key for the latest log is 'L'
1435 while read log; do
1436 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1437 timestamp=$(stat -c %Y $log)
1438 class=''
1439 if [ "$arg" == "$timestamp" ]; then
1440 class=' log'
1441 logfile="$log"
1442 fi
1443 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1444 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1445 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1446 case $acc in
1447 l) acc=0;;
1448 *) acc=$((acc+1));;
1449 esac
1450 done <<EOT
1451 $(find $LOGS -name "$pkg.log*" | sort)
1452 $(find $LOGS -name "$pkg-pack.log")
1453 EOT
1454 echo '</div>'
1456 if [ -z "$logfile" ]; then
1457 show_note e "Requested log is absent"
1458 page_footer
1459 exit 0
1460 fi
1462 # Define cook variables for syntax highlighter
1463 if [ -s "$WOK/$pkg/receipt" ]; then
1464 . "$WOK/$pkg/receipt"
1465 _wok='/home/slitaz/wok'
1466 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1467 _install="$_wok/$pkg/install"
1468 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1469 _stuff="$_wok/$pkg/stuff"
1470 fi
1472 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1473 # {
1474 # summary "$logfile" links
1476 # syntax_highlighter log < $logfile | awk '
1477 # BEGIN { print "<pre class=\"log\">"; }
1478 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1479 # END { print "</pre>"; }
1480 # '
1482 # page_footer
1483 # } | gzip > gzlog/$pkg.$arg
1484 # fi
1486 blog=$(basename $logfile)
1487 summary "$logfile" links
1489 # disable next `sed` for the 'like2016' theme
1490 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1491 cat $logfile | syntax_highlighter log | \
1492 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1493 awk '
1494 BEGIN { print "<pre class=\"log\">"; }
1495 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
1496 END { print "</pre>"; }
1498 ;;
1501 man|doc|info)
1502 page_header
1503 pkg_info
1504 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1506 dir="wok/$pkg/install/usr/share/$cmd"
1507 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1508 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1509 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1510 [ -n "$try" ] && arg="$try"
1511 fi
1512 while read i; do
1513 [ -s "$i" ] || continue
1514 case "$i" in
1515 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1516 esac
1517 i=${i#$dir/}
1518 [ -n "$arg" ] || arg="$i"
1519 class=''; [ "$arg" == "$i" ] && class=" doc"
1520 case "$cmd" in
1521 man)
1522 case $i in
1523 man*) lang='';;
1524 *) lang="${i%%/*}: ";;
1525 esac
1526 man=$(basename $i .gz)
1527 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1528 ;;
1529 doc)
1530 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1531 ;;
1532 info)
1533 info=$(basename $i)
1534 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1535 ;;
1536 esac
1537 done <<EOT
1538 $(for i in $dir; do find $i -type f; done | sort)
1539 EOT
1540 echo '</div>'
1542 [ -f "$arg" ] || arg="$dir/$arg"
1543 if [ -f "$arg" ]; then
1544 tmp="$(mktemp)"
1545 docat "$arg" > $tmp
1546 [ -s "$tmp" ] &&
1547 case "$cmd" in
1548 info)
1549 echo '<div id="content2" class="texinfo"><pre class="first">'
1550 info2html < "$tmp"
1551 echo '</pre></div>'
1552 ;;
1553 doc)
1554 case "$arg" in
1555 *.sgml|*.devhelp2) class='xml';;
1556 *.py) class='python';; # pycurl package
1557 *.css) class='css';;
1558 *.sh) class='bash';;
1559 *)
1560 first=$(head -n1 "$tmp")
1561 if [ "${first:0:1}" == '#' ]; then
1562 class='bash' # first line begins with '#'
1563 else
1564 class='asciidoc'
1565 fi;;
1566 esac
1567 case "$arg" in
1568 *.htm*)
1569 case $arg in
1570 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1571 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1572 esac
1573 # make the iframe height so long to contain its contents without scrollbar
1574 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1575 ;;
1576 *.pdf)
1577 case $arg in
1578 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1579 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1580 esac
1581 cat <<EOT
1582 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1583 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1584 </object>
1585 EOT
1586 ;;
1587 *.md|*.markdown)
1588 echo '<section>'
1589 $md2html "$tmp"
1590 echo '</section>'
1591 ;;
1592 *)
1593 show_code $class < "$tmp"
1594 ;;
1595 esac
1596 ;;
1597 man)
1598 #export TEXTDOMAIN='man2html'
1599 echo "<div id='content2'>"
1601 html=$(./man2html "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1602 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1603 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1605 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1606 # Process the pre-formatted man-cat page
1607 # (for example see sudo package without groff in build dependencies)
1608 sed -i '
1609 s|M-bM-^@M-^S|—|g;
1610 s|M-bM-^@M-^\\|<b>|g;
1611 s|M-bM-^@M-^]|</b>|g
1612 s|M-bM-^@M-^X|<u>|g;
1613 s|M-bM-^@M-^Y|</u>|g;
1614 s|M-BM-||g;
1615 s|++oo|•|g;
1616 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
1617 ' "$tmp"
1618 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 \
1619 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 \
1620 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
1621 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
1622 done
1623 echo '<pre class="catman">'
1624 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
1625 echo '</pre>'
1626 else
1627 echo "$html"
1628 fi
1629 echo "</div>"
1630 ;;
1631 esac
1632 rm -f $tmp
1633 else
1634 show_note e "File “$arg” not exists!"
1635 fi
1636 ;;
1638 download)
1639 page_header
1640 pkg_info
1641 show=0
1643 . $wok/$pkg/receipt
1645 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
1646 files_header
1647 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
1648 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
1649 echo "<td>Sources for building the package “$pkg”</td></tr>"
1650 show=1
1651 fi
1653 if [ -d "$wok/$pkg/taz" ]; then
1654 [ "$show" -eq 1 ] || files_header
1656 for i in $(all_names); do
1657 [ -e "$wok/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt" ] || continue
1658 . $wok/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1660 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
1661 [ -f "$PKGS/$filename" ] &&
1662 cat <<EOT
1663 <tr>
1664 <td><a href="$base/get/$filename">$filename</a></td>
1665 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
1666 <td>$SHORT_DESC</td>
1667 </tr>
1668 EOT
1669 done
1670 done
1671 show=1
1672 fi
1674 if [ "$show" -eq 1 ]; then
1675 echo '</tbody></table></section>'
1676 else
1677 show_note w "Sorry, there's nothing to download…"
1678 fi
1679 ;;
1681 esac
1684 page_footer
1685 exit 0