cookutils view web/cookiso.cgi @ rev 778

cooker.cgi: hide poke argument
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Nov 29 19:35:29 2015 +0100 (2015-11-29)
parents ab08b97140dc
children 1d1f65203fa3
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
12 # Cookiso DB files.
14 cache="$CACHE/cookiso"
15 iso="$SLITAZ/iso"
16 activity="$cache/activity"
17 command="$cache/command"
18 rollog="$cache/rolling.log"
19 synclog="$cache/rsync.log"
22 #
23 # Functions
24 #
26 # Put some colors in log and DB files.
27 syntax_highlighter() {
28 case $1 in
29 log)
30 sed -e 's#OK#<span class="span-ok">OK</span>#g' \
31 -e 's#Failed#<span class="span-red">Failed</span>#g' \
32 -e 's|\(Filesystem size:\).*G\([0-9\.]*M\) *$|\1 \2|' \
33 -e 's|.\[1m|<b>|' -e 's|.\[0m|</b>|' -e 's|.\[[0-9Gm;]*||g' ;;
34 activity)
35 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
36 esac
37 }
40 # Latest build pkgs.
42 list_isos() {
43 cd $iso
44 ls -1t *.iso | head -6 | \
45 while read file; do
46 echo -n $(stat -c '%y' $file | cut -d . -f 1 | sed s/:[0-9]*$//)
47 echo " : $file"
48 done
49 }
52 # xHTML header. Pages can be customized with a separate html.header file.
54 if [ -f 'header.html' ]; then
55 cat header.html | sed s'/Cooker/ISO Cooker/'
56 else
57 cat <<EOT
58 <!DOCTYPE html>
59 <html lang="en">
60 <head>
61 <meta charset="utf-8"/>
62 <title>SliTaz ISO Cooker</title>
63 <link rel="shortcut icon" href="favicon.ico"/>
64 <link rel="stylesheet" type="text/css" href="style.css"/>
65 </head>
66 <body>
68 <div id="header">
69 <div id="logo"></div>
70 <h1><a href="cookiso.cgi">SliTaz ISO Cooker</a></h1>
71 </div>
73 <!-- Content -->
74 <div id="content">
75 EOT
76 fi
78 #
79 # Load requested page
80 #
82 case "${QUERY_STRING}" in
83 distro=*)
84 distro=${QUERY_STRING#distro=}
85 ver=${distro%-core-4in1}
86 log=$iso/slitaz-$ver.log
87 . $SLITAZ/flavors/${distro#*-}/receipt
88 echo "<h2>Distro: $distro</h2>"
89 echo "<p>Description: $SHORT_DESC</p>"
90 echo '<h3>Summary</h3>'
91 echo '<pre>'
92 fgrep "Build time" $log
93 fgrep "Build date" $log
94 fgrep "Packages" $log
95 fgrep "Rootfs size" $log
96 fgrep "ISO image size" $log
97 echo '</pre>'
98 echo '<h3>Cookiso log</h3>'
99 echo '<pre>'
100 cat $log | syntax_highlighter log
101 echo '</pre>' ;;
103 *)
104 # Main page with summary.
105 echo -n 'Running command : '
106 if [ -f "$command" ]; then
107 cat $command
108 else
109 echo 'Not running'
110 fi
111 cat <<EOT
112 <h2>Activity</h2>
113 <pre>
114 $(tac $activity | head -n 12 | syntax_highlighter activity)
115 </pre>
117 <h2>Latest ISO</h2>
118 <pre>
119 $(list_isos | syntax_highlighter activity)
120 </pre>
121 EOT
122 # Rolling Bot log.
123 if [ -f "$rollog" ]; then
124 echo '<h2>Rolling log</h2>'
125 echo '<pre>'
126 cat $rollog
127 echo '</pre>'
128 fi
129 # Rsync log.
130 if [ -f "$synclog" ]; then
131 echo '<h2>Rsync log</h2>'
132 echo '<pre>'
133 awk '{
134 if (/\/s/) h=$0;
135 else {
136 if (h!="") print h;
137 h="";
138 print;
139 }
140 }'< $synclog
141 echo '</pre>'
142 fi ;;
143 esac
146 # Close xHTML page
148 cat <<EOT
149 </div>
151 <div id="footer">
152 <a href="http://www.slitaz.org/">SliTaz Website</a>
153 <a href="cookiso.cgi">Cookiso</a>
154 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
155 Documentation</a>
156 </div>
158 </body>
159 </html>
160 EOT
162 exit 0