cookutils view web/cookiso.cgi @ rev 319

Add Cookiso CGI/Web interface
author Christophe Lincoln <pankso@slitaz.org>
date Thu Mar 15 03:02:59 2012 +0100 (2012-03-15)
parents
children 39758ce8dc72
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"
18 #
19 # Functions
20 #
22 # Put some colors in log and DB files.
23 syntax_highlighter() {
24 case $1 in
25 log)
26 sed -e 's#OK#<span class="span-ok">OK</span>#g' \
27 -e 's#Failed#<span class="span-red">Failed</span>#g' \
28 -e 's|\(Filesystem size:\).*G\([0-9\.]*M\) *$|\1 \2|' \
29 -e 's|.\[1m|<b>|' -e 's|.\[0m|</b>|' -e 's|.\[[0-9Gm;]*||g' ;;
30 activity)
31 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
32 esac
33 }
35 # Latest build pkgs.
36 list_isos() {
37 cd $iso
38 ls -1t *.iso | head -6 | \
39 while read file
40 do
41 echo -n $(stat -c '%y' $file | cut -d . -f 1 | sed s/:[0-9]*$//)
42 echo " : $file"
43 done
44 }
46 # xHTML header. Pages can be customized with a separated html.header file.
47 if [ -f "header.html" ]; then
48 cat header.html | sed s'/Cooker/ISO Cooker/'
49 else
50 cat << EOT
51 <!DOCTYPE html>
52 <html xmlns="http://www.w3.org/1999/xhtml">
53 <head>
54 <title>SliTaz ISO Cooker</title>
55 <meta charset="utf-8" />
56 <link rel="shortcut icon" href="favicon.ico" />
57 <link rel="stylesheet" type="text/css" href="style.css" />
58 </head>
59 <body>
61 <div id="header">
62 <div id="logo"></div>
63 <h1><a href="cookiso.cgi">SliTaz ISO Cooker</a></h1>
64 </div>
66 <!-- Content -->
67 <div id="content">
68 EOT
69 fi
71 #
72 # Load requested page
73 #
75 case "${QUERY_STRING}" in
76 distro=*)
77 distro=${QUERY_STRING#distro=}
78 log=$iso/slitaz-$distro.log
79 . $SLITAZ/flavors/${distro#*-}/receipt
80 echo "<h2>Distro: $distro</h2>"
81 echo "<p>Description: $SHORT_DESC</p>"
82 echo '<h3>Cookiso log</h3>'
83 echo '<pre>'
84 cat $log | syntax_highlighter log
85 echo '</pre>' ;;
86 *)
87 # Main page with summary.
88 echo -n "Running command : "
89 if [ -f "$command" ]; then
90 cat $command
91 else
92 echo "Not running"
93 fi
94 cat << EOT
95 <h2>Activity</h2>
96 <pre>
97 $(tac $activity | head -n 12 | syntax_highlighter activity)
98 </pre>
100 <h2>Latest ISO</h2>
101 <pre>
102 $(list_isos | syntax_highlighter activity)
103 </pre>
104 EOT
105 # Rolling Bot log.
106 if [ -f "$rollog" ]; then
107 echo "<h2>Rolling log</h2>"
108 echo '<pre>'
109 cat $rollog
110 echo '</pre>'
111 fi ;;
112 esac
114 # Close xHTML page
115 cat << EOT
116 </div>
118 <div id="footer">
119 <a href="http://www.slitaz.org/">SliTaz Website</a>
120 <a href="cookiso.cgi">Cookiso</a>
121 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
122 Documentation</a>
123 </div>
125 </body>
126 </html>
127 EOT
129 exit 0