cookutils view web/cookiso.cgi @ rev 331

cookiso.cgi: pack rsync log output
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Mar 16 16:44:10 2012 +0100 (2012-03-16)
parents 00bacdfd1c06
children 55847a3fa287
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 log=$iso/slitaz-$distro.log
80 . $SLITAZ/flavors/${distro#*-}/receipt
81 echo "<h2>Distro: $distro</h2>"
82 echo "<p>Description: $SHORT_DESC</p>"
83 echo '<h3>Cookiso log</h3>'
84 echo '<pre>'
85 cat $log | syntax_highlighter log
86 echo '</pre>' ;;
87 *)
88 # Main page with summary.
89 echo -n "Running command : "
90 if [ -f "$command" ]; then
91 cat $command
92 else
93 echo "Not running"
94 fi
95 cat << EOT
96 <h2>Activity</h2>
97 <pre>
98 $(tac $activity | head -n 12 | syntax_highlighter activity)
99 </pre>
101 <h2>Latest ISO</h2>
102 <pre>
103 $(list_isos | syntax_highlighter activity)
104 </pre>
105 EOT
106 # Rolling Bot log.
107 if [ -f "$rollog" ]; then
108 echo "<h2>Rolling log</h2>"
109 echo '<pre>'
110 cat $rollog
111 echo '</pre>'
112 fi
113 # Rsync log.
114 if [ -f "$synclog" ]; then
115 echo "<h2>Rsync log</h2>"
116 echo '<pre>'
117 awk '{
118 if (/\/s/) h=$0;
119 else {
120 if (h!="") print h;
121 h="";
122 print;
123 }
124 }'< $synclog
125 echo '</pre>'
126 fi ;;
127 esac
129 # Close xHTML page
130 cat << EOT
131 </div>
133 <div id="footer">
134 <a href="http://www.slitaz.org/">SliTaz Website</a>
135 <a href="cookiso.cgi">Cookiso</a>
136 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
137 Documentation</a>
138 </div>
140 </body>
141 </html>
142 EOT
144 exit 0