cookutils view web/cookiso.cgi @ rev 332

cookiso.cgi: Display log for default 4in1
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 17 14:55:28 2012 +0100 (2012-03-17)
parents e5492d7d09a8
children 516a5e17e296
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 if echo $distro | fgrep core-4in1; then
80 ver=${distro%-core-4in1}
81 log=$iso/slitaz-$ver.log
82 else
83 log=$iso/slitaz-$distro.log
84 fi
85 . $SLITAZ/flavors/${distro#*-}/receipt
86 echo "<h2>Distro: $distro</h2>"
87 echo "<p>Description: $SHORT_DESC</p>"
88 echo '<h3>Cookiso log</h3>'
89 echo '<pre>'
90 cat $log | syntax_highlighter log
91 echo '</pre>' ;;
92 *)
93 # Main page with summary.
94 echo -n "Running command : "
95 if [ -f "$command" ]; then
96 cat $command
97 else
98 echo "Not running"
99 fi
100 cat << EOT
101 <h2>Activity</h2>
102 <pre>
103 $(tac $activity | head -n 12 | syntax_highlighter activity)
104 </pre>
106 <h2>Latest ISO</h2>
107 <pre>
108 $(list_isos | syntax_highlighter activity)
109 </pre>
110 EOT
111 # Rolling Bot log.
112 if [ -f "$rollog" ]; then
113 echo "<h2>Rolling log</h2>"
114 echo '<pre>'
115 cat $rollog
116 echo '</pre>'
117 fi
118 # Rsync log.
119 if [ -f "$synclog" ]; then
120 echo "<h2>Rsync log</h2>"
121 echo '<pre>'
122 awk '{
123 if (/\/s/) h=$0;
124 else {
125 if (h!="") print h;
126 h="";
127 print;
128 }
129 }'< $synclog
130 echo '</pre>'
131 fi ;;
132 esac
134 # Close xHTML page
135 cat << EOT
136 </div>
138 <div id="footer">
139 <a href="http://www.slitaz.org/">SliTaz Website</a>
140 <a href="cookiso.cgi">Cookiso</a>
141 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
142 Documentation</a>
143 </div>
145 </body>
146 </html>
147 EOT
149 exit 0