cookutils view lighttpd/index.cgi @ rev 1062
lighttpd/index.cgi: tiny edits
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Wed May 30 16:33:35 2018 +0300 (2018-05-30) |
parents | 815349e0020b |
children | 20c2e51560fe |
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 pretitle='' command
82 theme=$(COOKIE theme)
83 [ "$theme" == 'default' ] && theme=''
84 [ -n "$theme" ] && theme="-$theme"
85 css="cooker$theme.css"
87 if [ -n "$pkg" ]; then
88 case "$pkg" in
89 ~) pretitle="Tag \"$cmd\" - ";;
90 *) pretitle="$pkg - ";;
91 esac
92 else
93 command="$(cat $command)"
94 [ -n "$command" ] && pretitle="$command - "
95 fi
96 [ -z "$favicon" ] && favicon='/slitaz-cooker.png'
98 echo -e 'Content-Type: text/html; charset=UTF-8\n'
100 cat <<EOT
101 <!DOCTYPE html>
102 <html lang="en">
103 <head>
104 <title>$pretitle$title</title>
105 <link rel="stylesheet" href="/$css">
106 <link rel="icon" type="image/png" href="$favicon">
107 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
108 <!-- mobile -->
109 <meta name="viewport" content="width=device-width, initial-scale=1.0">
110 <meta name="theme-color" content="#222">
111 <!-- rss -->
112 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
113 </head>
114 <body>
115 <div id="container">
116 <header>
117 <h1><a href="$base/">$title</a></h1>
118 <div class="network">
119 <a href="http://www.slitaz.org/">Home</a>
120 <a href="http://bugs.slitaz.org/">Bugs</a>
121 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
122 <a href="http://roadmap.slitaz.org/">Roadmap</a>
123 <a href="http://pizza.slitaz.me/">Pizza</a>
124 <a href="http://tank.slitaz.org/">Tank</a>
125 |
126 <a href="/cross/">Cross</a>
127 <a href="/i486.cgi">i486</a>
128 <a href="$base/cookiso.cgi">ISO</a>
129 <select onChange="window.location.href=this.value" style="display: none">
130 <option value=".">Go to…</option>
131 <option value="http://www.slitaz.org/">Home</option>
132 <option value="http://bugs.slitaz.org/">Bug tracker</option>
133 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
134 <option value="http://roadmap.slitaz.org/">Roadmap</option>
135 <option value="http://pizza.slitaz.me/">Pizza</option>
136 <option value="http://tank.slitaz.org/">Tank</option>
137 <option disabled>---------</option>
138 <option value="cross/">Cross</option>
139 <option value="i486.cgi">i486</option>
140 <option value="cookiso.cgi">ISO</option>
141 </select>
142 </div>
143 </header>
145 <main>
146 EOT
148 [ -n "$(GET debug)" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
149 }
152 # HTML page footer
154 page_footer() {
155 date_now=$(date +%s)
156 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
157 wait_sec=$(( 60 - $sec_now ))
158 cat <<EOT
159 </main>
161 <footer>
162 <a href="http://www.slitaz.org/">SliTaz Website</a>
163 <a href="$base/">Cooker</a>
164 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
165 <a href="$base/?theme">Theme</a>
166 </footer>
167 </div>
168 <script src="/cooker.js"></script>
169 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
170 </body>
171 </html>
172 EOT
173 }
176 show_note() {
177 echo "<div class='bigicon-$1'>$2</div>"
178 }
181 not_found() {
182 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
183 echo "HTTP/1.1 404 Not Found"
184 page_header
185 echo "<h2>Not Found</h2>"
186 case $2 in
187 pkg)
188 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
189 *)
190 show_note e "The requested file “$file” was not found." ;;
191 esac
192 page_footer
193 }
196 manage_modified() {
197 local file="$1" option="$2" nul day mon year time hh mm ss date_s
198 if [ ! -f "$file" ]; then
199 if [ "$option" == 'silently-absent' ]; then
200 echo "HTTP/1.1 404 Not Found"
201 return
202 else
203 not_found "$file" "$2"
204 exit
205 fi
206 fi
207 [ "$option" == 'no-last-modified' ] && return
208 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
209 echo "$HTTP_IF_MODIFIED_SINCE" | \
210 while read nul day mon year time nul; do
211 case $mon in
212 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
213 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
214 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
215 esac
216 hh=$(echo $time | cut -d: -f1)
217 mm=$(echo $time | cut -d: -f2)
218 ss=$(echo $time | cut -d: -f3)
219 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
220 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
221 # echo -e 'HTTP/1.1 304 Not Modified\n'
222 # exit
223 # fi
224 # TODO: improve caching control
225 done
226 fi
227 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
228 echo "Cache-Control: public, max-age=3600"
229 }
232 # Query '?pct=<package>': update percentage
234 if [ -n "$(GET pct)" ]; then
235 pkg="$(GET pct)"
236 state="$(cat $command)"
237 if [ "$state" == "cook:$pkg" ]; then
238 set -- $(grep "^$state" $cooktime)
239 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
240 echo "${pct:-?}"
241 else
242 echo 'reload'
243 fi
244 exit 0
245 fi
248 # Query '?poke': poke cooker
250 if [ -n "$(GET poke)" ]; then
251 touch $CACHE/cooker-request
252 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
253 exit
254 fi
257 # Query '?recook=<package>': query to recook package
259 if [ -n "$(GET recook)" ]; then
260 pkg="$(GET recook)"
261 case "$HTTP_USER_AGENT" in
262 *SliTaz*)
263 grep -qs "^$pkg$" $CACHE/recook-packages ||
264 echo "$pkg" >> $CACHE/recook-packages
265 esac
266 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
267 exit
268 fi
271 # Query '/i/<log>/<pkg>': show indicator icon
272 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
274 if [ "$pkg" == 'i' ]; then
275 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
276 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
277 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
278 else
279 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
280 fi
281 exit
282 fi
285 # Query '/s/<pkg>': show status indicator icon
286 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
288 if [ "$pkg" == 's' ]; then
289 # argument <pkg> is in $cmd variable
290 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
291 # packages.info updates with each new package, so we'll find actual info here
292 if grep -q "^$cmd"$'\t' $PKGS/packages.info; then
293 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
294 else
295 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
296 fi
297 exit
298 fi
301 # Query '?theme[=<theme>]': change UI theme
303 if [ -n "$(GET theme)" ]; then
304 theme="$(GET theme)"
305 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
306 case $theme in
307 theme)
308 current=$(COOKIE theme)
309 page_header
310 cat <<EOT
311 <section>
312 <h2>Change theme</h2>
313 <p>Current theme: “${current:-default}”. Select other:</p>
314 <ul>
315 $(
316 for i in default emerald sky goldenrod midnight like2016 terminal; do
317 [ "$i" == "${current:-default}" ] || echo "<li><a href=\"$base/?theme=$i&ref=$ref\">$i</a></li>"
318 done
319 )
320 </ul>
321 </section>
322 EOT
323 page_footer
324 exit 0
325 ;;
326 default|emerald|sky|goldenrod|midnight|like2016|terminal)
327 ref="$(GET ref)"
328 [ -n "$ref" ] || ref="$base/"
329 # Expires in a year
330 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
331 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
332 exit 0
333 ;;
334 esac
335 fi
338 #case "$QUERY_STRING" in
339 # stuff*)
340 # file="$wok/$(GET stuff)"
341 # manage_modified "$file"
342 # ;;
343 #
344 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
345 # type=${QUERY_STRING%%=*}
346 # pkg=$(GET $type)
347 # case "$type" in
348 # description)
349 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
350 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
351 # ;;
352 # log)
353 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
354 # manage_modified "$LOGS/$pkg"
355 # ;;
356 # *)
357 # manage_modified "$wok/$pkg/receipt" pkg
358 # ;;
359 # esac
360 # ;;
361 #esac
364 # RSS feed generator
365 # URI: ?rss[&limit={1..100}]
367 if [ -n "$(GET rss)" ]; then
368 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
369 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
370 cooker_url="http://$HTTP_HOST$base/"
371 cat <<EOT
372 Content-Type: application/rss+xml
374 <?xml version="1.0" encoding="utf-8" ?>
375 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
376 <channel>
377 <title>$title</title>
378 <description>The SliTaz packages cooker feed</description>
379 <link>$cooker_url</link>
380 <lastBuildDate>$pubdate</lastBuildDate>
381 <pubDate>$pubdate</pubDate>
382 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
383 EOT
384 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
385 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $rss
386 done
387 cat <<EOT
388 </channel>
389 </rss>
390 EOT
391 exit 0
392 fi
395 ### OpenSearch ###
397 # Query '/os.xml': get OpenSearch Description
399 if [ "$pkg" == 'os.xml' ]; then
400 cat <<EOT
401 Content-Type: application/xml; charset=UTF-8
403 <?xml version="1.0" encoding="UTF-8"?>
404 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
405 <ShortName>$title</ShortName>
406 <Description>SliTaz packages search</Description>
407 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
408 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
409 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
410 <Param name="oss" value="{searchTerms}"/>
411 </Url>
412 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
413 <InputEncoding>UTF-8</InputEncoding>
414 </OpenSearchDescription>
415 EOT
416 exit 0
417 fi
419 # Query '?oss[=<term>]': OpenSearch suggestions
421 if [ -n "$(GET oss)" ]; then
422 term="$(GET oss | tr -cd '[:alnum:]+-')"
423 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
424 cd $wok
425 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
426 BEGIN{printf("[\"%s\",[", term)}
427 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
428 END {printf("]]")}
429 '
430 exit 0
431 fi
436 #
437 # Functions
438 #
441 # Unpack to stdout
443 docat() {
444 case "$1" in
445 *gz) zcat ;;
446 *bz2) bzcat ;;
447 *xz) xzcat ;;
448 *) cat
449 esac < $1
450 }
453 # Tiny texinfo converter
455 info2html() {
456 sed \
457 -e 's|&|\&|g; s|<|\<|g; s|>|\>|g' \
458 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
459 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
460 -e '/^File: / s|(dir)|Top|g' \
461 -e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
462 -e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
463 -e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
464 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
465 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
466 -e '/^Tag Table:$/,/^End Tag Table$/d' \
467 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
468 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
469 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
470 -e 's|^\* Menu:|<b>Menu:</b>|' \
471 -e "s|^|</pre>|"
472 }
475 # Put some colors into log and DB files.
477 syntax_highlighter() {
478 case $1 in
479 log)
480 # If variables not defined - define them with some rare values
481 : ${_src=#_#_#}
482 : ${_install=#_#_#}
483 : ${_fs=#_#_#}
484 : ${_stuff=#_#_#}
485 # Use one-letter html tags to save some bytes :)
486 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informative (green)</i>
487 sed \
488 -e 's/&/\&/g; s/</\</g; s/>/\>/g' \
489 -e 's#OK$#<i>OK</i>#' \
490 -e 's#\([Dd]one\)$#<i>\1</i>#' \
491 -e 's#Success$#<i>Success</i>#' \
492 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
493 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
494 -e 's#: \(YES.*\)#: <i>\1</i>#' \
495 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
496 -e 's#\(enabled\)$#<i>\1</i>#' \
497 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
498 -e 's#: \(NO.*\)#: <u>\1</u>#' \
499 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
500 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
501 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
502 -e 's#\(disabled\)$#<u>\1</u>#' \
503 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
504 \
505 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
506 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
507 -e 's# y$# <i>y</i>#' \
508 -e 's# n$# <u>n</u>#' \
509 -e 's#(NEW) *$#<b>(NEW)</b>#' \
510 \
511 -e 's#.*(pkg/local).*#<i>\0</i>#' \
512 -e 's#.*(web/cache).*#<u>\0</u>#' \
513 \
514 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
515 -e 's#ERROR:#<b>ERROR:</b>#g' \
516 \
517 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
518 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
519 -e '/non-fatal/ s|</*b>||g' \
520 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
521 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
522 -e 's#^.*No package .* found.*#<b>\0</b>#' \
523 -e 's#^.*Unable to find.*#<b>\0</b>#' \
524 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
525 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
526 -e 's#\(found\.*\)$#<i>\1</i>#' \
527 \
528 -e 's#^.*WARNING:.*#<u>\0</u>#' \
529 -e 's#^.*warning:.*#<u>\0</u>#' \
530 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
531 -e 's#^.*terminated.*#<b>\0</b>#' \
532 -e 's#\(missing\)#<b>\1</b>#g' \
533 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
534 -e 's#^.*unrecognized options.*#<u>\0</u>#' \
535 -e 's#^.*does not.*#<u>\0</u>#' \
536 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
537 -e 's#^.*note:.*#<u>\0</u>#' \
538 \
539 -e 's#^.* will not .*#<u>\0</u>#' \
540 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
541 -e 's#^.* Warning: .*#<u>\0</u>#' \
542 \
543 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
544 -e "s#^Making.*#<em>\0</em>#" \
545 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
546 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
547 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
548 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
549 \
550 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
551 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
552 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
553 -e 's|^<u><b>\(.*inlining failed.*\)</b></u>|<u>\1</u>|' \
554 \
555 -e "s|$_src|<var>\${src}</var>|g;
556 s|$_install|<var>\${install}</var>|g;
557 s|$_fs|<var>\${fs}</var>|g;
558 s|$_stuff|<var>\${stuff}</var>|g" \
559 \
560 -e "s|\[\([01]\)m\[3\([1-7]\)m|<span class='c\2\1'>|g;
561 s|\[\([01]\);3\([1-7]\)m|<span class='c\2\1'>|g;
562 s|\[3\([1-7]\)m|<span class='c\10'>|g;
563 s|\[\([01]\);0m|<span class='c0\1'>|g;
564 s|\[0m|</span>|g;
565 s|\[m|</span>|g;
566 s|\[0;10m|</span>|g;
567 s|\[K||g;" \
568 \
569 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
570 s|\[39m|</span>|;
571 #s|\[1m|<span class='c01'>|g;
572 s|\[1m|<span style='font-weight:bold'>|g; s|(B|</span>|g;
573 s|\[m||g;
574 " \
575 -e "s!^|\(+.*\)!|<span class='c20'>\1</span>!;
576 s!^|\(-.*\)!|<span class='c10'>\1</span>!;
577 s!^|\(@@.*@@\)\$!|<span class='c30'>\1</span>!;"
578 \
580 ;;
582 files)
583 # Highlight the Busybox's `ls` output
584 awk '{
585 part1 = substr($0, 0, 16);
586 part2 = substr($0, 17, 9);
587 part3 = substr($0, 26, 9);
588 part4 = substr($0, 35);
589 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
590 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
591 print part1 part2 part3 part4;
592 }' | \
593 sed "s|\[0m/|/\[0m|g;
594 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
595 s|\[\([01]\);0m|<a class='c0\1'>|g;
596 s|\[0m|</a>|g;
597 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
598 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
599 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
600 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
601 s|^\([lrwxs-][lrwxs-]*\)|<span class='c11'>\1</span>|;
602 "
603 ;;
604 esac
605 }
608 show_code() {
609 echo -n "<pre><code class=\"language-$1\">"
610 sed 's|&|\&|g; s|<|\<|g; s|>|\>|g'
611 echo '</code></pre>'
612 }
615 datalist() {
616 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
617 BEGIN{printf("<datalist id=\"packages\">")}
618 {printf("<option>%s",$1)}
619 END {printf("</datalist>")}
620 '
621 }
624 mklog() {
625 awk '
626 BEGIN { printf("<pre class=\"log dog\">\n") }
627 { print }
628 END { print "</pre>" }'
629 }
632 summary() {
633 log="$1"
634 pkg="$(basename ${log%%.log*})"
636 if [ -f "$log" ]; then
637 if grep -q "cook:$pkg$" $command; then
638 show_note i "The Cooker is currently building $pkg"
639 elif fgrep -q "Summary for:" $log; then
640 sed '/^Summary for:/,$!d' $log | awk '
641 BEGIN { print "<section>" }
642 function row(line) {
643 split(line, s, " : ");
644 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
645 }
646 function row2(line, rowNum) {
647 split(line, s, " : ");
648 if (rowNum == 1) {
649 print "<thead>";
650 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]);
651 print "</thead><tbody>";
652 }
653 else
654 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]);
655 }
656 {
657 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
658 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
659 if ($0 ~ "---") {
660 seen2++;
661 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
662 next
663 }
664 if (seen2) row2($0, seen2); else row($0);
665 }
666 END { print "</tbody></table></section>" }
667 '
668 elif fgrep -q "Debug information" $log; then
669 echo -e '<section>\n<h3>Debug information</h3>'
670 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
671 if [ -n "$2" ]; then
672 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
673 else
674 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
675 fi | mklog
676 echo '</section>'
677 fi
678 else
679 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
680 fi
681 }
684 active() {
685 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
686 }
689 pkg_info() {
690 local log active bpkg short_desc=''
691 log="$LOGS/$pkg.log"
693 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
694 # Get short description for existing packages
695 [ -f $PKGS/packages.info ] &&
696 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
697 # If package does not exist (not created yet or broken), get short description
698 # (but only for "main" package) from receipt
699 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
700 echo ": $short_desc</h2>"
701 echo '<div id="info">'
702 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt & stuff</a>"
704 # In the receipts $EXTRAVERSION is defined using $kvers, get it here [copy from 'cook' set_paths()]
705 if [ -f "$wok/linux/receipt" ]; then
706 kvers=$(. $wok/linux/receipt; echo $VERSION)
707 kbasevers=$(echo $kvers | cut -d. -f1,2)
708 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
709 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
710 kbasevers=$(echo $kvers | cut -d. -f1,2)
711 fi
713 unset WEB_SITE WANTED
714 . $wok/$pkg/receipt
716 [ -n "$WEB_SITE" ] &&
717 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
719 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/receipt" ] &&
720 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
722 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
723 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
725 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
726 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
728 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
730 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
731 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
733 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
734 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
736 [ -d "$wok/$pkg/install/usr/share/info" ] &&
737 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
739 if [ -n "$LFS" ]; then
740 printf "<a class='button icon doc' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
741 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
742 printf "LFS</a>\n"
743 fi
745 [ -s "$log" ] &&
746 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
748 echo '</div>'
749 }
752 mktable() {
753 sed 's# : #|#' | awk -vc="$1" '
754 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
755 { printf("<tr><td>%s</td>", $1);
756 if (NF == 2) printf("<td>%s</td>", $2);
757 printf("</tr>\n", $2) }
758 END { print "</table>" }'
759 }
762 section() {
763 local i=$(basename "$1")
764 echo -e '\n\n<section>'
765 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
766 echo "<h2>${3%|*}</h2>"
767 mktable "$i"
768 echo '</section>'
769 }
772 show_desc() {
773 echo "<section><h3>Description of “$1”</h3>"
774 if [ -n "$md2html" ]; then
775 $md2html $2
776 else
777 show_code markdown < $2
778 fi
779 echo "</section>"
780 }
783 # Return all the names of packages bundled in this receipt
785 all_names() {
786 # Get package names from $SPLIT variable
787 local split=$(echo $SPLIT \
788 | awk '
789 BEGIN { RS = " "; FS = ":"; }
790 { print $1; }' \
791 | tr '\n' ' ')
792 local split_space=" $split "
793 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
794 # For receipts v1: $SPLIT may present in the $WANTED package,
795 # but split packages have their own receipts
796 echo $PACKAGE
797 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
798 # $PACKAGE included somewhere in $SPLIT (probably in the end).
799 # We should build packages in the order defined in the $SPLIT.
800 echo $split
801 else
802 # We'll build the $PACKAGE, then all defined in the $SPLIT.
803 echo $PACKAGE $split
804 fi
805 }
808 toolchain_version() {
809 echo "<tr><td><a href='$base/$1'>$1</a></td>"
810 awk -F$'\t' -vpkg="$1" '
811 BEGIN { version = description = "---"; }
812 {
813 if ($1 == pkg) { version = $2; description = $4; }
814 }
815 END { printf("<td>%s</td><td>%s</td></tr>", version, description); }
816 ' $PKGS/packages.info
817 }
820 files_header() {
821 echo '<section><h3>Available downloads:</h3>'
822 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
823 }
826 # Update statistics used in web interface.
827 # There is no need to recalculate the statistics every time the page is displayed.
828 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
830 update_webstat() {
831 echo '<div id="waitme">'
832 show_note i 'Please wait while statistics are being collected.'
833 echo "</div>"
835 # for receipts:
836 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
837 rcooked=$(ls -d $WOK/*/taz | wc -l)
838 runbuilt=$(($rtotal - $rcooked))
839 rblocked=$(wc -l < $blocked)
840 rbroken=$(wc -l < $broken)
842 # for packages:
843 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
844 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
845 punbuilt=$(($ptotal - $pcooked))
846 pblocked=$(
847 while read i; do
848 sed "/^$i\t/!d" $CACHE/split.db
849 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
850 pbroken=$(
851 while read i; do
852 sed "/^$i\t/!d" $CACHE/split.db
853 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
855 cat > $webstat <<EOT
856 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
857 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
858 EOT
860 echo '<script>document.getElementById("waitme").remove();</script>'
861 }
866 #
867 # Load requested page
868 #
870 if [ -z "$pkg" ]; then
872 page_header
873 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
875 for list in activity cooknotes cooklist; do
876 [ -n "$(GET $list)" ] || continue
877 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
878 echo '<section id="content2">'
879 echo "<h2>DB: $list $nb</h2>"
880 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
881 s|\[ Done|<span class="r c20">Done|;
882 s|\[ Failed|<span class="r c10">Failed|;
883 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
884 s| \]|</span>|' | mktable $list
885 echo '</section>'
886 done
888 if [ -n "$(GET broken)" ]; then
889 echo '<section id="content2">'
890 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
891 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
892 echo '</section>'
893 fi
895 case "$QUERY_STRING" in
896 *.log)
897 log=$LOGS/$QUERY_STRING
898 name=$(basename $log)
899 if [ -f "$log" ]; then
900 echo "<h2>Log for: ${name%.log}</h2>"
901 if fgrep -q "Summary" $log; then
902 echo '<pre class="log">'
903 grep -A 20 'Summary' $log | syntax_highlighter log
904 echo '</pre>'
905 fi
906 echo '<pre class="log">'
907 syntax_highlighter log < $log
908 echo '</pre>'
909 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
910 # Display button only for SliTaz web browser
911 case "$HTTP_USER_AGENT" in
912 *SliTaz*)
913 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
914 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
915 show_note i "The package database has been requested for re-creation"
916 else
917 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
918 fi
919 fi
920 ;;
921 esac
922 fi
923 else
924 show_note e "No log file: $log"
925 fi
926 ;;
927 toolchain)
928 cat <<EOT
929 <div id="content2">
930 <section>
931 <h2>SliTaz GNU/Linux toolchain</h2>
933 <table>
934 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
935 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
936 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
937 <tr><td>Host system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
938 <tr><td>Target system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
939 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
940 $(toolchain_version slitaz-toolchain)
941 $(toolchain_version binutils)
942 $(toolchain_version linux-api-headers)
943 $(toolchain_version gcc)
944 $(toolchain_version glibc)
945 </table>
947 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
948 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
949 </p>
951 </section>
952 </div>
953 EOT
954 ;;
955 esac
956 page_footer
957 exit 0
958 fi
961 # We may have a toolchain.cgi script for cross cooker's
962 if [ -f "toolchain.cgi" ]; then
963 toolchain="toolchain.cgi"
964 else
965 toolchain="?toolchain"
966 fi
968 # Main page with summary. Count only packages included in ARCH,
969 # use 'cooker arch-db' to manually create arch.$ARCH files.
971 cat <<EOT
972 <div id="content2">
974 <section>
975 <form method="get" action="" class="search r">
976 <input type="hidden" name="search" value="pkg"/>
977 <button type="submit" title="Search">Search</button>
978 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
979 </form>
981 <h2>Summary</h2>
982 EOT
984 mktable <<EOT
985 Cooker state : $(running_command)
986 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
987 Commits to cook : $(wc -l < $commits)
988 Current cooklist : $(wc -l < $cooklist)
989 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
990 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
991 EOT
993 # If command is "cook:*", update gauge and percentage periodically.
994 # If different package is cooking, reload the page (with new settings)
995 cmd="$(cat $command)"
996 case "$cmd" in
997 cook:*)
998 pkg=${cmd#*:}
999 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
1000 ;;
1001 esac
1003 # Do we need to update the statistics?
1004 [ "$webstat" -nt "$activity" ] || update_webstat
1005 . $webstat
1007 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
1009 cat <<EOT
1010 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
1012 <table class="webstat"><thead>
1013 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
1014 </thead><tbody>
1015 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
1016 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
1017 </tbody></table>
1018 EOT
1020 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1021 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1022 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1023 else
1024 show_note i 'Cooker will be launched in the next 5 minutes.'
1025 fi
1026 fi
1028 cat <<EOT
1029 <p>
1030 Service logs:
1031 <a href="?cookorder.log">cookorder</a> ·
1032 <a href="?commits.log">commits</a> ·
1033 <a href="?pkgdb.log">pkgdb</a>
1034 </p>
1035 </section>
1036 EOT
1038 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
1039 s|\[ Done|<span class="r c20">Done|;
1040 s|\[ Failed|<span class="r c10">Failed|;
1041 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1042 s| \]|</span>|;
1043 s|%2B|\+|g' | \
1044 section $activity 12 "Activity|More activity"
1046 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
1047 section $cooknotes 12 "Cooknotes|More notes"
1049 [ -s "$commits" ] &&
1050 section $commits 20 "Commits|More commits" < $commits
1052 [ -s "$cooklist" ] && head -n 20 $cooklist | \
1053 section $cooklist 20 "Cooklist|Full cooklist"
1055 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
1056 section $broken 20 "Broken|All broken packages"
1058 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
1059 section $blocked 12 "Blocked|All blocked packages"
1061 cd $PKGS
1062 # About BusyBox's `ls`
1063 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
1064 # It supported the option `-e`, output with `-let` options like this:
1065 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
1066 # 1 2 3 4 5 6 7 8 9 10 11
1067 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
1068 # configure it or return the option back. It supported the long option
1069 # `--full-time` instead, but output is different:
1070 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
1071 # 1 2 3 4 5 6 7 8 9
1072 if ls -let >/dev/null 2>&1; then
1073 ls -let *.tazpkg \
1074 | awk '
1075 (NR<=20){
1076 sub(/:[0-9][0-9]$/, "", $9);
1077 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
1078 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
1079 }' \
1080 | section $activity 1000 "Latest cook"
1081 else
1082 ls -lt --full-time *.tazpkg \
1083 | awk '
1084 (NR<=20){
1085 sub(/:[0-9][0-9]$/, "", $7);
1086 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
1087 }' \
1088 | section $activity 1000 "Latest cook"
1089 fi
1091 echo '</div>'
1092 datalist
1093 page_footer
1094 exit 0
1095 fi
1098 # show tag
1100 if [ "$pkg" == '~' -a -n "$cmd" ]; then
1101 tag="$cmd"
1102 page_header
1103 cat <<EOT
1104 <div id="content2">
1105 <section>
1106 <h2>Tag “$tag”</h2>
1108 <table>
1109 <thead>
1110 <tr><th>Name</th><th>Description</th><th>Category</th></tr>
1111 </thead>
1112 <tbody>
1113 EOT
1114 sort $PKGS/packages.info \
1115 | awk -F$'\t' -vtag=" $tag " -vbase="$base" '{
1116 if (index(" " $6 " ", tag)) {
1117 url = base "/" $1 "/";
1118 gsub("+", "%2B", url);
1119 printf("<tr><td><img src=\"%s/s/%s\"> ", base, $1);
1120 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1121 }
1122 }'
1123 echo '</tbody></table></section></div>'
1124 page_footer
1125 exit 0
1126 fi
1129 case "$cmd" in
1130 '')
1131 page_header
1133 requested_pkg="$pkg"
1134 # Package info.
1135 if [ ! -f "$wok/$pkg/receipt" ]; then
1136 # Let's look at the cases when the package was not found
1138 # Maybe query is the exact name of split package? -> proceed to main package
1139 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1140 if (index(" " $2 " ", pkg)) {print $1; exit}
1141 }' $splitdb)
1143 # No, so let's find any matches among packages names (both main and split)
1144 if [ -z "$mainpkg" ]; then
1145 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1146 # Nothing matched
1147 if [ -z "$pkgs" ]; then
1148 echo "<h2>Not Found</h2>"
1149 show_note e "The requested package <b>$pkg</b> was not found on this server."
1150 page_footer; exit 0
1151 fi
1152 # Search results page
1153 echo "<section><h2>Package names matching “$pkg”</h2>"
1154 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1155 query="$pkg"
1156 for pkg in $pkgs; do
1157 # Find main package
1158 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1159 if (index(" " $2 " ", pkg)) {print $1; exit}
1160 }' $splitdb)
1161 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1163 unset SHORT_DESC CATEGORY
1164 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1165 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1167 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1168 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1169 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1170 done
1171 echo '</tbody></table></section>'
1172 page_footer; exit 0
1173 fi
1174 pkg="$mainpkg"
1175 fi
1177 log=$LOGS/$pkg.log
1178 pkg_info
1180 # Check for a log file and display summary if it exists.
1181 summary "$log"
1184 # Show tag list
1185 taglist=$(
1186 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1187 [ -s "$PKGS/packages.info" ] &&
1188 awk -F$'\t' -vpkg="$i" '{
1189 if ($1 == pkg) { print $6; exit; }
1190 }' "$PKGS/packages.info"
1191 done \
1192 | tr ' ' '\n' \
1193 | sort -u
1194 )
1195 if [ -n "$taglist" ]; then
1196 echo -n '<section><h3>Tags</h3><p>'
1197 lasttag=$(echo "$taglist" | tail -n1)
1198 for tag in $taglist; do
1199 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1200 [ "$tag" != "$lasttag" ] && echo -n " · "
1201 done
1202 echo '</p></section>'
1203 fi
1206 # Informational table with dependencies
1207 pkg="$requested_pkg"
1208 inf="$(mktemp -d)"
1210 # 1/3: Build dependencies (from receipt and pkgdb)
1211 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1212 echo "$i" >> $inf/a
1213 done
1215 # 2/3: Runtime dependencies (from pkgdb)
1216 {
1217 [ -s "$PKGS/packages.info" ] &&
1218 awk -F$'\t' -vp="$pkg" '{
1219 if ($1 == p) print $8
1220 }' "$PKGS/packages.info"
1221 } | tr ' ' '\n' | sort -u > $inf/b
1223 # 3/3: Required by (from pkgdb)
1224 {
1225 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1226 [ -s "$PKGS/packages.info" ] &&
1227 awk -F$'\t' -vp=" $i " '{
1228 if (index(" " $8 " ", p)) print $1
1229 }' "$PKGS/packages.info"
1231 [ -s "$PKGS/bdeps.txt" ] &&
1232 awk -F$'\t' -vp=" $i " '{
1233 if (index(" " $2 " ", p)) print $1
1234 }' $PKGS/bdeps.txt
1235 done
1236 } | sort -u > $inf/c
1238 cat <<EOT
1239 <section>
1240 <h3>Related packages</h3>
1241 <table class="third">
1242 <thead>
1243 <tr>
1244 <th>Build dependencies</th>
1245 <th>Runtime dependencies</th>
1246 <th>Required by</th>
1247 </tr>
1248 </thead>
1249 <tbody>
1250 EOT
1252 awk -vinf="$inf" -vbase="$base" '
1253 function linki(i) {
1254 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1255 }
1256 BEGIN{
1257 do {
1258 a = b = c = "";
1259 getline a < inf "/a";
1260 getline b < inf "/b";
1261 getline c < inf "/c";
1262 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1263 } while ( a b c )
1264 }'
1265 cat <<EOT
1266 </tbody>
1267 </table>
1268 </section>
1269 EOT
1270 # Clean
1271 rm -r $inf
1276 # Display <Recook> button only for SliTaz web browser
1277 case "$HTTP_USER_AGENT" in
1278 *SliTaz*)
1279 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1280 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1281 show_note i "The package “$pkg” has been requested for recook"
1282 else
1283 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1284 fi
1285 fi
1286 ;;
1287 esac
1288 ;;
1290 receipt)
1291 page_header
1292 pkg_info
1293 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1294 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1295 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1297 show_code bash < $wok/$pkg/receipt
1298 ;;
1300 stuff)
1301 page_header
1302 pkg_info
1303 file="$pkg/stuff/$arg"
1304 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1305 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1306 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1307 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1308 }'
1310 if [ -f "$wok/$file" ]; then
1311 case $file in
1312 *.desktop|*.theme) class="ini" ;;
1313 *.patch|*.diff|*.u) class="diff" ;;
1314 *.sh) class="bash" ;;
1315 *.conf*|*.ini)
1316 class="bash"
1317 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1318 ;;
1319 *.pl) class="perl" ;;
1320 *.c|*.h|*.awk) class="clike" ;;
1321 *.svg) class="svg" ;;
1322 *Makefile*) class="makefile" ;;
1323 *.po|*.pot) class="bash" ;;
1324 *.css) class="css" ;;
1325 *.htm|*.html) class="html" ;;
1326 *.js) class="js" ;;
1327 *.txt) class="asciidoc" ;;
1328 *)
1329 case $(head -n1 $wok/$file) in
1330 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1331 esac
1332 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1333 class="bash"
1334 fi
1335 if [ -z "$class" ]; then
1336 # Follow Busybox restrictions. Search for non-printable chars
1337 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1338 raw="true"
1339 fi
1340 fi
1341 ;;
1342 esac
1344 # Display image
1345 case $file in
1346 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1347 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1348 ;;
1349 esac
1351 # Display colored listing for all text-based documents (also for *.svg)
1352 case $file in
1353 *.png|*.jpg|*.jpeg|*.ico) ;;
1354 *)
1355 if [ -z "$raw" ]; then
1356 cat $wok/$file | show_code $class
1357 fi
1358 ;;
1359 esac
1361 # Display hex dump for binary files
1362 if [ -n "$raw" ]; then
1363 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1364 fi
1365 else
1366 show_note e "File “$file” absent!"
1367 fi
1368 ;;
1370 files)
1371 page_header
1372 pkg_info
1374 # find main package
1375 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1376 main=${wanted:-$pkg}
1377 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1379 splitsets=$(echo $SPLIT" " \
1380 | awk '
1381 BEGIN { RS = " "; FS = ":"; }
1382 { print $2; }' \
1383 | sort -u \
1384 | tr '\n' ' ' \
1385 | sed 's|^ *||; s| *$||')
1387 splitpkgs=$(echo $SPLIT" " \
1388 | awk '
1389 BEGIN { RS = " "; FS = ":"; }
1390 { print $1; }' \
1391 | tr '\n' ' ' \
1392 | sed 's|^ *||; s| *$||')
1394 # we need the version
1395 if [ -f "$WOK/linux/receipt" ]; then
1396 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1397 kbasevers=$(echo $kvers | cut -d. -f1,2)
1398 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1399 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1400 kbasevers=$(echo $kvers | cut -d. -f1,2)
1401 fi
1402 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1404 echo "<section><h3>Quick jump:</h3>"
1407 for part in head body; do
1409 for set in '' $splitsets; do
1410 pkgsofset=$(echo $SPLIT" " \
1411 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1412 BEGIN {
1413 RS = " "; FS = ":";
1414 if (!set) print main;
1415 if (!set && dev) print dev;
1416 }
1417 {
1418 if ($2 == set) print $1;
1419 }' \
1420 | sort -u)
1422 set_description=''
1423 [ -n "$splitsets" ] &&
1424 case "$set" in
1425 '')
1426 set_description=' (default set)'
1427 set_title='Default set'
1428 ;;
1429 *)
1430 set_description=" (set “$set”)"
1431 set_title="Set “$set”"
1432 ;;
1433 esac
1435 install="$wok/$main/install"
1436 [ -n "$set" ] && install="$install-$set"
1438 case $part in
1439 head)
1440 [ -n "$splitsets" ] &&
1441 case "$set" in
1442 '') echo "<ul><li>Default set:";;
1443 *) echo "<li>Set “$set”:";;
1444 esac
1445 echo -e '\t<ul>'
1446 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1447 cat <<EOT
1448 <li id='li-repeats$set' style='display:none'>
1449 <a href='#repeats$set'>repeatedly packaged files</a></li>
1450 <li id='li-empty$set' style='display:none'>
1451 <a href='#empty$set'>unpackaged empty folders</a></li>
1452 <li id='li-outoftree$set' style='display:none'>
1453 <a href='#outoftree$set'>out-of-tree files</a></li>
1454 <li id='li-orphans$set' style='display:none'>
1455 <a href='#orphans$set'>unpackaged files</a>
1456 <span id='orphansTypes$set'></span></li>
1457 EOT
1458 echo -e '\t</ul>'
1459 [ -n "$splitsets" ] && echo "</li>"
1460 ;;
1461 body)
1462 all_files=$(mktemp)
1463 cd $install; find ! -type d | sed 's|\.||' > $all_files
1465 # ------------------------------------------------------
1466 # Packages content
1467 # ------------------------------------------------------
1468 packaged=$(mktemp)
1469 for p in $pkgsofset; do
1470 namever="$(awk -F$'\t' -vp="$p" '{
1471 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
1472 }' $PKGS/packages.info)"
1473 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1474 indir=$p
1475 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1476 indir=$main
1477 fi
1478 dir="$wok/$indir/taz/$p-$ver/fs"
1480 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1482 echo
1483 echo "<section id='$p'>"
1484 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
1485 echo ' <pre class="files">'
1486 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1487 echo -en '<span class="underline">permissions·lnk·user ·group · size·date & time ·name\n</span>'
1488 cd $dir
1489 find . -print0 \
1490 | sort -z \
1491 | xargs -0 ls -ldp --color=always \
1492 | syntax_highlighter files \
1493 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
1494 | awk 'BEGIN { FS="\""; }
1495 { gsub("+", "%2B", $2); print; }'
1496 else
1497 echo 'No files'
1498 fi
1499 echo '</pre>'
1500 echo '</section>'
1502 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1503 done
1504 # ------------------------------------------------------
1505 # /Packages content
1506 # ------------------------------------------------------
1508 # ------------------------------------------------------
1509 # Repeatedly packaged files
1510 # ------------------------------------------------------
1511 repeats=$(mktemp)
1512 sort $packaged | uniq -d > $repeats
1513 if [ -s "$repeats" ]; then
1514 echo
1515 echo "<script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>"
1516 echo "<section id='repeats$set'>"
1517 echo " <h3>Repeatedly packaged files$set_description:</h3>"
1518 cd $install
1520 IFS=$'\n'
1521 echo -n ' <pre class="files">'
1522 echo -en '<span class="underline">permissions·lnk·user ·group · size·date & time ·name\n</span>'
1523 while read i; do
1524 find .$i -exec ls -ldp --color=always '{}' \; \
1525 | syntax_highlighter files \
1526 | sed 's|>\./|>/|'
1527 done < $repeats
1528 echo '</pre>'
1529 echo '</section>'
1530 unset IFS
1531 fi
1532 rm $repeats
1533 # ------------------------------------------------------
1534 # /Repeatedly packaged files
1535 # ------------------------------------------------------
1537 # ------------------------------------------------------
1538 # Unpackaged empty folders
1539 # ------------------------------------------------------
1540 emptydirs=$(mktemp)
1541 cd $install
1542 IFS=$'\n'
1543 find -type d \
1544 | sed 's|\.||' \
1545 | while read d; do
1546 [ -z "$(ls "$install$d")" ] || continue
1547 # empty dir determined by empty `ls`
1548 echo $d
1549 done \
1550 | while read d; do
1551 notfound='yes'
1552 for p in $(cd $wok/$main/taz; ls); do
1553 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1554 notfound=''
1555 break
1556 fi
1557 done
1558 [ -n "$notfound" ] &&
1559 ls -ldp --color=always .$d \
1560 | syntax_highlighter files \
1561 | sed 's|>\./|>/|'
1562 done > $emptydirs
1563 unset IFS
1564 if [ -s "$emptydirs" ]; then
1565 echo
1566 echo "<script>document.getElementById('li-empty$set').style.display = 'list-item'</script>"
1567 echo "<section id='empty$set'>"
1568 echo " <h3>Unpackaged empty folders$set_description:</h3>"
1569 echo -n ' <pre class="files">'
1570 echo -en '<span class="underline">permissions·lnk·user ·group · size·date & time ·name\n</span>'
1571 cat $emptydirs
1572 echo '</pre>'
1573 echo '</section>'
1574 fi
1575 rm $emptydirs
1576 # ------------------------------------------------------
1577 # /Unpackaged empty folders
1578 # ------------------------------------------------------
1580 # ------------------------------------------------------
1581 # Out-of-tree files
1582 # ------------------------------------------------------
1583 outoftree=$(mktemp)
1584 awk -F$'\n' -vall="$all_files" '
1585 {
1586 if (FILENAME == all) files_all[$1] = "1";
1587 else files_pkg[$1] = "1";
1588 }
1589 END {
1590 for (i in files_pkg) {
1591 if (! files_all[i]) print i;
1592 }
1593 }
1594 ' "$all_files" "$packaged" > $outoftree
1596 if [ -d "$install" -a -s "$outoftree" ]; then
1597 echo
1598 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
1599 echo "<section id='outoftree$set'>"
1600 echo " <h3>Out-of-tree files$set_description:</h3>"
1601 echo -n ' <pre class="files">'
1602 echo -en '<span class="underline">permissions·lnk·user ·group · size·date & time ·name\n</span>'
1603 IFS=$'\n'
1604 while read outoftree_line; do
1605 # Find the package out-of-tree file belongs to
1606 for i in $pkgsofset; do
1607 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
1608 cd $wok/$main/taz/$i-$ver/fs
1609 ls -ldp --color=always ".$outoftree_line" \
1610 | syntax_highlighter files \
1611 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
1612 | awk 'BEGIN { FS="\""; }
1613 { gsub("+", "%2B", $2); print; }'
1614 fi
1615 done
1616 done < $outoftree
1617 unset IFS
1618 echo '</pre>'
1619 echo '</section>'
1620 fi
1621 rm $outoftree
1622 # ------------------------------------------------------
1623 # /Out-of-tree files
1624 # ------------------------------------------------------
1626 # ------------------------------------------------------
1627 # Unpackaged files
1628 # ------------------------------------------------------
1629 orphans=$(mktemp)
1630 awk -F$'\n' -vall="$all_files" '
1631 {
1632 if (FILENAME == all) files_all[$1] = "1";
1633 else files_pkg[$1] = "1";
1634 }
1635 END {
1636 for (i in files_all) {
1637 if (! files_pkg[i]) print i;
1638 }
1639 }
1640 ' "$all_files" "$packaged" | sort > $orphans
1641 if [ -d "$install" -a -s "$orphans" ]; then
1642 echo
1643 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
1644 echo "<section id='orphans$set'>"
1645 echo " <h3>Unpackaged files$set_description:</h3>"
1646 table=$(mktemp)
1647 awk '
1648 function tag(text, color) {
1649 printf("<span class=\"c%s1\">%s</span> ", color, text);
1650 printf("%s\n", $0);
1651 }
1652 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
1653 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
1654 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
1655 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ {
1656 tag("---", 0); next }
1657 /\.pod$/ { tag("pod", 5); next }
1658 /\/share\/man\// { tag("man", 5); next }
1659 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1660 /\/share\/devhelp\// { tag("doc", 5); next }
1661 /\/share\/icons\// { tag("ico", 2); next }
1662 /\/share\/locale\// { tag("loc", 4); next }
1663 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1664 /\/Makefile.*$/ { tag("dev", 3); next }
1665 /\/share\/help\// || /\/share\/appdata\// { tag("gnm", 6); next }
1666 { tag("???", 1) }
1667 ' "$orphans" > $table
1669 # Summary table
1670 orphans_types='()'
1671 for i in head body; do
1672 case $i in
1673 head) echo -n '<table class="summary"><tr>';;
1674 body) echo -n '<th> </th></tr><tr>';;
1675 esac
1676 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1677 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1678 case $i in
1679 head) echo -n "<th class='$class'>$tag</th>";;
1680 body)
1681 tagscount="$(grep ">$tag<" $table | wc -l)"
1682 printf '<td>%s</td>' "$tagscount"
1683 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1684 ;;
1685 esac
1686 done
1687 done
1688 echo '<td> </td></tr></table>'
1689 orphans_types="${orphans_types/( /(}"
1690 [ "$orphans_types" != '()' ] &&
1691 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
1693 suffix=''; [ -n "$set" ] && suffix="-$set"
1694 echo -n ' <pre class="files">'
1695 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date & time ·name\n</span>'
1696 IFS=$'\n'
1697 while read orphan_line; do
1698 echo -n "${orphan_line/span> */span>} "
1699 cd $install
1700 ls -ldp --color=always ".${orphan_line#*</span> }" \
1701 | syntax_highlighter files \
1702 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
1703 | awk 'BEGIN { FS="\""; }
1704 { gsub("+", "%2B", $2); print; }'
1705 done < $table
1706 unset IFS
1707 echo '</pre>'
1708 echo '</section>'
1709 rm $table
1710 fi
1711 rm $orphans
1712 # ------------------------------------------------------
1713 # /Unpackaged files
1714 # ------------------------------------------------------
1716 rm $all_files $packaged
1717 ;;
1718 esac
1719 done # /set
1721 case "$part" in
1722 head)
1723 [ -n "$splitsets" ] && echo "</ul>"
1724 echo "</section>"
1725 ;;
1726 esac
1727 done # /part
1729 ;;
1731 description)
1732 page_header
1733 pkg_info
1734 descs="$(ls $WOK/$pkg/description*.txt)"
1735 if [ -n "$descs" ]; then
1736 echo '<div id="content2">'
1737 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1738 for i in $descs; do
1739 case $i in
1740 */description.txt) continue ;;
1741 *) package=$(echo $i | cut -d. -f2) ;;
1742 esac
1743 show_desc "$package" "$i"
1744 done
1745 echo '</div>'
1746 else
1747 show_note w "No description of $pkg"
1748 fi
1749 ;;
1751 log)
1752 page_header
1753 pkg_info
1754 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1756 echo '<div class="btnList">'
1757 acc='l' # access key for the latest log is 'L'
1758 while read log; do
1759 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1760 timestamp=$(stat -c %Y $log)
1761 class=''
1762 if [ "$arg" == "$timestamp" ]; then
1763 class=' log'
1764 logfile="$log"
1765 fi
1766 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1767 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1768 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1769 case $acc in
1770 l) acc=0;;
1771 *) acc=$((acc+1));;
1772 esac
1773 done <<EOT
1774 $(find $LOGS -name "$pkg.log*" | sort)
1775 $(find $LOGS -name "$pkg-pack.log")
1776 EOT
1777 echo '</div>'
1779 if [ -z "$logfile" ]; then
1780 show_note e "Requested log is absent"
1781 page_footer
1782 exit 0
1783 fi
1785 # Define cook variables for syntax highlighter
1786 if [ -s "$WOK/$pkg/receipt" ]; then
1787 . "$WOK/$pkg/receipt"
1788 _wok='/home/slitaz/wok'
1789 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1790 _install="$_wok/$pkg/install"
1791 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1792 _stuff="$_wok/$pkg/stuff"
1793 fi
1795 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1796 # {
1797 # summary "$logfile" links
1798 #
1799 # syntax_highlighter log < $logfile | awk '
1800 # BEGIN { print "<pre class=\"log\">"; }
1801 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1802 # END { print "</pre>"; }
1803 # '
1804 #
1805 # page_footer
1806 # } | gzip > gzlog/$pkg.$arg
1807 # fi
1809 blog=$(basename $logfile)
1810 summary "$logfile" links
1812 # disable next `sed` for the 'like2016' theme
1813 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1814 cat $logfile | syntax_highlighter log | \
1815 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1816 awk '
1817 BEGIN { print "<pre class=\"log\">"; }
1818 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
1819 END { print "</pre>"; }
1820 '
1821 ;;
1824 man|doc|info)
1825 page_header
1826 pkg_info
1827 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1829 dir="wok/$pkg/install/usr/share/$cmd"
1830 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1831 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1832 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1833 [ -n "$try" ] && arg="$try"
1834 fi
1835 while read i; do
1836 [ -s "$i" ] || continue
1837 case "$i" in
1838 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1839 esac
1840 i=${i#$dir/}
1841 [ -n "$arg" ] || arg="$i"
1842 class=''; [ "$arg" == "$i" ] && class=" doc"
1843 case "$cmd" in
1844 man)
1845 case $i in
1846 man*) lang='';;
1847 *) lang="${i%%/*}: ";;
1848 esac
1849 man=$(basename $i .gz)
1850 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1851 ;;
1852 doc)
1853 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1854 ;;
1855 info)
1856 info=$(basename $i)
1857 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1858 ;;
1859 esac
1860 done <<EOT
1861 $(for i in $dir; do find $i -type f; done | sort)
1862 EOT
1863 echo '</div>'
1865 [ -f "$arg" ] || arg="$dir/$arg"
1866 if [ -f "$arg" ]; then
1867 tmp="$(mktemp)"
1868 docat "$arg" > $tmp
1869 [ -s "$tmp" ] &&
1870 case "$cmd" in
1871 info)
1872 echo '<div id="content2" class="texinfo"><pre class="first">'
1873 info2html < "$tmp"
1874 echo '</pre></div>'
1875 ;;
1876 doc)
1877 case "$arg" in
1878 *.sgml|*.devhelp2) class='xml';;
1879 *.py) class='python';; # pycurl package
1880 *.css) class='css';;
1881 *.sh) class='bash';;
1882 *)
1883 first=$(head -n1 "$tmp")
1884 if [ "${first:0:1}" == '#' ]; then
1885 class='bash' # first line begins with '#'
1886 else
1887 class='asciidoc'
1888 fi;;
1889 esac
1890 case "$arg" in
1891 *.htm*)
1892 case $arg in
1893 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1894 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1895 esac
1896 # make the iframe height so long to contain its contents without scrollbar
1897 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1898 ;;
1899 *.pdf)
1900 case $arg in
1901 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1902 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1903 esac
1904 cat <<EOT
1905 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1906 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1907 </object>
1908 EOT
1909 ;;
1910 *.md|*.markdown)
1911 echo '<section>'
1912 $md2html "$tmp"
1913 echo '</section>'
1914 ;;
1915 *)
1916 show_code $class < "$tmp"
1917 ;;
1918 esac
1919 ;;
1920 man)
1921 #export TEXTDOMAIN='man2html'
1922 echo "<div id='content2'>"
1924 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1925 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1926 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1928 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1929 # Process the pre-formatted man-cat page
1930 # (for example see sudo package without groff in build dependencies)
1931 sed -i '
1932 s|M-bM-^@M-^S|—|g;
1933 s|M-bM-^@M-^\\|<b>|g;
1934 s|M-bM-^@M-^]|</b>|g
1935 s|M-bM-^@M-^X|<u>|g;
1936 s|M-bM-^@M-^Y|</u>|g;
1937 s|M-BM-||g;
1938 s|++oo|•|g;
1939 s|&|\&|g; s|<|\<|g; s|>|\>|g;
1940 ' "$tmp"
1941 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 \
1942 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 \
1943 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
1944 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
1945 done
1946 echo '<pre class="catman">'
1947 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
1948 echo '</pre>'
1949 else
1950 echo "$html"
1951 fi
1952 echo "</div>"
1953 ;;
1954 esac
1955 rm -f $tmp
1956 else
1957 show_note e "File “$arg” does not exist!"
1958 fi
1959 ;;
1961 download)
1962 page_header
1963 pkg_info
1964 show=0
1966 . $wok/$pkg/receipt
1968 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
1969 files_header
1970 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
1971 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
1972 echo "<td>Sources for building the package “$pkg”</td></tr>"
1973 show=1
1974 fi
1976 if [ -d "$wok/$pkg/taz" ]; then
1977 [ "$show" -eq 1 ] || files_header
1979 common_version=$VERSION
1980 for i in $(all_names); do
1981 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
1982 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
1984 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
1985 [ -f "$PKGS/$filename" ] &&
1986 cat <<EOT
1987 <tr>
1988 <td><a href="$base/get/$filename">$filename</a></td>
1989 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
1990 <td>$SHORT_DESC</td>
1991 </tr>
1992 EOT
1993 done
1994 done
1995 show=1
1996 fi
1998 if [ "$show" -eq 1 ]; then
1999 echo '</tbody></table></section>'
2000 else
2001 show_note w "Sorry, there's nothing to download…"
2002 fi
2003 ;;
2005 esac
2008 page_footer
2009 exit 0