cookutils annotate lighttpd/index.cgi @ rev 1073

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