cookutils view web/cooker.cgi @ rev 5

Added: cooker.cgi web interface
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 03 22:32:00 2011 +0200 (2011-05-03)
parents
children 01dfc1ed1e0e
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker 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 # The same wok as cook.
12 wok="$WOK"
14 # Cooker DB files.
15 activity="$CACHE/activity"
16 commits="$CACHE/commits"
17 cooklist="$CACHE/cooklist"
18 cookorder="$CACHE/cookorder"
19 status="$CACHE/status"
20 blocked="$CACHE/blocked"
21 broken="$CACHE/broken"
23 #
24 # Functions
25 #
27 # Put some colors in log and DB files.
28 syntax_highlighter() {
29 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
30 -e 's#yes$#<span class="span-ok">yes</span>#g' \
31 -e 's#no$#<span class="span-no">no</span>#g' \
32 -e 's#error$#<span class="span-error">error</span>#g' \
33 -e 's#ERROR:#<span class="span-error">ERROR</span>#g' \
34 -e s"#^Executing:\([^']*\).#<span class='span-sky'>\0</span>#"g \
35 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g
36 }
38 # Latest build pkgs.
39 list_packages() {
40 cd $PKGS
41 ls -1t *.tazpkg | head -20 | \
42 while read file
43 do
44 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
45 echo " : $file"
46 done
47 }
49 # xHTML header
50 cat << EOT
51 <!DOCTYPE html>
52 <html xmlns="http://www.w3.org/1999/xhtml">
53 <head>
54 <title>SliTaz Cooker</title>
55 <meta charset="utf-8" />
56 <link rel="stylesheet" type="text/css" href="style.css" />
57 </head>
58 <body>
60 <div id="header">
61 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
62 </div>
64 <!-- Content -->
65 <div id="content">
66 EOT
68 #
69 # Load requested page
70 #
72 case "${QUERY_STRING}" in
73 log=*)
74 pkg=${QUERY_STRING#log=}
75 if [ -f "$LOGS/$pkg.log" ]; then
76 echo '<pre>'
77 if grep -q "cook:$pkg$" $status; then
78 echo "$pkg currently cooking"
79 fi
80 grep -A 8 "Summary" $LOGS/$pkg.log | sed /^$/d | syntax_highlighter
81 echo '</pre>'
82 echo '<pre>'
83 cat $LOGS/$pkg.log | syntax_highlighter
84 echo '</pre>'
85 else
86 echo "<pre>No log file found for: $pkg</pre>"
87 fi ;;
88 *)
89 cat << EOT
90 <div style="float: right;">
91 <form method="get" action="$SCRIPT_NAME">
92 Show log:
93 <input type="text" name="log" />
94 </form>
95 </div>
97 <h2>Summary</h2>
98 <pre>
99 Cooked packages : $(ls $PKGS/*.tazpkg | wc -l)
100 Packages in wok : $(ls $WOK | wc -l)
101 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
102 Commits to cook : $(cat $commits | wc -l)
103 Broken packages : $(cat $broken | wc -l)
104 </pre>
106 <h2>Activity</h2>
107 <pre>
108 $(tac $CACHE/activity | sed s"#^\([^']* : \)#<span class='span-date'>\0</span>#"g)
109 </pre>
111 <h2>Commits</h2>
112 <pre>
113 $(cat $commits)
114 </pre>
116 <h2>Broken</h2>
117 <pre>
118 $(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
119 </pre>
121 <h2>Latest cook</h2>
122 <pre>
123 $(list_packages | sed s"#^\([^']* \)#<span class='span-date'>\0</span>#"g)
124 </pre>
125 EOT
126 ;;
127 esac
129 # Close xHTML page
130 cat << EOT
131 </div>
133 <div id="footer">
134 <a href="http://www.slitaz.org/">SliTaz Cooker</a>
135 </div>
137 </body>
138 </html>
139 EOT
141 exit 0