cookutils annotate lighttpd/index.cgi @ rev 1090

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