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