cookutils view web/cookiso.cgi @ rev 340

cookiso.cgo add build time in summary
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 17 23:02:31 2012 +0100 (2012-03-17)
parents c99954bba012
children da66e6be1add
line source
1 #!/bin/sh
2 #
3 # SliTaz Cookiso CGI/web interface.
4 #
5 echo "Content-Type: text/html"
6 echo ""
8 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
9 [ -f "cook.conf" ] && . ./cook.conf
11 # Cookiso DB files.
12 cache="$CACHE/cookiso"
13 iso="$SLITAZ/iso"
14 activity="$cache/activity"
15 command="$cache/command"
16 rollog="$cache/rolling.log"
17 synclog="$cache/rsync.log"
19 #
20 # Functions
21 #
23 # Put some colors in log and DB files.
24 syntax_highlighter() {
25 case $1 in
26 log)
27 sed -e 's#OK#<span class="span-ok">OK</span>#g' \
28 -e 's#Failed#<span class="span-red">Failed</span>#g' \
29 -e 's|\(Filesystem size:\).*G\([0-9\.]*M\) *$|\1 \2|' \
30 -e 's|.\[1m|<b>|' -e 's|.\[0m|</b>|' -e 's|.\[[0-9Gm;]*||g' ;;
31 activity)
32 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
33 esac
34 }
36 # Latest build pkgs.
37 list_isos() {
38 cd $iso
39 ls -1t *.iso | head -6 | \
40 while read file
41 do
42 echo -n $(stat -c '%y' $file | cut -d . -f 1 | sed s/:[0-9]*$//)
43 echo " : $file"
44 done
45 }
47 # xHTML header. Pages can be customized with a separate html.header file.
48 if [ -f "header.html" ]; then
49 cat header.html | sed s'/Cooker/ISO Cooker/'
50 else
51 cat << EOT
52 <!DOCTYPE html>
53 <html xmlns="http://www.w3.org/1999/xhtml">
54 <head>
55 <title>SliTaz ISO Cooker</title>
56 <meta charset="utf-8" />
57 <link rel="shortcut icon" href="favicon.ico" />
58 <link rel="stylesheet" type="text/css" href="style.css" />
59 </head>
60 <body>
62 <div id="header">
63 <div id="logo"></div>
64 <h1><a href="cookiso.cgi">SliTaz ISO Cooker</a></h1>
65 </div>
67 <!-- Content -->
68 <div id="content">
69 EOT
70 fi
72 #
73 # Load requested page
74 #
76 case "${QUERY_STRING}" in
77 distro=*)
78 distro=${QUERY_STRING#distro=}
79 ver=${distro%-core-4in1}
80 log=$iso/slitaz-$ver.log
81 . $SLITAZ/flavors/${distro#*-}/receipt
82 echo "<h2>Distro: $distro</h2>"
83 echo "<p>Description: $SHORT_DESC</p>"
84 echo '<h3>Summary</h3>'
85 echo '<pre>'
86 fgrep "Build time" $log
87 fgrep "Build date" $log
88 fgrep "Packages" $log
89 fgrep "Rootfs size" $log
90 fgrep "ISO image size" $log
91 echo '</pre>'
92 echo '<h3>Cookiso log</h3>'
93 echo '<pre>'
94 cat $log | syntax_highlighter log
95 echo '</pre>' ;;
96 *)
97 # Main page with summary.
98 echo -n "Running command : "
99 if [ -f "$command" ]; then
100 cat $command
101 else
102 echo "Not running"
103 fi
104 cat << EOT
105 <h2>Activity</h2>
106 <pre>
107 $(tac $activity | head -n 12 | syntax_highlighter activity)
108 </pre>
110 <h2>Latest ISO</h2>
111 <pre>
112 $(list_isos | syntax_highlighter activity)
113 </pre>
114 EOT
115 # Rolling Bot log.
116 if [ -f "$rollog" ]; then
117 echo "<h2>Rolling log</h2>"
118 echo '<pre>'
119 cat $rollog
120 echo '</pre>'
121 fi
122 # Rsync log.
123 if [ -f "$synclog" ]; then
124 echo "<h2>Rsync log</h2>"
125 echo '<pre>'
126 awk '{
127 if (/\/s/) h=$0;
128 else {
129 if (h!="") print h;
130 h="";
131 print;
132 }
133 }'< $synclog
134 echo '</pre>'
135 fi ;;
136 esac
138 # Close xHTML page
139 cat << EOT
140 </div>
142 <div id="footer">
143 <a href="http://www.slitaz.org/">SliTaz Website</a>
144 <a href="cookiso.cgi">Cookiso</a>
145 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
146 Documentation</a>
147 </div>
149 </body>
150 </html>
151 EOT
153 exit 0