cookutils annotate web/cooker.cgi @ rev 602

cooker.cgi: fix download link
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jul 08 16:46:15 2013 +0000 (2013-07-08)
parents c1bbd0a44da8
children 03c2a456ac4b
rev   line source
pankso@5 1 #!/bin/sh
pankso@5 2 #
pankso@5 3 # SliTaz Cooker CGI/web interface.
pankso@5 4 #
pankso@5 5
pankso@5 6 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
pankso@5 7 [ -f "cook.conf" ] && . ./cook.conf
pankso@5 8
pankso@5 9 # The same wok as cook.
pankso@5 10 wok="$WOK"
pankso@5 11
pankso@5 12 # Cooker DB files.
pankso@5 13 activity="$CACHE/activity"
pankso@5 14 commits="$CACHE/commits"
pankso@5 15 cooklist="$CACHE/cooklist"
pankso@5 16 cookorder="$CACHE/cookorder"
pankso@14 17 command="$CACHE/command"
pankso@5 18 blocked="$CACHE/blocked"
pankso@5 19 broken="$CACHE/broken"
pankso@22 20 cooknotes="$CACHE/cooknotes"
pankso@164 21 wokrev="$CACHE/wokrev"
pankso@5 22
paul@256 23 # We're not logged and want time zone to display correct server date.
pankso@249 24 export TZ=$(cat /etc/TZ)
pankso@249 25
pascal@354 26 if [ "${QUERY_STRING%%=*}" == "download" ]; then
pascal@354 27 file=$PKGS/${QUERY_STRING#*=}
pascal@354 28 cat <<EOT
pascal@354 29 Content-Type: application/octet-stream
pascal@354 30 Content-Length: $(stat -c %s $file)
pascal@354 31 Content-Disposition: attachment; filename=$(basename $file)
pascal@354 32
pascal@354 33 EOT
pascal@354 34 cat $file
pascal@354 35 exit
pascal@354 36 fi
pascal@354 37
pascal@354 38 echo "Content-Type: text/html"
pascal@354 39 echo ""
pankso@5 40
pankso@310 41 # RSS feed generator
pankso@310 42 if [ "$QUERY_STRING" == "rss" ]; then
pankso@310 43 pubdate=$(date "+%a, %d %b %Y %X")
pankso@310 44 cat << EOT
pankso@310 45 <?xml version="1.0" encoding="utf-8" ?>
pankso@310 46 <rss version="2.0">
pankso@310 47 <channel>
pankso@310 48 <title>SliTaz Cooker</title>
pankso@310 49 <description>The SliTaz packages cooker feed</description>
pankso@310 50 <link>$COOKER_URL</link>
pankso@310 51 <lastBuildDate>$pubdate GMT</lastBuildDate>
pankso@310 52 <pubDate>$pubdate GMT</pubDate>
pankso@310 53 EOT
pankso@310 54 for rss in $(ls -lt $FEEDS/*.xml | head -n 12)
pankso@310 55 do
pankso@310 56 cat $rss
pankso@310 57 done
pankso@310 58 cat << EOT
pankso@310 59 </channel>
pankso@310 60 </rss>
pankso@310 61 EOT
pankso@310 62 exit 0
pankso@310 63 fi
pankso@310 64
pascal@354 65 #
pascal@354 66 # Functions
pascal@354 67 #
pascal@354 68
pankso@5 69 # Put some colors in log and DB files.
pankso@5 70 syntax_highlighter() {
pankso@17 71 case $1 in
pankso@17 72 log)
pascal@601 73 sed -e 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' \
pascal@601 74 -e 's#OK$#<span class="span-ok">OK</span>#g' \
pascal@535 75 -e 's#Done$#<span class="span-ok">Done</span>#g' \
pankso@17 76 -e 's#yes$#<span class="span-ok">yes</span>#g' \
pankso@17 77 -e 's#no$#<span class="span-no">no</span>#g' \
pankso@129 78 -e 's#error$#<span class="span-red">error</span>#g' \
pankso@129 79 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
pankso@129 80 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
pankso@65 81 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
pankso@17 82 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
pankso@29 83 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
pascal@507 84 -e s"#ftp://[^ '\"]*#<a href='\0'>\0</a>#"g \
pascal@507 85 -e s"#http://[^ '\"]*#<a href='\0'>\0</a>#"g ;;
pankso@17 86 receipt)
pascal@601 87 sed -e 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' \
pascal@601 88 -e s'|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|'g \
pankso@258 89 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
pankso@17 90 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
pankso@129 91 diff)
pankso@129 92 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
pankso@129 93 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
pankso@129 94 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
pankso@129 95 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
pankso@129 96 activity)
pankso@129 97 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
pankso@17 98 esac
pankso@5 99 }
pankso@5 100
pankso@5 101 # Latest build pkgs.
pankso@5 102 list_packages() {
pankso@5 103 cd $PKGS
pankso@5 104 ls -1t *.tazpkg | head -20 | \
pankso@5 105 while read file
pankso@5 106 do
pankso@5 107 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
pankso@5 108 echo " : $file"
pankso@5 109 done
pankso@5 110 }
pankso@5 111
pankso@253 112 # xHTML header. Pages can be customized with a separated html.header file.
pankso@253 113 if [ -f "header.html" ]; then
pankso@253 114 cat header.html
pankso@253 115 else
pankso@253 116 cat << EOT
pankso@5 117 <!DOCTYPE html>
pankso@5 118 <html xmlns="http://www.w3.org/1999/xhtml">
pankso@5 119 <head>
pankso@5 120 <title>SliTaz Cooker</title>
pankso@5 121 <meta charset="utf-8" />
pankso@252 122 <link rel="shortcut icon" href="favicon.ico" />
pankso@5 123 <link rel="stylesheet" type="text/css" href="style.css" />
pankso@5 124 </head>
pankso@5 125 <body>
pankso@5 126
pankso@5 127 <div id="header">
pankso@253 128 <div id="logo"></div>
pankso@5 129 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
pankso@5 130 </div>
pankso@5 131
pankso@5 132 <!-- Content -->
pankso@5 133 <div id="content">
pankso@5 134 EOT
pankso@253 135 fi
pankso@5 136
pankso@5 137 #
pankso@5 138 # Load requested page
pankso@5 139 #
pankso@5 140
pankso@5 141 case "${QUERY_STRING}" in
pankso@16 142 pkg=*)
pankso@16 143 pkg=${QUERY_STRING#pkg=}
pankso@16 144 log=$LOGS/$pkg.log
pankso@16 145 echo "<h2>Package: $pkg</h2>"
pankso@16 146
pankso@18 147 # Package info.
pankso@18 148 echo '<div id="info">'
pankso@16 149 if [ -f "$wok/$pkg/receipt" ]; then
pankso@16 150 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
pascal@275 151 unset WEB_SITE
pascal@275 152 . $wok/$pkg/receipt
pascal@301 153 [ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
pascal@275 154 echo "<a href='$WEB_SITE'>home</a>"
pascal@354 155 if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
pascal@355 156 echo "<a href='cooker.cgi?files=$pkg'>files</a>"
pascal@354 157 unset EXTRAVERSION
pascal@354 158 . $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
pascal@490 159 if [ -f $wok/$pkg/taz/$PACKAGE-$VERSION/description.txt ]; then
slaxemulator@491 160 echo "<a href='cooker.cgi?description=$pkg'>description</a>"
pascal@490 161 fi
pascal@354 162 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
pascal@354 163 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
pascal@354 164 fi
pascal@439 165 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
pascal@439 166 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
pascal@439 167 fi
pascal@354 168 fi
pankso@16 169 else
pankso@18 170 echo "No package named: $pkg"
pankso@16 171 fi
pankso@18 172 echo '</div>'
pankso@16 173
paul@62 174 # Check for a log file and display summary if it exists.
pankso@16 175 if [ -f "$log" ]; then
pankso@87 176 if grep -q "cook:$pkg$" $command; then
pankso@88 177 echo "<pre>The Cooker is currently building: $pkg</pre>"
pankso@87 178 fi
pankso@149 179 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
pankso@87 180 echo "<h3>Cook summary</h3>"
pankso@87 181 echo '<pre>'
pankso@392 182 grep -A 9 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
pankso@87 183 syntax_highlighter log
pankso@87 184 echo '</pre>'
pankso@14 185 fi
pankso@149 186 if fgrep -q "Debug information" $LOGS/$pkg.log; then
pankso@17 187 echo "<h3>Cook failed</h3>"
pankso@17 188 echo '<pre>'
pankso@149 189 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
pankso@17 190 syntax_highlighter log
pankso@17 191 echo '</pre>'
pankso@16 192 fi
pankso@16 193 echo "<h3>Cook log</h3>"
pankso@16 194 echo '<pre>'
pascal@601 195 cat $log | syntax_highlighter log
pankso@16 196 echo '</pre>'
pankso@5 197 else
pankso@16 198 echo "<pre>No log: $pkg</pre>"
pankso@16 199 fi ;;
pankso@65 200 file=*)
paul@89 201 # Dont allow all files on the system for security reasons.
pankso@65 202 file=${QUERY_STRING#file=}
pankso@65 203 case "$file" in
pankso@90 204 activity|cooknotes|cooklist)
pankso@91 205 [ "$file" == "cooklist" ] && \
pankso@93 206 nb="- Packages: $(cat $cooklist | wc -l)"
pankso@91 207 echo "<h2>DB: $file $nb</h2>"
pankso@18 208 echo '<pre>'
pankso@129 209 tac $CACHE/$file | syntax_highlighter activity
pankso@65 210 echo '</pre>' ;;
pankso@66 211 broken)
pankso@66 212 nb=$(cat $broken | wc -l)
pankso@93 213 echo "<h2>DB: broken - Packages: $nb</h2>"
pankso@66 214 echo '<pre>'
pankso@129 215 cat $CACHE/$file | sort | \
pankso@66 216 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
pankso@66 217 echo '</pre>' ;;
pankso@129 218 *.diff)
pankso@129 219 diff=$CACHE/$file
pankso@129 220 echo "<h2>Diff for: ${file%.diff}</h2>"
pankso@129 221 [ "$file" == "installed.diff" ] && echo \
pankso@129 222 "<p>This is the latest diff between installed packages \
pankso@130 223 and installed build dependencies to cook.</p>"
pankso@129 224 echo '<pre>'
pankso@129 225 cat $diff | syntax_highlighter diff
pankso@129 226 echo '</pre>' ;;
pankso@65 227 *.log)
pankso@71 228 log=$LOGS/$file
pankso@71 229 name=$(basename $log)
pankso@65 230 echo "<h2>Log for: ${name%.log}</h2>"
pankso@71 231 if [ -f "$log" ]; then
pankso@71 232 if fgrep -q "Summary" $log; then
pankso@65 233 echo '<pre>'
pankso@73 234 grep -A 20 "^Summary" $log | sed /^$/d | \
pankso@65 235 syntax_highlighter log
pankso@65 236 echo '</pre>'
pankso@65 237 fi
pankso@65 238 echo '<pre>'
pankso@71 239 cat $log | syntax_highlighter log
pankso@65 240 echo '</pre>'
pankso@65 241 else
pankso@71 242 echo "<pre>No log file: $log</pre>"
pankso@65 243 fi ;;
pankso@65 244 esac ;;
pascal@509 245 stuff=*)
pascal@509 246 file=${QUERY_STRING#stuff=}
pascal@509 247 echo "<h2>$file</h2>"
pascal@509 248 echo '<pre>'
pascal@601 249 cat $wok/$file | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
pascal@509 250 echo '</pre>' ;;
pankso@16 251 receipt=*)
pankso@16 252 pkg=${QUERY_STRING#receipt=}
pankso@17 253 echo "<h2>Receipt for: $pkg</h2>"
pankso@16 254 if [ -f "$wok/$pkg/receipt" ]; then
pascal@509 255 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | \
pascal@509 256 while read file ; do
pascal@509 257 echo "<a href=\"?stuff=$pkg/$file\">$file</a>"
pascal@509 258 done
pankso@16 259 echo '<pre>'
pascal@601 260 cat $wok/$pkg/receipt | \
pascal@601 261 syntax_highlighter receipt
pankso@16 262 echo '</pre>'
pankso@16 263 else
pascal@301 264 echo "<pre>No receipt for: $pkg</pre>"
pascal@301 265 fi ;;
pascal@301 266 files=*)
pascal@301 267 pkg=${QUERY_STRING#files=}
pascal@301 268 echo "<h2>Installed files by: $pkg</h2>"
pascal@301 269 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
pascal@301 270 if [ -d "$dir/fs" ]; then
pascal@301 271 echo '<pre>'
pascal@301 272 find $dir/fs -not -type d | xargs ls -ld | \
pascal@602 273 syntax_highlighter log | \
pascal@602 274 sed "s|\(.*\) /.*\(${dir#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|;s|^\([^-].*\)\(<a.*\)\">\(.*\)</a>|\1\3|"
pascal@301 275 echo '</pre>'
pascal@301 276 else
pascal@301 277 echo "<pre>No files list for: $pkg</pre>"
pankso@5 278 fi ;;
pascal@490 279 description=*)
pascal@490 280 pkg=${QUERY_STRING#description=}
pascal@490 281 echo "<h2>Description of $pkg</h2>"
pascal@490 282 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
pascal@493 283 if [ -s "$dir/description.txt" ]; then
pascal@490 284 echo '<pre>'
pascal@601 285 cat $dir/description.txt | \
pascal@601 286 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
pascal@490 287 echo '</pre>'
pascal@490 288 else
pascal@490 289 echo "<pre>No description for: $pkg</pre>"
pascal@490 290 fi ;;
pankso@5 291 *)
pankso@383 292 # We may have a toolchain.cgi script for cross cooker's
pankso@383 293 if [ -f "toolchain.cgi" ]; then
pankso@383 294 toolchain='toolchain.cgi'
pankso@383 295 else
pankso@383 296 toolchain='cooker.cgi?pkg=slitaz-toolchain'
pankso@383 297 fi
pankso@383 298 # Main page with summary. Count only package include in ARCH,
pankso@383 299 # use 'cooker arch' to manually create arch.$ARCH files.
pankso@383 300 # We may have arm only packages, use arch.i486 ?
pankso@383 301 case "$ARCH" in
pankso@436 302 arm|x86_64) inwok=$(ls $WOK/*/arch.$ARCH | wc -l) ;;
pankso@383 303 *) inwok=$(ls $WOK | wc -l) ;;
pankso@383 304 esac
pankso@75 305 cooked=$(ls $PKGS/*.tazpkg | wc -l)
pankso@106 306 unbuilt=$(($inwok - $cooked))
pankso@245 307 pct=0
pankso@245 308 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
pankso@5 309 cat << EOT
pankso@5 310 <div style="float: right;">
pankso@5 311 <form method="get" action="$SCRIPT_NAME">
pankso@16 312 Package:
pankso@16 313 <input type="text" name="pkg" />
pankso@5 314 </form>
pankso@5 315 </div>
pankso@5 316
pankso@5 317 <h2>Summary</h2>
pankso@75 318
pankso@5 319 <pre>
pankso@16 320 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
pascal@301 321 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
pankso@5 322 Commits to cook : $(cat $commits | wc -l)
pankso@65 323 Current cooklist : $(cat $cooklist | wc -l)
pankso@5 324 Broken packages : $(cat $broken | wc -l)
pankso@95 325 Blocked packages : $(cat $blocked | wc -l)
pankso@5 326 </pre>
pankso@5 327
pankso@383 328 <p class="info">
pankso@247 329 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt -
pankso@247 330 Server date: $(date '+%Y-%m-%d %H:%M')
pankso@75 331 </p>
pankso@75 332 <div class="pctbar">
pankso@75 333 <div class="pct" style="width: ${pct}%;">${pct}%</div>
pankso@14 334 </div>
pankso@14 335
pankso@75 336 <p>
pankso@129 337 Latest:
pankso@129 338 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
pankso@129 339 <a href="cooker.cgi?file=commits.log">commits.log</a>
pankso@129 340 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
pankso@188 341 - Architecture $ARCH:
pankso@383 342 <a href="$toolchain">toolchain</a>
pankso@75 343 </p>
pankso@75 344
pascal@270 345 <a name="activity"></a>
pankso@5 346 <h2>Activity</h2>
pankso@5 347 <pre>
pankso@129 348 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
pankso@5 349 </pre>
pankso@65 350 <a class="button" href="cooker.cgi?file=activity">More activity</a>
pankso@5 351
pascal@272 352 <a name="cooknotes"></a>
pankso@23 353 <h2>Cooknotes</h2>
pankso@23 354 <pre>
pankso@129 355 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
pankso@23 356 </pre>
pankso@65 357 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
pankso@23 358
pascal@270 359 <a name="commits"></a>
pankso@5 360 <h2>Commits</h2>
pankso@5 361 <pre>
pankso@5 362 $(cat $commits)
pankso@5 363 </pre>
pankso@5 364
pascal@270 365 <a name="cooklist"></a>
pankso@18 366 <h2>Cooklist</h2>
pankso@18 367 <pre>
pankso@90 368 $(cat $cooklist | head -n 20)
pankso@18 369 </pre>
pankso@90 370 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
pankso@18 371
pascal@270 372 <a name="broken"></a>
pankso@5 373 <h2>Broken</h2>
pankso@5 374 <pre>
pankso@66 375 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
pankso@5 376 </pre>
pankso@66 377 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
pankso@5 378
pascal@270 379 <a name="blocked"></a>
pankso@23 380 <h2>Blocked</h2>
pankso@14 381 <pre>
pankso@23 382 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
pankso@14 383 </pre>
pankso@14 384
pascal@270 385 <a name="lastcook"></a>
pankso@5 386 <h2>Latest cook</h2>
pankso@5 387 <pre>
pankso@20 388 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
pankso@5 389 </pre>
pankso@5 390 EOT
pankso@5 391 ;;
pankso@5 392 esac
pankso@5 393
pankso@5 394 # Close xHTML page
pankso@5 395 cat << EOT
pankso@5 396 </div>
pankso@5 397
pankso@5 398 <div id="footer">
pankso@116 399 <a href="http://www.slitaz.org/">SliTaz Website</a>
pankso@116 400 <a href="cooker.cgi">Cooker</a>
pankso@116 401 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
pankso@116 402 Documentation</a>
pankso@5 403 </div>
pankso@5 404
pankso@5 405 </body>
pankso@5 406 </html>
pankso@5 407 EOT
pankso@5 408
pankso@5 409 exit 0