cookutils view web/cookiso.cgi @ rev 1145

cooker.cgi: fix src= path
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 05 15:22:15 2020 +0100 (2020-02-05)
parents 1520231a65c2
children
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 -n6 | \
50 while read file; do
51 echo -n $(stat -c '%y' $file | cut -d. -f1 | 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" 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 $(stat -c %y $log | sed 's/:..\..*//')</h3>"
104 for i in $(ls -t $log.*); do
105 echo -n "<a href=\"?log=$(basename $i)\">"
106 echo "$(stat -c %y $i | sed 's/ .*//')</a>"
107 done
108 echo '<pre>'
109 cat $log | syntax_highlighter log
110 echo '</pre>' ;;
112 log=*)
113 log=$iso/${QUERY_STRING#log=}
114 if [ -s $log ]; then
115 echo "<h3>Cook log $(stat -c %y $log | sed 's/:..\..*//')</h3>"
116 echo '<pre>'
117 cat $log | syntax_highlighter log
118 echo '</pre>'
119 fi ;;
121 *)
122 # Main page with summary.
123 echo -n 'Running command : '
124 if [ -f "$command" ]; then
125 cat $command
126 else
127 echo 'Not running'
128 fi
129 cat <<EOT
130 <h2>Activity</h2>
131 <pre>
132 $(tac $activity | head -n 12 | syntax_highlighter activity)
133 </pre>
135 <h2>Latest ISO</h2>
136 <pre>
137 $(list_isos | syntax_highlighter activity)
138 </pre>
139 EOT
140 # Rolling Bot log.
141 if [ -f "$rollog" ]; then
142 echo '<h2>Rolling log</h2>'
143 echo '<pre>'
144 cat $rollog
145 echo '</pre>'
146 fi
147 # Rsync log.
148 if [ -f "$synclog" ]; then
149 echo '<h2>Rsync log</h2>'
150 echo '<pre>'
151 awk '{
152 if (/\/s/) h=$0;
153 else {
154 if (h!="") print h;
155 h="";
156 print;
157 }
158 }'< $synclog
159 echo '</pre>'
160 fi ;;
161 esac
164 # Close xHTML page
166 cat <<EOT
167 </div>
169 <div id="footer">
170 <a href="http://www.slitaz.org/">SliTaz Website</a>
171 <a href="cookiso.cgi">Cookiso</a>
172 <a href="doc/cookutils/cookutils.en.html">Documentation</a>
173 </div>
175 </body>
176 </html>
177 EOT
179 exit 0