cookutils annotate lighttpd/index.cgi @ rev 1126

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