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