cookutils view web/cookiso.cgi @ rev 333

cookiso.cgi: show ISO size on top page
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 17 14:58:33 2012 +0100 (2012-03-17)
parents 55847a3fa287
children d24066e99cec
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 fgrep "ISO image size" $log
91 cat $log | syntax_highlighter log
92 echo '</pre>' ;;
93 *)
94 # Main page with summary.
95 echo -n "Running command : "
96 if [ -f "$command" ]; then
97 cat $command
98 else
99 echo "Not running"
100 fi
101 cat << EOT
102 <h2>Activity</h2>
103 <pre>
104 $(tac $activity | head -n 12 | syntax_highlighter activity)
105 </pre>
107 <h2>Latest ISO</h2>
108 <pre>
109 $(list_isos | syntax_highlighter activity)
110 </pre>
111 EOT
112 # Rolling Bot log.
113 if [ -f "$rollog" ]; then
114 echo "<h2>Rolling log</h2>"
115 echo '<pre>'
116 cat $rollog
117 echo '</pre>'
118 fi
119 # Rsync log.
120 if [ -f "$synclog" ]; then
121 echo "<h2>Rsync log</h2>"
122 echo '<pre>'
123 awk '{
124 if (/\/s/) h=$0;
125 else {
126 if (h!="") print h;
127 h="";
128 print;
129 }
130 }'< $synclog
131 echo '</pre>'
132 fi ;;
133 esac
135 # Close xHTML page
136 cat << EOT
137 </div>
139 <div id="footer">
140 <a href="http://www.slitaz.org/">SliTaz Website</a>
141 <a href="cookiso.cgi">Cookiso</a>
142 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
143 Documentation</a>
144 </div>
146 </body>
147 </html>
148 EOT
150 exit 0