cookutils view lighttpd/index.cgi @ rev 1059
modules/pkgdb: provide "atomic" update now
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Tue May 29 04:09:44 2018 +0300 (2018-05-29) |
parents | ea288d4f994f |
children | 45a7e146df74 |
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#\([^a-z]\)no$#\1<u>no</u>#' \
497 -e 's#: \(NO.*\)#: <u>\1</u>#' \
498 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
499 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
500 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
501 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
502 \
503 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
504 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
505 -e 's# y$# <i>y</i>#' \
506 -e 's# n$# <u>n</u>#' \
507 -e 's#(NEW) *$#<b>(NEW)</b>#' \
508 \
509 -e 's#.*(pkg/local).*#<i>\0</i>#' \
510 -e 's#.*(web/cache).*#<u>\0</u>#' \
511 \
512 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
513 -e 's#ERROR:#<b>ERROR:</b>#g' \
514 \
515 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
516 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
517 -e '/non-fatal/ s|</*b>||g' \
518 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
519 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
520 -e 's#^.*No package .* found.*#<b>\0</b>#' \
521 -e 's#^.*Unable to find.*#<b>\0</b>#' \
522 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
523 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
524 -e 's#\(found\.*\)$#<i>\1</i>#' \
525 \
526 -e 's#^.*WARNING:.*#<u>\0</u>#' \
527 -e 's#^.*warning:.*#<u>\0</u>#' \
528 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
529 -e 's#^.*terminated.*#<b>\0</b>#' \
530 -e 's#\(missing\)#<b>\1</b>#g' \
531 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
532 -e 's#^.*unrecognized options.*#<u>\0</u>#' \
533 -e 's#^.*does not.*#<u>\0</u>#' \
534 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
535 -e 's#^.*note:.*#<u>\0</u>#' \
536 \
537 -e 's#^.* will not .*#<u>\0</u>#' \
538 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
539 -e 's#^.* Warning: .*#<u>\0</u>#' \
540 \
541 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
542 -e "s#^Making.*#<em>\0</em>#" \
543 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
544 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
545 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
546 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
547 \
548 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
549 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
550 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
551 -e 's|^<u><b>\(.*inlining failed.*\)</b></u>|<u>\1</u>|' \
552 \
553 -e "s|$_src|<var>\${src}</var>|g;
554 s|$_install|<var>\${install}</var>|g;
555 s|$_fs|<var>\${fs}</var>|g;
556 s|$_stuff|<var>\${stuff}</var>|g" \
557 \
558 -e "s|\[\([01]\)m\[3\([1-7]\)m|<span class='c\2\1'>|g;
559 s|\[\([01]\);3\([1-7]\)m|<span class='c\2\1'>|g;
560 s|\[3\([1-7]\)m|<span class='c\10'>|g;
561 s|\[\([01]\);0m|<span class='c0\1'>|g;
562 s|\[0m|</span>|g;
563 s|\[m|</span>|g;
564 s|\[0;10m|</span>|g;
565 s|\[K||g;" \
566 \
567 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
568 s|\[39m|</span>|;
569 #s|\[1m|<span class='c01'>|g;
570 s|\[1m|<span style='font-weight:bold'>|g; s|(B|</span>|g;
571 s|\[m||g;
572 " \
573 -e "s!^|\(+.*\)!|<span class='c20'>\1</span>!;
574 s!^|\(-.*\)!|<span class='c10'>\1</span>!;
575 s!^|\(@@.*@@\)\$!|<span class='c30'>\1</span>!;"
576 \
578 ;;
580 files)
581 # Highlight the Busybox's `ls` output
582 awk '{
583 part1 = substr($0, 0, 16);
584 part2 = substr($0, 17, 9);
585 part3 = substr($0, 26, 9);
586 part4 = substr($0, 35);
587 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
588 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
589 print part1 part2 part3 part4;
590 }' | \
591 sed "s|\[0m/|/\[0m|g;
592 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
593 s|\[\([01]\);0m|<a class='c0\1'>|g;
594 s|\[0m|</a>|g;
595 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
596 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
597 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
598 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
599 s|^\([lrwxs-][lrwxs-]*\)|<span class='c11'>\1</span>|;
600 "
601 ;;
602 esac
603 }
606 show_code() {
607 echo -n "<pre><code class=\"language-$1\">"
608 sed 's|&|\&|g; s|<|\<|g; s|>|\>|g'
609 echo '</code></pre>'
610 }
613 datalist() {
614 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
615 BEGIN{printf("<datalist id=\"packages\">")}
616 {printf("<option>%s",$1)}
617 END {printf("</datalist>")}
618 '
619 }
622 mklog() {
623 awk '
624 BEGIN { printf("<pre class=\"log dog\">\n") }
625 { print }
626 END { print "</pre>" }'
627 }
630 summary() {
631 log="$1"
632 pkg="$(basename ${log%%.log*})"
634 if [ -f "$log" ]; then
635 if grep -q "cook:$pkg$" $command; then
636 show_note i "The Cooker is currently building $pkg"
637 elif fgrep -q "Summary for:" $log; then
638 sed '/^Summary for:/,$!d' $log | awk '
639 BEGIN { print "<section>" }
640 function row(line) {
641 split(line, s, " : ");
642 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
643 }
644 function row2(line, rowNum) {
645 split(line, s, " : ");
646 if (rowNum == 1) {
647 print "<thead>";
648 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]);
649 print "</thead><tbody>";
650 }
651 else
652 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]);
653 }
654 {
655 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
656 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
657 if ($0 ~ "---") {
658 seen2++;
659 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
660 next
661 }
662 if (seen2) row2($0, seen2); else row($0);
663 }
664 END { print "</tbody></table></section>" }
665 '
666 elif fgrep -q "Debug information" $log; then
667 echo -e '<section>\n<h3>Debug information</h3>'
668 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
669 if [ -n "$2" ]; then
670 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
671 else
672 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
673 fi | mklog
674 echo '</section>'
675 fi
676 else
677 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
678 fi
679 }
682 active() {
683 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
684 }
687 pkg_info() {
688 local log active bpkg short_desc=''
689 log="$LOGS/$pkg.log"
691 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
692 # Get short description for existing packages
693 [ -f $PKGS/packages.info ] &&
694 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
695 # If package does not exist (not created yet or broken), get short description
696 # (but only for "main" package) from receipt
697 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
698 echo ": $short_desc</h2>"
699 echo '<div id="info">'
700 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt & stuff</a>"
702 # In the receipts $EXTRAVERSION is defined using $kvers, get it here [copy from 'cook' set_paths()]
703 if [ -f "$wok/linux/receipt" ]; then
704 kvers=$(. $wok/linux/receipt; echo $VERSION)
705 kbasevers=$(echo $kvers | cut -d. -f1,2)
706 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
707 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
708 kbasevers=$(echo $kvers | cut -d. -f1,2)
709 fi
711 unset WEB_SITE WANTED
712 . $wok/$pkg/receipt
714 [ -n "$WEB_SITE" ] &&
715 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
717 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/receipt" ] &&
718 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
720 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
721 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
723 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
724 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
726 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
728 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
729 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
731 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
732 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
734 [ -d "$wok/$pkg/install/usr/share/info" ] &&
735 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
737 if [ -n "$LFS" ]; then
738 printf "<a class='button icon doc' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
739 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
740 printf "LFS</a>\n"
741 fi
743 [ -s "$log" ] &&
744 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
746 echo '</div>'
747 }
750 mktable() {
751 sed 's# : #|#' | awk -vc="$1" '
752 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
753 { printf("<tr><td>%s</td>", $1);
754 if (NF == 2) printf("<td>%s</td>", $2);
755 printf("</tr>\n", $2) }
756 END { print "</table>" }'
757 }
760 section() {
761 local i=$(basename "$1")
762 echo -e '\n\n<section>'
763 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
764 echo "<h2>${3%|*}</h2>"
765 mktable "$i"
766 echo '</section>'
767 }
770 show_desc() {
771 echo "<section><h3>Description of “$1”</h3>"
772 if [ -n "$md2html" ]; then
773 $md2html $2
774 else
775 show_code markdown < $2
776 fi
777 echo "</section>"
778 }
781 # Return all the names of packages bundled in this receipt
783 all_names() {
784 # Get package names from $SPLIT variable
785 local split=$(echo $SPLIT \
786 | awk '
787 BEGIN { RS = " "; FS = ":"; }
788 { print $1; }' \
789 | tr '\n' ' ')
790 local split_space=" $split "
791 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
792 # For receipts v1: $SPLIT may present in the $WANTED package,
793 # but split packages have their own receipts
794 echo $PACKAGE
795 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
796 # $PACKAGE included somewhere in $SPLIT (probably in the end).
797 # We should build packages in the order defined in the $SPLIT.
798 echo $split
799 else
800 # We'll build the $PACKAGE, then all defined in the $SPLIT.
801 echo $PACKAGE $split
802 fi
803 }
806 toolchain_version() {
807 echo "<tr><td><a href='$base/$1'>$1</a></td>"
808 awk -F$'\t' -vpkg="$1" '
809 BEGIN { version = description = "---"; }
810 {
811 if ($1 == pkg) { version = $2; description = $4; }
812 }
813 END { printf("<td>%s</td><td>%s</td></tr>", version, description); }
814 ' $PKGS/packages.info
815 }
818 files_header() {
819 echo '<section><h3>Available downloads:</h3>'
820 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
821 }
824 # Update statistics used in web interface.
825 # There is no need to recalculate the statistics every time the page is displayed.
826 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
828 update_webstat() {
829 echo '<div id="waitme">'
830 show_note i 'Please wait while statistics are being collected.'
831 echo "</div>"
833 # for receipts:
834 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
835 rcooked=$(ls -d $WOK/*/taz | wc -l)
836 runbuilt=$(($rtotal - $rcooked))
837 rblocked=$(wc -l < $blocked)
838 rbroken=$(wc -l < $broken)
840 # for packages:
841 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
842 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
843 punbuilt=$(($ptotal - $pcooked))
844 pblocked=$(
845 while read i; do
846 sed "/^$i\t/!d" $CACHE/split.db
847 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
848 pbroken=$(
849 while read i; do
850 sed "/^$i\t/!d" $CACHE/split.db
851 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
853 cat > $webstat <<EOT
854 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
855 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
856 EOT
858 echo '<script>document.getElementById("waitme").remove();</script>'
859 }
864 #
865 # Load requested page
866 #
868 if [ -z "$pkg" ]; then
870 page_header
871 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
873 for list in activity cooknotes cooklist; do
874 [ -n "$(GET $list)" ] || continue
875 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
876 echo '<section id="content2">'
877 echo "<h2>DB: $list $nb</h2>"
878 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
879 s|\[ Done|<span class="r c20">Done|;
880 s|\[ Failed|<span class="r c10">Failed|;
881 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
882 s| \]|</span>|' | mktable $list
883 echo '</section>'
884 done
886 if [ -n "$(GET broken)" ]; then
887 echo '<section id="content2">'
888 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
889 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
890 echo '</section>'
891 fi
893 case "$QUERY_STRING" in
894 *.log)
895 log=$LOGS/$QUERY_STRING
896 name=$(basename $log)
897 if [ -f "$log" ]; then
898 echo "<h2>Log for: ${name%.log}</h2>"
899 if fgrep -q "Summary" $log; then
900 echo '<pre class="log">'
901 grep -A 20 'Summary' $log | syntax_highlighter log
902 echo '</pre>'
903 fi
904 echo '<pre class="log">'
905 syntax_highlighter log < $log
906 echo '</pre>'
907 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
908 # Display button only for SliTaz web browser
909 case "$HTTP_USER_AGENT" in
910 *SliTaz*)
911 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
912 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
913 show_note i "The package database has been requested for re-creation"
914 else
915 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
916 fi
917 fi
918 ;;
919 esac
920 fi
921 else
922 show_note e "No log file: $log"
923 fi
924 ;;
925 toolchain)
926 cat <<EOT
927 <div id="content2">
928 <section>
929 <h2>SliTaz GNU/Linux toolchain</h2>
931 <table>
932 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
933 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
934 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
935 <tr><td>Host system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
936 <tr><td>Target system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
937 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
938 $(toolchain_version slitaz-toolchain)
939 $(toolchain_version binutils)
940 $(toolchain_version linux-api-headers)
941 $(toolchain_version gcc)
942 $(toolchain_version glibc)
943 </table>
945 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
946 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
947 </p>
949 </section>
950 </div>
951 EOT
952 ;;
953 esac
954 page_footer
955 exit 0
956 fi
959 # We may have a toolchain.cgi script for cross cooker's
960 if [ -f "toolchain.cgi" ]; then
961 toolchain="toolchain.cgi"
962 else
963 toolchain="?toolchain"
964 fi
966 # Main page with summary. Count only packages included in ARCH,
967 # use 'cooker arch-db' to manually create arch.$ARCH files.
969 cat <<EOT
970 <div id="content2">
972 <section>
973 <form method="get" action="" class="search r">
974 <input type="hidden" name="search" value="pkg"/>
975 <button type="submit" title="Search">Search</button>
976 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
977 </form>
979 <h2>Summary</h2>
980 EOT
982 mktable <<EOT
983 Cooker state : $(running_command)
984 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
985 Commits to cook : $(wc -l < $commits)
986 Current cooklist : $(wc -l < $cooklist)
987 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
988 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
989 EOT
991 # If command is "cook:*", update gauge and percentage periodically.
992 # If different package is cooking, reload the page (with new settings)
993 cmd="$(cat $command)"
994 case "$cmd" in
995 cook:*)
996 pkg=${cmd#*:}
997 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
998 ;;
999 esac
1001 # Do we need to update the statistics?
1002 [ "$webstat" -nt "$activity" ] || update_webstat
1003 . $webstat
1005 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
1007 cat <<EOT
1008 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
1010 <table class="webstat"><thead>
1011 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
1012 </thead><tbody>
1013 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
1014 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
1015 </tbody></table>
1016 EOT
1018 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1019 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1020 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1021 else
1022 show_note i 'Cooker will be launched in the next 5 minutes.'
1023 fi
1024 fi
1026 cat <<EOT
1027 <p>
1028 Service logs:
1029 <a href="?cookorder.log">cookorder</a> ·
1030 <a href="?commits.log">commits</a> ·
1031 <a href="?pkgdb.log">pkgdb</a>
1032 </p>
1033 </section>
1034 EOT
1036 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
1037 s|\[ Done|<span class="r c20">Done|;
1038 s|\[ Failed|<span class="r c10">Failed|;
1039 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1040 s| \]|</span>|;
1041 s|%2B|\+|g' | \
1042 section $activity 12 "Activity|More activity"
1044 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
1045 section $cooknotes 12 "Cooknotes|More notes"
1047 [ -s "$commits" ] &&
1048 section $commits 20 "Commits|More commits" < $commits
1050 [ -s "$cooklist" ] && head -n 20 $cooklist | \
1051 section $cooklist 20 "Cooklist|Full cooklist"
1053 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
1054 section $broken 20 "Broken|All broken packages"
1056 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
1057 section $blocked 12 "Blocked|All blocked packages"
1059 cd $PKGS
1060 # About BusyBox's `ls`
1061 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
1062 # It supported the option `-e`, output with `-let` options like this:
1063 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
1064 # 1 2 3 4 5 6 7 8 9 10 11
1065 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
1066 # configure it or return the option back. It supported the long option
1067 # `--full-time` instead, but output is different:
1068 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
1069 # 1 2 3 4 5 6 7 8 9
1070 if ls -let >/dev/null 2>&1; then
1071 ls -let *.tazpkg \
1072 | awk '
1073 (NR<=20){
1074 sub(/:[0-9][0-9]$/, "", $9);
1075 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
1076 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
1077 }' \
1078 | section $activity 1000 "Latest cook"
1079 else
1080 ls -lt --full-time *.tazpkg \
1081 | awk '
1082 (NR<=20){
1083 sub(/:[0-9][0-9]$/, "", $7);
1084 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
1085 }' \
1086 | section $activity 1000 "Latest cook"
1087 fi
1089 echo '</div>'
1090 datalist
1091 page_footer
1092 exit 0
1093 fi
1096 # show tag
1098 if [ "$pkg" == '~' -a -n "$cmd" ]; then
1099 tag="$cmd"
1100 page_header
1101 cat <<EOT
1102 <div id="content2">
1103 <section>
1104 <h2>Tag “$tag”</h2>
1106 <table>
1107 <thead>
1108 <tr><th>Name</th><th>Description</th><th>Category</th></tr>
1109 </thead>
1110 <tbody>
1111 EOT
1112 sort $PKGS/packages.info \
1113 | awk -F$'\t' -vtag=" $tag " -vbase="$base" '{
1114 if (index(" " $6 " ", tag)) {
1115 url = base "/" $1 "/";
1116 gsub("+", "%2B", url);
1117 printf("<tr><td><img src=\"%s/s/%s\"> ", base, $1);
1118 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1119 }
1120 }'
1121 echo '</tbody></table></section></div>'
1122 page_footer
1123 exit 0
1124 fi
1127 case "$cmd" in
1128 '')
1129 page_header
1131 requested_pkg="$pkg"
1132 # Package info.
1133 if [ ! -f "$wok/$pkg/receipt" ]; then
1134 # Let's look at the cases when the package was not found
1136 # Maybe query is the exact name of split package? -> proceed to main package
1137 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1138 if (index(" " $2 " ", pkg)) {print $1; exit}
1139 }' $splitdb)
1141 # No, so let's find any matches among packages names (both main and split)
1142 if [ -z "$mainpkg" ]; then
1143 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1144 # Nothing matched
1145 if [ -z "$pkgs" ]; then
1146 echo "<h2>Not Found</h2>"
1147 show_note e "The requested package <b>$pkg</b> was not found on this server."
1148 page_footer; exit 0
1149 fi
1150 # Search results page
1151 echo "<section><h2>Package names matching “$pkg”</h2>"
1152 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1153 query="$pkg"
1154 for pkg in $pkgs; do
1155 # Find main package
1156 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1157 if (index(" " $2 " ", pkg)) {print $1; exit}
1158 }' $splitdb)
1159 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1161 unset SHORT_DESC CATEGORY
1162 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1163 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1165 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1166 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1167 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1168 done
1169 echo '</tbody></table></section>'
1170 page_footer; exit 0
1171 fi
1172 pkg="$mainpkg"
1173 fi
1175 log=$LOGS/$pkg.log
1176 pkg_info
1178 # Check for a log file and display summary if it exists.
1179 summary "$log"
1182 # Show tag list
1183 taglist=$(
1184 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1185 [ -s "$PKGS/packages.info" ] &&
1186 awk -F$'\t' -vpkg="$i" '{
1187 if ($1 == pkg) { print $6; exit; }
1188 }' "$PKGS/packages.info"
1189 done \
1190 | tr ' ' '\n' \
1191 | sort -u
1192 )
1193 if [ -n "$taglist" ]; then
1194 echo -n '<section><h3>Tags</h3><p>'
1195 lasttag=$(echo "$taglist" | tail -n1)
1196 for tag in $taglist; do
1197 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1198 [ "$tag" != "$lasttag" ] && echo -n " · "
1199 done
1200 echo '</p></section>'
1201 fi
1204 # Informational table with dependencies
1205 pkg="$requested_pkg"
1206 inf="$(mktemp -d)"
1208 # 1/3: Build dependencies (from receipt and pkgdb)
1209 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1210 echo "$i" >> $inf/a
1211 done
1213 # 2/3: Runtime dependencies (from pkgdb)
1214 {
1215 [ -s "$PKGS/packages.info" ] &&
1216 awk -F$'\t' -vp="$pkg" '{
1217 if ($1 == p) print $8
1218 }' "$PKGS/packages.info"
1219 } | tr ' ' '\n' | sort -u > $inf/b
1221 # 3/3: Required by (from pkgdb)
1222 {
1223 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1224 [ -s "$PKGS/packages.info" ] &&
1225 awk -F$'\t' -vp=" $i " '{
1226 if (index(" " $8 " ", p)) print $1
1227 }' "$PKGS/packages.info"
1229 [ -s "$PKGS/bdeps.txt" ] &&
1230 awk -F$'\t' -vp=" $i " '{
1231 if (index(" " $2 " ", p)) print $1
1232 }' $PKGS/bdeps.txt
1233 done
1234 } | sort -u > $inf/c
1236 cat <<EOT
1237 <section>
1238 <h3>Related packages</h3>
1239 <table class="third">
1240 <thead>
1241 <tr>
1242 <th>Build dependencies</th>
1243 <th>Runtime dependencies</th>
1244 <th>Required by</th>
1245 </tr>
1246 </thead>
1247 <tbody>
1248 EOT
1250 awk -vinf="$inf" -vbase="$base" '
1251 function linki(i) {
1252 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1253 }
1254 BEGIN{
1255 do {
1256 a = b = c = "";
1257 getline a < inf "/a";
1258 getline b < inf "/b";
1259 getline c < inf "/c";
1260 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1261 } while ( a b c )
1262 }'
1263 cat <<EOT
1264 </tbody>
1265 </table>
1266 </section>
1267 EOT
1268 # Clean
1269 rm -r $inf
1274 # Display <Recook> button only for SliTaz web browser
1275 case "$HTTP_USER_AGENT" in
1276 *SliTaz*)
1277 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1278 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1279 show_note i "The package “$pkg” has been requested for recook"
1280 else
1281 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1282 fi
1283 fi
1284 ;;
1285 esac
1286 ;;
1288 receipt)
1289 page_header
1290 pkg_info
1291 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1292 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1293 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1295 show_code bash < $wok/$pkg/receipt
1296 ;;
1298 stuff)
1299 page_header
1300 pkg_info
1301 file="$pkg/stuff/$arg"
1302 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1303 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1304 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1305 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1306 }'
1308 if [ -f "$wok/$file" ]; then
1309 case $file in
1310 *.desktop|*.theme) class="ini" ;;
1311 *.patch|*.diff|*.u) class="diff" ;;
1312 *.sh) class="bash" ;;
1313 *.conf*|*.ini)
1314 class="bash"
1315 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1316 ;;
1317 *.pl) class="perl" ;;
1318 *.c|*.h|*.awk) class="clike" ;;
1319 *.svg) class="svg" ;;
1320 *Makefile*) class="makefile" ;;
1321 *.po|*.pot) class="bash" ;;
1322 *.css) class="css" ;;
1323 *.htm|*.html) class="html" ;;
1324 *.js) class="js" ;;
1325 *.txt) class="asciidoc" ;;
1326 *)
1327 case $(head -n1 $wok/$file) in
1328 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1329 esac
1330 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1331 class="bash"
1332 fi
1333 if [ -z "$class" ]; then
1334 # Follow Busybox restrictions. Search for non-printable chars
1335 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1336 raw="true"
1337 fi
1338 fi
1339 ;;
1340 esac
1342 # Display image
1343 case $file in
1344 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1345 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1346 ;;
1347 esac
1349 # Display colored listing for all text-based documents (also for *.svg)
1350 case $file in
1351 *.png|*.jpg|*.jpeg|*.ico) ;;
1352 *)
1353 if [ -z "$raw" ]; then
1354 cat $wok/$file | show_code $class
1355 fi
1356 ;;
1357 esac
1359 # Display hex dump for binary files
1360 if [ -n "$raw" ]; then
1361 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1362 fi
1363 else
1364 show_note e "File “$file” absent!"
1365 fi
1366 ;;
1368 files)
1369 page_header
1370 pkg_info
1372 # find main package
1373 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1374 main=${wanted:-$pkg}
1375 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1377 splitsets=$(echo $SPLIT" " \
1378 | awk '
1379 BEGIN { RS = " "; FS = ":"; }
1380 { print $2; }' \
1381 | sort -u \
1382 | tr '\n' ' ' \
1383 | sed 's|^ *||; s| *$||')
1385 splitpkgs=$(echo $SPLIT" " \
1386 | awk '
1387 BEGIN { RS = " "; FS = ":"; }
1388 { print $1; }' \
1389 | tr '\n' ' ' \
1390 | sed 's|^ *||; s| *$||')
1392 # we need the version
1393 if [ -f "$WOK/linux/receipt" ]; then
1394 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1395 kbasevers=$(echo $kvers | cut -d. -f1,2)
1396 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1397 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1398 kbasevers=$(echo $kvers | cut -d. -f1,2)
1399 fi
1400 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1402 echo "<section><h3>Quick jump:</h3>"
1405 for part in head body; do
1407 for set in '' $splitsets; do
1408 pkgsofset=$(echo $SPLIT" " \
1409 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1410 BEGIN {
1411 RS = " "; FS = ":";
1412 if (!set) print main;
1413 if (!set && dev) print dev;
1414 }
1415 {
1416 if ($2 == set) print $1;
1417 }' \
1418 | sort -u)
1420 set_description=''
1421 [ -n "$splitsets" ] &&
1422 case "$set" in
1423 '')
1424 set_description=' (default set)'
1425 set_title='Default set'
1426 ;;
1427 *)
1428 set_description=" (set “$set”)"
1429 set_title="Set “$set”"
1430 ;;
1431 esac
1433 install="$wok/$main/install"
1434 [ -n "$set" ] && install="$install-$set"
1436 case $part in
1437 head)
1438 [ -n "$splitsets" ] &&
1439 case "$set" in
1440 '') echo "<ul><li>Default set:";;
1441 *) echo "<li>Set “$set”:";;
1442 esac
1443 echo -e '\t<ul>'
1444 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1445 cat <<EOT
1446 <li id='li-repeats$set' style='display:none'>
1447 <a href='#repeats$set'>repeatedly packaged files</a></li>
1448 <li id='li-empty$set' style='display:none'>
1449 <a href='#empty$set'>unpackaged empty folders</a></li>
1450 <li id='li-outoftree$set' style='display:none'>
1451 <a href='#outoftree$set'>out-of-tree files</a></li>
1452 <li id='li-orphans$set' style='display:none'>
1453 <a href='#orphans$set'>unpackaged files</a>
1454 <span id='orphansTypes$set'></span></li>
1455 EOT
1456 echo -e '\t</ul>'
1457 [ -n "$splitsets" ] && echo "</li>"
1458 ;;
1459 body)
1460 all_files=$(mktemp)
1461 cd $install; find ! -type d | sed 's|\.||' > $all_files
1463 # ------------------------------------------------------
1464 # Packages content
1465 # ------------------------------------------------------
1466 packaged=$(mktemp)
1467 for p in $pkgsofset; do
1468 namever="$(awk -F$'\t' -vp="$p" '{
1469 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
1470 }' $PKGS/packages.info)"
1471 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1472 indir=$p
1473 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1474 indir=$main
1475 fi
1476 dir="$wok/$indir/taz/$p-$ver/fs"
1478 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1480 echo
1481 echo "<section id='$p'>"
1482 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
1483 echo ' <pre class="files">'
1484 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1485 echo -en '<span class="underline">permissions·lnk·user ·group · size·date & time ·name\n</span>'
1486 cd $dir
1487 find . -print0 \
1488 | sort -z \
1489 | xargs -0 ls -ldp --color=always \
1490 | syntax_highlighter files \
1491 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
1492 | awk 'BEGIN { FS="\""; }
1493 { gsub("+", "%2B", $2); print; }'
1494 else
1495 echo 'No files'
1496 fi
1497 echo '</pre>'
1498 echo '</section>'
1500 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1501 done
1502 # ------------------------------------------------------
1503 # /Packages content
1504 # ------------------------------------------------------
1506 # ------------------------------------------------------
1507 # Repeatedly packaged files
1508 # ------------------------------------------------------
1509 repeats=$(mktemp)
1510 sort $packaged | uniq -d > $repeats
1511 if [ -s "$repeats" ]; then
1512 echo
1513 echo "<script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>"
1514 echo "<section id='repeats$set'>"
1515 echo " <h3>Repeatedly packaged files$set_description:</h3>"
1516 cd $install
1518 IFS=$'\n'
1519 echo -n ' <pre class="files">'
1520 echo -en '<span class="underline">permissions·lnk·user ·group · size·date & time ·name\n</span>'
1521 while read i; do
1522 find .$i -exec ls -ldp --color=always '{}' \; \
1523 | syntax_highlighter files \
1524 | sed 's|>\./|>/|'
1525 done < $repeats
1526 echo '</pre>'
1527 echo '</section>'
1528 unset IFS
1529 fi
1530 rm $repeats
1531 # ------------------------------------------------------
1532 # /Repeatedly packaged files
1533 # ------------------------------------------------------
1535 # ------------------------------------------------------
1536 # Unpackaged empty folders
1537 # ------------------------------------------------------
1538 emptydirs=$(mktemp)
1539 cd $install
1540 IFS=$'\n'
1541 find -type d \
1542 | sed 's|\.||' \
1543 | while read d; do
1544 [ -z "$(ls "$install$d")" ] || continue
1545 # empty dir determined by empty `ls`
1546 echo $d
1547 done \
1548 | while read d; do
1549 notfound='yes'
1550 for p in $(cd $wok/$main/taz; ls); do
1551 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1552 notfound=''
1553 break
1554 fi
1555 done
1556 [ -n "$notfound" ] &&
1557 ls -ldp --color=always .$d \
1558 | syntax_highlighter files \
1559 | sed 's|>\./|>/|'
1560 done > $emptydirs
1561 unset IFS
1562 if [ -s "$emptydirs" ]; then
1563 echo
1564 echo "<script>document.getElementById('li-empty$set').style.display = 'list-item'</script>"
1565 echo "<section id='empty$set'>"
1566 echo " <h3>Unpackaged empty folders$set_description:</h3>"
1567 echo -n ' <pre class="files">'
1568 echo -en '<span class="underline">permissions·lnk·user ·group · size·date & time ·name\n</span>'
1569 cat $emptydirs
1570 echo '</pre>'
1571 echo '</section>'
1572 fi
1573 rm $emptydirs
1574 # ------------------------------------------------------
1575 # /Unpackaged empty folders
1576 # ------------------------------------------------------
1578 # ------------------------------------------------------
1579 # Out-of-tree files
1580 # ------------------------------------------------------
1581 outoftree=$(mktemp)
1582 awk -F$'\n' -vall="$all_files" '
1583 {
1584 if (FILENAME == all) files_all[$1] = "1";
1585 else files_pkg[$1] = "1";
1586 }
1587 END {
1588 for (i in files_pkg) {
1589 if (! files_all[i]) print i;
1590 }
1591 }
1592 ' "$all_files" "$packaged" > $outoftree
1594 if [ -d "$install" -a -s "$outoftree" ]; then
1595 echo
1596 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
1597 echo "<section id='outoftree$set'>"
1598 echo " <h3>Out-of-tree files$set_description:</h3>"
1599 echo -n ' <pre class="files">'
1600 echo -en '<span class="underline">permissions·lnk·user ·group · size·date & time ·name\n</span>'
1601 IFS=$'\n'
1602 while read outoftree_line; do
1603 # Find the package out-of-tree file belongs to
1604 for i in $pkgsofset; do
1605 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
1606 cd $wok/$main/taz/$i-$ver/fs
1607 ls -ldp --color=always ".$outoftree_line" \
1608 | syntax_highlighter files \
1609 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
1610 | awk 'BEGIN { FS="\""; }
1611 { gsub("+", "%2B", $2); print; }'
1612 fi
1613 done
1614 done < $outoftree
1615 unset IFS
1616 echo '</pre>'
1617 echo '</section>'
1618 fi
1619 rm $outoftree
1620 # ------------------------------------------------------
1621 # /Out-of-tree files
1622 # ------------------------------------------------------
1624 # ------------------------------------------------------
1625 # Unpackaged files
1626 # ------------------------------------------------------
1627 orphans=$(mktemp)
1628 awk -F$'\n' -vall="$all_files" '
1629 {
1630 if (FILENAME == all) files_all[$1] = "1";
1631 else files_pkg[$1] = "1";
1632 }
1633 END {
1634 for (i in files_all) {
1635 if (! files_pkg[i]) print i;
1636 }
1637 }
1638 ' "$all_files" "$packaged" | sort > $orphans
1639 if [ -d "$install" -a -s "$orphans" ]; then
1640 echo
1641 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
1642 echo "<section id='orphans$set'>"
1643 echo " <h3>Unpackaged files$set_description:</h3>"
1644 table=$(mktemp)
1645 awk '
1646 function tag(text, color) {
1647 printf("<span class=\"c%s1\">%s</span> ", color, text);
1648 printf("%s\n", $0);
1649 }
1650 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
1651 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
1652 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
1653 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ {
1654 tag("---", 0); next }
1655 /\.pod$/ { tag("pod", 5); next }
1656 /\/share\/man\// { tag("man", 5); next }
1657 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1658 /\/share\/devhelp\// { tag("doc", 5); next }
1659 /\/share\/icons\// { tag("ico", 2); next }
1660 /\/share\/locale\// { tag("loc", 4); next }
1661 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1662 /\/Makefile.*$/ { tag("dev", 3); next }
1663 /\/share\/help\// || /\/share\/appdata\// { tag("gnm", 6); next }
1664 { tag("???", 1) }
1665 ' "$orphans" > $table
1667 # Summary table
1668 orphans_types='()'
1669 for i in head body; do
1670 case $i in
1671 head) echo -n '<table class="summary"><tr>';;
1672 body) echo -n '<th> </th></tr><tr>';;
1673 esac
1674 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1675 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1676 case $i in
1677 head) echo -n "<th class='$class'>$tag</th>";;
1678 body)
1679 tagscount="$(grep ">$tag<" $table | wc -l)"
1680 printf '<td>%s</td>' "$tagscount"
1681 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1682 ;;
1683 esac
1684 done
1685 done
1686 echo '<td> </td></tr></table>'
1687 orphans_types="${orphans_types/( /(}"
1688 [ "$orphans_types" != '()' ] &&
1689 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
1691 suffix=''; [ -n "$set" ] && suffix="-$set"
1692 echo -n ' <pre class="files">'
1693 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date & time ·name\n</span>'
1694 IFS=$'\n'
1695 while read orphan_line; do
1696 echo -n "${orphan_line/span> */span>} "
1697 cd $install
1698 ls -ldp --color=always ".${orphan_line#*</span> }" \
1699 | syntax_highlighter files \
1700 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
1701 | awk 'BEGIN { FS="\""; }
1702 { gsub("+", "%2B", $2); print; }'
1703 done < $table
1704 unset IFS
1705 echo '</pre>'
1706 echo '</section>'
1707 rm $table
1708 fi
1709 rm $orphans
1710 # ------------------------------------------------------
1711 # /Unpackaged files
1712 # ------------------------------------------------------
1714 rm $all_files $packaged
1715 ;;
1716 esac
1717 done # /set
1719 case "$part" in
1720 head)
1721 [ -n "$splitsets" ] && echo "</ul>"
1722 echo "</section>"
1723 ;;
1724 esac
1725 done # /part
1727 ;;
1729 description)
1730 page_header
1731 pkg_info
1732 descs="$(ls $WOK/$pkg/description*.txt)"
1733 if [ -n "$descs" ]; then
1734 echo '<div id="content2">'
1735 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1736 for i in $descs; do
1737 case $i in
1738 */description.txt) continue ;;
1739 *) package=$(echo $i | cut -d. -f2) ;;
1740 esac
1741 show_desc "$package" "$i"
1742 done
1743 echo '</div>'
1744 else
1745 show_note w "No description of $pkg"
1746 fi
1747 ;;
1749 log)
1750 page_header
1751 pkg_info
1752 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1754 echo '<div class="btnList">'
1755 acc='l' # access key for the latest log is 'L'
1756 while read log; do
1757 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1758 timestamp=$(stat -c %Y $log)
1759 class=''
1760 if [ "$arg" == "$timestamp" ]; then
1761 class=' log'
1762 logfile="$log"
1763 fi
1764 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1765 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1766 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1767 case $acc in
1768 l) acc=0;;
1769 *) acc=$((acc+1));;
1770 esac
1771 done <<EOT
1772 $(find $LOGS -name "$pkg.log*" | sort)
1773 $(find $LOGS -name "$pkg-pack.log")
1774 EOT
1775 echo '</div>'
1777 if [ -z "$logfile" ]; then
1778 show_note e "Requested log is absent"
1779 page_footer
1780 exit 0
1781 fi
1783 # Define cook variables for syntax highlighter
1784 if [ -s "$WOK/$pkg/receipt" ]; then
1785 . "$WOK/$pkg/receipt"
1786 _wok='/home/slitaz/wok'
1787 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1788 _install="$_wok/$pkg/install"
1789 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1790 _stuff="$_wok/$pkg/stuff"
1791 fi
1793 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1794 # {
1795 # summary "$logfile" links
1796 #
1797 # syntax_highlighter log < $logfile | awk '
1798 # BEGIN { print "<pre class=\"log\">"; }
1799 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1800 # END { print "</pre>"; }
1801 # '
1802 #
1803 # page_footer
1804 # } | gzip > gzlog/$pkg.$arg
1805 # fi
1807 blog=$(basename $logfile)
1808 summary "$logfile" links
1810 # disable next `sed` for the 'like2016' theme
1811 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1812 cat $logfile | syntax_highlighter log | \
1813 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1814 awk '
1815 BEGIN { print "<pre class=\"log\">"; }
1816 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
1817 END { print "</pre>"; }
1818 '
1819 ;;
1822 man|doc|info)
1823 page_header
1824 pkg_info
1825 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1827 dir="wok/$pkg/install/usr/share/$cmd"
1828 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1829 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1830 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1831 [ -n "$try" ] && arg="$try"
1832 fi
1833 while read i; do
1834 [ -s "$i" ] || continue
1835 case "$i" in
1836 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1837 esac
1838 i=${i#$dir/}
1839 [ -n "$arg" ] || arg="$i"
1840 class=''; [ "$arg" == "$i" ] && class=" doc"
1841 case "$cmd" in
1842 man)
1843 case $i in
1844 man*) lang='';;
1845 *) lang="${i%%/*}: ";;
1846 esac
1847 man=$(basename $i .gz)
1848 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1849 ;;
1850 doc)
1851 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1852 ;;
1853 info)
1854 info=$(basename $i)
1855 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1856 ;;
1857 esac
1858 done <<EOT
1859 $(for i in $dir; do find $i -type f; done | sort)
1860 EOT
1861 echo '</div>'
1863 [ -f "$arg" ] || arg="$dir/$arg"
1864 if [ -f "$arg" ]; then
1865 tmp="$(mktemp)"
1866 docat "$arg" > $tmp
1867 [ -s "$tmp" ] &&
1868 case "$cmd" in
1869 info)
1870 echo '<div id="content2" class="texinfo"><pre class="first">'
1871 info2html < "$tmp"
1872 echo '</pre></div>'
1873 ;;
1874 doc)
1875 case "$arg" in
1876 *.sgml|*.devhelp2) class='xml';;
1877 *.py) class='python';; # pycurl package
1878 *.css) class='css';;
1879 *.sh) class='bash';;
1880 *)
1881 first=$(head -n1 "$tmp")
1882 if [ "${first:0:1}" == '#' ]; then
1883 class='bash' # first line begins with '#'
1884 else
1885 class='asciidoc'
1886 fi;;
1887 esac
1888 case "$arg" in
1889 *.htm*)
1890 case $arg in
1891 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1892 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1893 esac
1894 # make the iframe height so long to contain its contents without scrollbar
1895 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1896 ;;
1897 *.pdf)
1898 case $arg in
1899 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1900 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1901 esac
1902 cat <<EOT
1903 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1904 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1905 </object>
1906 EOT
1907 ;;
1908 *.md|*.markdown)
1909 echo '<section>'
1910 $md2html "$tmp"
1911 echo '</section>'
1912 ;;
1913 *)
1914 show_code $class < "$tmp"
1915 ;;
1916 esac
1917 ;;
1918 man)
1919 #export TEXTDOMAIN='man2html'
1920 echo "<div id='content2'>"
1922 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1923 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1924 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1926 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1927 # Process the pre-formatted man-cat page
1928 # (for example see sudo package without groff in build dependencies)
1929 sed -i '
1930 s|M-bM-^@M-^S|—|g;
1931 s|M-bM-^@M-^\\|<b>|g;
1932 s|M-bM-^@M-^]|</b>|g
1933 s|M-bM-^@M-^X|<u>|g;
1934 s|M-bM-^@M-^Y|</u>|g;
1935 s|M-BM-||g;
1936 s|++oo|•|g;
1937 s|&|\&|g; s|<|\<|g; s|>|\>|g;
1938 ' "$tmp"
1939 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 \
1940 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 \
1941 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
1942 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
1943 done
1944 echo '<pre class="catman">'
1945 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
1946 echo '</pre>'
1947 else
1948 echo "$html"
1949 fi
1950 echo "</div>"
1951 ;;
1952 esac
1953 rm -f $tmp
1954 else
1955 show_note e "File “$arg” does not exist!"
1956 fi
1957 ;;
1959 download)
1960 page_header
1961 pkg_info
1962 show=0
1964 . $wok/$pkg/receipt
1966 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
1967 files_header
1968 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
1969 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
1970 echo "<td>Sources for building the package “$pkg”</td></tr>"
1971 show=1
1972 fi
1974 if [ -d "$wok/$pkg/taz" ]; then
1975 [ "$show" -eq 1 ] || files_header
1977 common_version=$VERSION
1978 for i in $(all_names); do
1979 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
1980 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
1982 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
1983 [ -f "$PKGS/$filename" ] &&
1984 cat <<EOT
1985 <tr>
1986 <td><a href="$base/get/$filename">$filename</a></td>
1987 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
1988 <td>$SHORT_DESC</td>
1989 </tr>
1990 EOT
1991 done
1992 done
1993 show=1
1994 fi
1996 if [ "$show" -eq 1 ]; then
1997 echo '</tbody></table></section>'
1998 else
1999 show_note w "Sorry, there's nothing to download…"
2000 fi
2001 ;;
2003 esac
2006 page_footer
2007 exit 0