cookutils view lighttpd/index.cgi @ rev 1085

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