cookutils view web/cookiso.cgi @ rev 813
cooker.cgi: show htm
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Jul 05 21:55:50 2016 +0200 (2016-07-05) |
parents | 1d1f65203fa3 |
children | f6478839bdd8 |
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 esc=$'\033'
31 sed -e 's|\(Filesystem size:\).*G\([0-9\.]*M\) *$|\1 \2|' \
32 -e "s|$esc\[1m|<span style=\"color: #008; font-weight: bold\">|g" \
33 -e "s|$esc\[0m|</span>|g" -e "s|$esc\[0;39m|</span>|g" \
34 -e "s|$esc\[0;33m|<span style=\"color: #861\">|g" \
35 -e "s|$esc\[1;31m|<span style=\"color: #F00; font-weight: bold\">|g" \
36 -e "s|$esc\[1;32m|<span style=\"color: #0A0; font-weight: bold\">|g" \
37 -e "s|$esc\[[0-9;]*m|<span>|g"
38 ;;
39 activity)
40 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
41 esac
42 }
45 # Latest build pkgs.
47 list_isos() {
48 cd $iso
49 ls -1t *.iso | head -6 | \
50 while read file; do
51 echo -n $(stat -c '%y' $file | cut -d . -f 1 | sed s/:[0-9]*$//)
52 echo " : $file"
53 done
54 }
57 # xHTML header. Pages can be customized with a separate html.header file.
59 if [ -f 'header.html' ]; then
60 cat header.html | sed s'/Cooker/ISO Cooker/'
61 else
62 cat <<EOT
63 <!DOCTYPE html>
64 <html lang="en">
65 <head>
66 <meta charset="utf-8"/>
67 <title>SliTaz ISO Cooker</title>
68 <link rel="shortcut icon" href="favicon.ico"/>
69 <link rel="stylesheet" type="text/css" href="style.css"/>
70 </head>
71 <body>
73 <div id="header">
74 <div id="logo"></div>
75 <h1><a href="cookiso.cgi">SliTaz ISO Cooker</a></h1>
76 </div>
78 <!-- Content -->
79 <div id="content">
80 EOT
81 fi
83 #
84 # Load requested page
85 #
87 case "${QUERY_STRING}" in
88 distro=*)
89 distro=${QUERY_STRING#distro=}
90 ver=${distro%-core-4in1}
91 log=$iso/slitaz-$ver.log
92 . $SLITAZ/flavors/${distro#*-}/receipt
93 echo "<h2>Distro: $distro</h2>"
94 echo "<p>Description: $SHORT_DESC</p>"
95 echo '<h3>Summary</h3>'
96 echo '<pre>'
97 fgrep "Build time" $log
98 fgrep "Build date" $log
99 fgrep "Packages" $log
100 fgrep "Rootfs size" $log
101 fgrep "ISO image size" $log
102 echo '</pre>'
103 echo '<h3>Cookiso log</h3>'
104 echo '<pre>'
105 cat $log | syntax_highlighter log
106 echo '</pre>' ;;
108 *)
109 # Main page with summary.
110 echo -n 'Running command : '
111 if [ -f "$command" ]; then
112 cat $command
113 else
114 echo 'Not running'
115 fi
116 cat <<EOT
117 <h2>Activity</h2>
118 <pre>
119 $(tac $activity | head -n 12 | syntax_highlighter activity)
120 </pre>
122 <h2>Latest ISO</h2>
123 <pre>
124 $(list_isos | syntax_highlighter activity)
125 </pre>
126 EOT
127 # Rolling Bot log.
128 if [ -f "$rollog" ]; then
129 echo '<h2>Rolling log</h2>'
130 echo '<pre>'
131 cat $rollog
132 echo '</pre>'
133 fi
134 # Rsync log.
135 if [ -f "$synclog" ]; then
136 echo '<h2>Rsync log</h2>'
137 echo '<pre>'
138 awk '{
139 if (/\/s/) h=$0;
140 else {
141 if (h!="") print h;
142 h="";
143 print;
144 }
145 }'< $synclog
146 echo '</pre>'
147 fi ;;
148 esac
151 # Close xHTML page
153 cat <<EOT
154 </div>
156 <div id="footer">
157 <a href="http://www.slitaz.org/">SliTaz Website</a>
158 <a href="cookiso.cgi">Cookiso</a>
159 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
160 Documentation</a>
161 </div>
163 </body>
164 </html>
165 EOT
167 exit 0