rev |
line source |
al@898
|
1 #!/bin/sh
|
al@898
|
2 #
|
al@898
|
3 # SliTaz Cooker CGI + Lighttpd web interface.
|
al@898
|
4 #
|
al@898
|
5
|
al@898
|
6 # Make request URI relative to the script name
|
al@898
|
7 base="$(dirname "$SCRIPT_NAME")"; [ "$base" == '/' ] && base=''
|
al@898
|
8 REQUEST_URI=$(echo "$REQUEST_URI" | sed "s|^$base/*|/|; s|\?.*||")
|
al@898
|
9
|
al@898
|
10 # Split the URI request to /pkg/cmd/arg
|
al@898
|
11 export pkg=$(echo "$REQUEST_URI" | cut -d/ -f2)
|
al@898
|
12 export cmd=$(echo "$REQUEST_URI" | cut -d/ -f3)
|
al@898
|
13 export arg=$(echo "$REQUEST_URI" | sed 's|^/[^/]*/[^/]*/||')
|
al@898
|
14
|
al@898
|
15
|
al@898
|
16 . /usr/lib/slitaz/httphelper.sh
|
al@898
|
17
|
al@898
|
18 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
|
al@898
|
19 [ -f "./cook.conf" ] && . ./cook.conf
|
al@898
|
20 wok="$WOK"
|
al@898
|
21 title=${title:-SliTaz Cooker}
|
al@898
|
22 # Cooker DB files.
|
al@898
|
23 activity="$CACHE/activity"
|
al@898
|
24 commits="$CACHE/commits"
|
al@898
|
25 cooklist="$CACHE/cooklist"
|
al@898
|
26 cookorder="$CACHE/cookorder"
|
al@898
|
27 command="$CACHE/command"; touch $command
|
al@898
|
28 blocked="$CACHE/blocked"
|
al@898
|
29 broken="$CACHE/broken"
|
al@898
|
30 cooknotes="$CACHE/cooknotes"
|
al@898
|
31 cooktime="$CACHE/cooktime"
|
al@898
|
32 wokrev="$CACHE/wokrev"
|
al@898
|
33
|
al@898
|
34 # Path to markdown to html convertor
|
al@898
|
35 cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
|
al@898
|
36 if [ -n "$(which cmark 2>/dev/null)" ]; then
|
al@898
|
37 md2html="$(which cmark) $cmark_opts"
|
al@898
|
38 elif [ -x "./cmark" ]; then
|
al@898
|
39 md2html="./cmark $cmark_opts"
|
al@898
|
40 elif [ -n "$(which sundown 2>/dev/null)" ]; then
|
al@898
|
41 md2html=$(which sundown)
|
al@898
|
42 elif [ -x "./sundown" ]; then
|
al@898
|
43 md2html="./sundown"
|
al@898
|
44 fi
|
al@898
|
45
|
al@898
|
46
|
al@898
|
47
|
al@898
|
48
|
al@898
|
49 # Search form redirection
|
al@898
|
50 if [ -n "$(GET search)" ]; then
|
al@898
|
51 echo -e "HTTP/1.1 301 Moved Permanently\nLocation: $base/$(GET q)\n\n"
|
al@898
|
52 exit 0
|
al@898
|
53 fi
|
al@898
|
54
|
al@898
|
55
|
al@898
|
56 # Show the running command and it's progression
|
al@898
|
57
|
al@898
|
58 running_command() {
|
al@898
|
59 state="$(cat $command)"
|
al@898
|
60 local pct
|
al@898
|
61 if [ -n "$state" ];then
|
al@898
|
62 echo -n "$state</td></tr><tr><td>Completion</td>"
|
al@898
|
63 set -- $(grep "^$state" $cooktime)
|
al@898
|
64 [ -n "$1" -a $2 -ne 0 ] && pct=$((($(date +%s)-$3)*100/$2))
|
al@898
|
65 [ -n "$pct" ] && max="max='100'"
|
al@898
|
66 echo -n "<td><progress id='gauge' $max value='$pct' title='Click to stop updating' onclick='stopUpdating()'>"
|
al@898
|
67 echo -n "</progress> <span id='pct'>${pct:-?}%</span>"
|
al@898
|
68 [ "$2" -gt 60 ] &&
|
al@898
|
69 echo -n "</td></tr><tr><td>Estimated end time</td><td>$(date +%H:%M -ud @$(($2+$3)))"
|
al@898
|
70 else
|
al@898
|
71 echo 'not running'
|
al@898
|
72 fi
|
al@898
|
73 }
|
al@898
|
74
|
al@898
|
75
|
al@898
|
76 # HTML page header
|
al@898
|
77
|
al@898
|
78 page_header() {
|
al@898
|
79 local theme t='' css
|
al@898
|
80 theme=$(COOKIE theme)
|
al@898
|
81 [ "$theme" == 'default' ] && theme=''
|
al@898
|
82 [ -n "$theme" ] && theme="-$theme"
|
al@898
|
83 css="cooker$theme.css"
|
al@898
|
84
|
al@898
|
85 echo -e 'Content-Type: text/html; charset=UTF-8\n'
|
al@898
|
86
|
al@898
|
87 cat <<EOT
|
al@898
|
88 <!DOCTYPE html>
|
al@898
|
89 <html lang="en">
|
al@898
|
90 <head>
|
al@898
|
91 <title>$([ -n "$pkg" ] && echo "$pkg - ")$title</title>
|
al@898
|
92 <link rel="stylesheet" href="/$css">
|
al@898
|
93 <link rel="icon" type="image/png" href="/slitaz-cooker.png">
|
al@898
|
94 <!-- mobile -->
|
al@898
|
95 <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
al@898
|
96 <meta name="theme-color" content="#222">
|
al@898
|
97 <!-- rss -->
|
al@898
|
98 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
|
al@898
|
99 </head>
|
al@898
|
100 <body>
|
al@898
|
101 <div id="container">
|
al@898
|
102 <header>
|
al@898
|
103 <h1><a href="$base/">$title</a></h1>
|
al@898
|
104 <div class="network">
|
al@898
|
105 <a href="http://www.slitaz.org/">Home</a>
|
al@898
|
106 <a href="http://bugs.slitaz.org/">Bugs</a>
|
al@898
|
107 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
|
al@898
|
108 <a href="http://roadmap.slitaz.org/">Roadmap</a>
|
al@898
|
109 <a href="http://pizza.slitaz.me/">Pizza</a>
|
al@898
|
110 <a href="http://tank.slitaz.org/">Tank</a>
|
al@898
|
111 |
|
al@898
|
112 <a href="$base/cross/">Cross</a>
|
al@898
|
113 <a href="$base/i486.cgi">i486</a>
|
al@898
|
114 <a href="$base/cookiso.cgi">ISO</a>
|
al@898
|
115 <select onChange="window.location.href=this.value" style="display: none">
|
al@898
|
116 <option value=".">Go to…</option>
|
al@898
|
117 <option value="http://www.slitaz.org/">Home</option>
|
al@898
|
118 <option value="http://bugs.slitaz.org/">Bug tracker</option>
|
al@898
|
119 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
|
al@898
|
120 <option value="http://roadmap.slitaz.org/">Roadmap</option>
|
al@898
|
121 <option value="http://pizza.slitaz.me/">Pizza</option>
|
al@898
|
122 <option value="http://tank.slitaz.org/">Tank</option>
|
al@898
|
123 <option disabled>---------</option>
|
al@898
|
124 <option value="cross/">Cross</option>
|
al@898
|
125 <option value="i486.cgi">i486</option>
|
al@898
|
126 <option value="cookiso.cgi">ISO</option>
|
al@898
|
127 </select>
|
al@898
|
128 </div>
|
al@898
|
129 </header>
|
al@898
|
130
|
al@898
|
131 <main>
|
al@898
|
132 EOT
|
al@898
|
133
|
al@898
|
134 [ -n "$(GET debug)" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
|
al@898
|
135 }
|
al@898
|
136
|
al@898
|
137
|
al@898
|
138 # HTML page footer
|
al@898
|
139
|
al@898
|
140 page_footer() {
|
al@898
|
141 date_now=$(date +%s)
|
al@898
|
142 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
|
al@898
|
143 wait_sec=$(( 60 - $sec_now ))
|
al@898
|
144 cat <<EOT
|
al@898
|
145 </main>
|
al@898
|
146
|
al@898
|
147 <footer>
|
al@898
|
148 <a href="http://www.slitaz.org/">SliTaz Website</a>
|
al@898
|
149 <a href="$base/">Cooker</a>
|
al@898
|
150 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
|
al@898
|
151 <a href="$base/?theme">Theme</a>
|
al@898
|
152 </footer>
|
al@898
|
153 </div>
|
al@898
|
154 <script src="/cooker.js"></script>
|
al@898
|
155 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
|
al@898
|
156 </body>
|
al@898
|
157 </html>
|
al@898
|
158 EOT
|
al@898
|
159 }
|
al@898
|
160
|
al@898
|
161
|
al@898
|
162 show_note() {
|
al@898
|
163 echo "<div class='bigicon-$1'>$2</div>"
|
al@898
|
164 }
|
al@898
|
165
|
al@898
|
166
|
al@898
|
167 not_found() {
|
al@898
|
168 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
|
al@898
|
169 echo "HTTP/1.1 404 Not Found"
|
al@898
|
170 page_header
|
al@898
|
171 echo "<h2>Not Found</h2>"
|
al@898
|
172 case $2 in
|
al@898
|
173 pkg)
|
al@898
|
174 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
|
al@898
|
175 *)
|
al@898
|
176 show_note e "The requested file “$file” was not found." ;;
|
al@898
|
177 esac
|
al@898
|
178 page_footer
|
al@898
|
179 }
|
al@898
|
180
|
al@898
|
181
|
al@898
|
182 manage_modified() {
|
al@898
|
183 local file="$1" option="$2" nul day mon year time hh mm ss date_s
|
al@898
|
184 if [ ! -f "$file" ]; then
|
al@898
|
185 if [ "$option" == 'silently-absent' ]; then
|
al@898
|
186 echo "HTTP/1.1 404 Not Found"
|
al@898
|
187 return
|
al@898
|
188 else
|
al@898
|
189 not_found "$file" "$2"
|
al@898
|
190 exit
|
al@898
|
191 fi
|
al@898
|
192 fi
|
al@898
|
193 [ "$option" == 'no-last-modified' ] && return
|
al@898
|
194 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
|
al@898
|
195 echo "$HTTP_IF_MODIFIED_SINCE" | \
|
al@898
|
196 while read nul day mon year time nul; do
|
al@898
|
197 case $mon in
|
al@898
|
198 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
|
al@898
|
199 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
|
al@898
|
200 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
|
al@898
|
201 esac
|
al@898
|
202 hh=$(echo $time | cut -d: -f1)
|
al@898
|
203 mm=$(echo $time | cut -d: -f2)
|
al@898
|
204 ss=$(echo $time | cut -d: -f3)
|
al@898
|
205 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
|
al@898
|
206 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
|
al@898
|
207 # echo -e 'HTTP/1.1 304 Not Modified\n'
|
al@898
|
208 # exit
|
al@898
|
209 # fi
|
al@898
|
210 # TODO: improve caching control
|
al@898
|
211 done
|
al@898
|
212 fi
|
al@898
|
213 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
|
al@898
|
214 echo "Cache-Control: public, max-age=3600"
|
al@898
|
215 }
|
al@898
|
216
|
al@898
|
217
|
al@898
|
218 # Query '?pct=<package>': update percentage
|
al@898
|
219
|
al@898
|
220 if [ -n "$(GET pct)" ]; then
|
al@898
|
221 pkg="$(GET pct)"
|
al@898
|
222 state="$(cat $command)"
|
al@898
|
223 if [ "$state" == "cook:$pkg" ]; then
|
al@898
|
224 set -- $(grep "^$state" $cooktime)
|
al@898
|
225 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
|
al@898
|
226 echo "${pct:-?}"
|
al@898
|
227 else
|
al@898
|
228 echo 'reload'
|
al@898
|
229 fi
|
al@898
|
230 exit 0
|
al@898
|
231 fi
|
al@898
|
232
|
al@898
|
233
|
al@898
|
234 # Query '?poke': poke cooker
|
al@898
|
235
|
al@898
|
236 if [ -n "$(GET poke)" ]; then
|
al@898
|
237 touch $CACHE/cooker-request
|
al@898
|
238 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
|
al@898
|
239 exit
|
al@898
|
240 fi
|
al@898
|
241
|
al@898
|
242
|
al@898
|
243 # Query '?recook=<package>': query to recook package
|
al@898
|
244
|
al@898
|
245 if [ -n "$(GET recook)" ]; then
|
al@898
|
246 pkg="$(GET recook)"
|
al@898
|
247 case "$HTTP_USER_AGENT" in
|
al@898
|
248 *SliTaz*)
|
al@898
|
249 grep -qs "^$pkg$" $CACHE/recook-packages ||
|
al@898
|
250 echo "$pkg" >> $CACHE/recook-packages
|
al@898
|
251 esac
|
al@898
|
252 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
|
al@898
|
253 exit
|
al@898
|
254 fi
|
al@898
|
255
|
al@898
|
256
|
al@898
|
257 # Query '/i/<log>/<pkg>': show indicator icon
|
al@898
|
258 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
|
al@898
|
259
|
al@898
|
260 if [ "$pkg" == 'i' ]; then
|
al@898
|
261 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
|
al@898
|
262 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
|
al@898
|
263 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
|
al@898
|
264 else
|
al@898
|
265 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
|
al@898
|
266 fi
|
al@898
|
267 exit
|
al@898
|
268 fi
|
al@898
|
269
|
al@898
|
270
|
al@898
|
271 # Query '?theme[=<theme>]': change UI theme
|
al@898
|
272
|
al@898
|
273 if [ -n "$(GET theme)" ]; then
|
al@898
|
274 theme="$(GET theme)"
|
al@898
|
275 case $theme in
|
al@898
|
276 theme)
|
al@898
|
277 current=$(COOKIE theme)
|
al@898
|
278 page_header
|
al@898
|
279 cat <<EOT
|
al@898
|
280 <section>
|
al@898
|
281 <h2>Change theme</h2>
|
al@898
|
282 <p>Current theme: “${current:-default}”. Select other:</p>
|
al@898
|
283 <ul>
|
al@898
|
284 $(
|
al@898
|
285 for i in default emerald sky goldenrod like2016 terminal; do
|
al@898
|
286 [ "$i" == "${current:-default}" ] || echo "<li><a href="$base/?theme=$i">$i</a></li>"
|
al@898
|
287 done
|
al@898
|
288 )
|
al@898
|
289 </ul>
|
al@898
|
290 </section>
|
al@898
|
291 EOT
|
al@898
|
292 page_footer
|
al@898
|
293 exit 0
|
al@898
|
294 ;;
|
al@898
|
295 default|emerald|sky|goldenrod|like2016|terminal)
|
al@898
|
296 # Expires in a year
|
al@898
|
297 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
|
al@898
|
298 echo -e "HTTP/1.1 302 Found\nLocation: $base/\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
|
al@898
|
299 exit 0
|
al@898
|
300 ;;
|
al@898
|
301 esac
|
al@898
|
302 fi
|
al@898
|
303
|
al@898
|
304
|
al@898
|
305 #case "$QUERY_STRING" in
|
al@898
|
306 # stuff*)
|
al@898
|
307 # file="$wok/$(GET stuff)"
|
al@898
|
308 # manage_modified "$file"
|
al@898
|
309 # ;;
|
al@898
|
310 #
|
al@898
|
311 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
|
al@898
|
312 # type=${QUERY_STRING%%=*}
|
al@898
|
313 # pkg=$(GET $type)
|
al@898
|
314 # case "$type" in
|
al@898
|
315 # description)
|
al@898
|
316 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
|
al@898
|
317 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
|
al@898
|
318 # ;;
|
al@898
|
319 # log)
|
al@898
|
320 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
|
al@898
|
321 # manage_modified "$LOGS/$pkg"
|
al@898
|
322 # ;;
|
al@898
|
323 # *)
|
al@898
|
324 # manage_modified "$wok/$pkg/receipt" pkg
|
al@898
|
325 # ;;
|
al@898
|
326 # esac
|
al@898
|
327 # ;;
|
al@898
|
328 #esac
|
al@898
|
329
|
al@898
|
330
|
al@898
|
331 # RSS feed generator
|
al@898
|
332 # URI: ?rss[&limit={1..100}]
|
al@898
|
333
|
al@898
|
334 if [ -n "$(GET rss)" ]; then
|
al@898
|
335 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
|
al@898
|
336 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
|
al@898
|
337 cooker_url="http://$HTTP_HOST$base/"
|
al@898
|
338 cat <<EOT
|
al@898
|
339 Content-Type: application/rss+xml
|
al@898
|
340
|
al@898
|
341 <?xml version="1.0" encoding="utf-8" ?>
|
al@898
|
342 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
al@898
|
343 <channel>
|
al@898
|
344 <title>$title</title>
|
al@898
|
345 <description>The SliTaz packages cooker feed</description>
|
al@898
|
346 <link>$cooker_url</link>
|
al@898
|
347 <lastBuildDate>$pubdate</lastBuildDate>
|
al@898
|
348 <pubDate>$pubdate</pubDate>
|
al@898
|
349 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
|
al@898
|
350 EOT
|
al@898
|
351 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
|
al@898
|
352 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $rss
|
al@898
|
353 done
|
al@898
|
354 cat <<EOT
|
al@898
|
355 </channel>
|
al@898
|
356 </rss>
|
al@898
|
357 EOT
|
al@898
|
358 exit 0
|
al@898
|
359 fi
|
al@898
|
360
|
al@898
|
361
|
al@898
|
362
|
al@898
|
363
|
al@898
|
364 #
|
al@898
|
365 # Functions
|
al@898
|
366 #
|
al@898
|
367
|
al@898
|
368
|
al@898
|
369 # Unpack to stdout
|
al@898
|
370
|
al@898
|
371 docat() {
|
al@898
|
372 case "$1" in
|
al@898
|
373 *gz) zcat ;;
|
al@898
|
374 *bz2) bzcat ;;
|
al@898
|
375 *xz) xzcat ;;
|
al@898
|
376 *) cat
|
al@898
|
377 esac < $1
|
al@898
|
378 }
|
al@898
|
379
|
al@898
|
380
|
al@898
|
381 # Tiny texinfo converter
|
al@898
|
382
|
al@898
|
383 info2html() {
|
al@898
|
384 sed \
|
al@898
|
385 -e 's|&|\&|g; s|<|\<|g; s|>|\>|g' \
|
al@898
|
386 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
|
al@898
|
387 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
|
al@898
|
388 -e '/^File: / s|(dir)|Top|g' \
|
al@898
|
389 -e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
|
al@898
|
390 -e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
|
al@898
|
391 -e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
|
al@898
|
392 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
|
al@898
|
393 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
|
al@898
|
394 -e '/^Tag Table:$/,/^End Tag Table$/d' \
|
al@898
|
395 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
|
al@898
|
396 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
|
al@898
|
397 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
|
al@898
|
398 -e 's|^\* Menu:|<b>Menu:</b>|' \
|
al@898
|
399 -e "s|^|</pre>|"
|
al@898
|
400 }
|
al@898
|
401
|
al@898
|
402
|
al@898
|
403 # Put some colors into log and DB files.
|
al@898
|
404
|
al@898
|
405 syntax_highlighter() {
|
al@898
|
406 case $1 in
|
al@898
|
407 log)
|
al@898
|
408 # If variables not defined - define them with some rare values
|
al@898
|
409 : ${_src=#_#_#}
|
al@898
|
410 : ${_install=#_#_#}
|
al@898
|
411 : ${_fs=#_#_#}
|
al@898
|
412 : ${_stuff=#_#_#}
|
al@898
|
413 # Use one-letter html tags to save some bytes :)
|
al@898
|
414 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informal (green)</i>
|
al@898
|
415 sed -e 's/&/\&/g; s/</\</g; s/>/\>/g' \
|
al@898
|
416 -e 's#OK$#<i>OK</i>#' \
|
al@898
|
417 -e 's#\([Dd]one\)$#<i>\1</i>#' \
|
al@898
|
418 -e 's#Success$#<i>Success</i>#' \
|
al@898
|
419 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
|
al@898
|
420 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
|
al@898
|
421 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
|
al@898
|
422 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
|
al@898
|
423 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
|
al@898
|
424 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
|
al@898
|
425 \
|
al@898
|
426 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
|
al@898
|
427 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
|
al@898
|
428 -e 's# y$# <i>y</i>#' \
|
al@898
|
429 -e 's# n$# <u>n</u>#' \
|
al@898
|
430 -e 's#(NEW) *$#<b>(NEW)</b>#' \
|
al@898
|
431 \
|
al@898
|
432 -e 's#.*(pkg/local).*#<i>\0</i>#' \
|
al@898
|
433 -e 's#.*(web/cache).*#<u>\0</u>#' \
|
al@898
|
434 \
|
al@898
|
435 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
|
al@898
|
436 -e 's#ERROR:#<b>ERROR:</b>#g' \
|
al@898
|
437 \
|
al@898
|
438 -e 's#^.*[Ff]ailed.*#<b>\0</b>#' \
|
al@898
|
439 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
|
al@898
|
440 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
|
al@898
|
441 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
|
al@898
|
442 -e 's#^.*No package .* found.*#<b>\0</b>#' \
|
al@898
|
443 -e 's#^.*Unable to find.*#<b>\0</b>#' \
|
al@898
|
444 -e 's#^.*[Ii]nvalid.*#<b>\0</b>#' \
|
al@898
|
445 -e 's#\([Nn][Oo][Tt] found\)$#<b>\1</b>#' \
|
al@898
|
446 -e 's#\(found\)$#<i>\1</i>#' \
|
al@898
|
447 \
|
al@898
|
448 -e 's#^.*WARNING:.*#<u>\0</u>#' \
|
al@898
|
449 -e 's#^.*warning:.*#<u>\0</u>#' \
|
al@898
|
450 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
|
al@898
|
451 -e 's#^.*terminated.*#<b>\0</b>#' \
|
al@898
|
452 -e 's#\(missing\)#<b>\1</b>#g' \
|
al@898
|
453 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
|
al@898
|
454 -e 's#^.*unrecognized options.*#<u>\0</u>#' \
|
al@898
|
455 -e 's#^.*does not.*#<u>\0</u>#' \
|
al@898
|
456 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
|
al@898
|
457 -e 's#^.*note:.*#<u>\0</u>#' \
|
al@898
|
458 \
|
al@898
|
459 -e 's#^.* will not .*#<u>\0</u>#' \
|
al@898
|
460 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
|
al@898
|
461 -e 's#^.* Warning: .*#<u>\0</u>#' \
|
al@898
|
462 \
|
al@898
|
463 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
|
al@898
|
464 -e "s#^Making.*#<em>\0</em>#" \
|
al@898
|
465 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
|
al@898
|
466 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
|
al@898
|
467 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
|
al@898
|
468 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
|
al@898
|
469 \
|
al@898
|
470 -e "s|$_src|<span class='var'>\${src}</span>|g;
|
al@898
|
471 s|$_install|<span class='var'>\${install}</span>|g;
|
al@898
|
472 s|$_fs|<span class='var'>\${fs}</span>|g;
|
al@898
|
473 s|$_stuff|<span class='var'>\${stuff}</span>|g" \
|
al@898
|
474 -e "s|\[9\([1-6]\)m|<span class='c\1'>|;
|
al@898
|
475 s|\[39m|</span>|;"
|
al@898
|
476 ;;
|
al@898
|
477
|
al@898
|
478 files)
|
al@898
|
479 # Highlight the Busybox's `ls` output
|
al@898
|
480 awk '{
|
al@898
|
481 part1 = substr($0, 0, 16);
|
al@898
|
482 part2 = substr($0, 17, 9);
|
al@898
|
483 part3 = substr($0, 26, 9);
|
al@898
|
484 part4 = substr($0, 35);
|
al@898
|
485 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
|
al@898
|
486 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
|
al@898
|
487 print part1 part2 part3 part4;
|
al@898
|
488 }' | \
|
al@898
|
489 sed "s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
|
al@898
|
490 s|\[\([01]\);0m|<a class='c0\1'>|g;
|
al@898
|
491 s|\[0m|</a>|g;
|
al@898
|
492 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
|
al@898
|
493 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
|
al@898
|
494 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
|
al@898
|
495 s|^\([lrwx-]*\)|<span class='c11'>\1</span>|;
|
al@898
|
496 "
|
al@898
|
497 ;;
|
al@898
|
498 esac
|
al@898
|
499 }
|
al@898
|
500
|
al@898
|
501
|
al@898
|
502 show_code() {
|
al@898
|
503 echo -n "<pre><code class=\"language-$1\">"
|
al@898
|
504 sed 's|&|\&|g; s|<|\<|g; s|>|\>|g'
|
al@898
|
505 echo '</code></pre>'
|
al@898
|
506 }
|
al@898
|
507
|
al@898
|
508
|
al@898
|
509 datalist() {
|
al@898
|
510 (
|
al@898
|
511 cd $wok
|
al@898
|
512
|
al@898
|
513 ls | awk '
|
al@898
|
514 BEGIN{printf("<datalist id=\"packages\">")}
|
al@898
|
515 {printf("<option>%s</option>",$1)}
|
al@898
|
516 END {printf("</datalist>")}
|
al@898
|
517 '
|
al@898
|
518 )
|
al@898
|
519 }
|
al@898
|
520
|
al@898
|
521
|
al@898
|
522 mklog() {
|
al@898
|
523 awk '
|
al@898
|
524 BEGIN { printf("<pre class=\"log dog\">\n") }
|
al@898
|
525 { print }
|
al@898
|
526 END { print "</pre>" }'
|
al@898
|
527 }
|
al@898
|
528
|
al@898
|
529
|
al@898
|
530 summary() {
|
al@898
|
531 log="$1"
|
al@898
|
532 pkg="$(basename ${log%%.log*})"
|
al@898
|
533
|
al@898
|
534 if [ -f "$log" ]; then
|
al@898
|
535 if grep -q "cook:$pkg$" $command; then
|
al@898
|
536 show_note i "The Cooker is currently building $pkg"
|
al@898
|
537 elif fgrep -q "Summary for:" $log; then
|
al@898
|
538 sed '/^Summary for:/,$!d' $log | head -n13 | awk '
|
al@898
|
539 BEGIN { print "<section>" }
|
al@898
|
540 {
|
al@898
|
541 if (NR==1) {
|
al@898
|
542 printf("<h3>%s</h3>\n<table>\n", $0)
|
al@898
|
543 } else if ($0 !~ "===") {
|
al@898
|
544 split($0, s, " : ");
|
al@898
|
545 printf("<tr><td>%s</td><td>%s</td></tr>", s[1], s[2]);
|
al@898
|
546 }
|
al@898
|
547 }
|
al@898
|
548 END { print "</table></section>" }
|
al@898
|
549 '
|
al@898
|
550 elif fgrep -q "Debug information" $log; then
|
al@898
|
551 echo -e '<section>\n<h3>Debug information</h3>'
|
al@898
|
552 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
|
al@898
|
553 if [ -n "$2" ]; then
|
al@898
|
554 syntax_highlighter log | sed 's|\([0-9][0-9]*\):|<a href="#l\1">\1</a>:|'
|
al@898
|
555 else
|
al@898
|
556 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
|
al@898
|
557 fi | mklog
|
al@898
|
558 echo '</section>'
|
al@898
|
559 fi
|
al@898
|
560 else
|
al@898
|
561 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
|
al@898
|
562 fi
|
al@898
|
563 }
|
al@898
|
564
|
al@898
|
565
|
al@898
|
566 active() {
|
al@898
|
567 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
|
al@898
|
568 }
|
al@898
|
569
|
al@898
|
570
|
al@898
|
571 pkg_info() {
|
al@898
|
572 local log active bpkg
|
al@898
|
573 log="$LOGS/$pkg.log"
|
al@898
|
574
|
al@898
|
575 echo "<h2>Package “$pkg”</h2>"
|
al@898
|
576 echo '<div id="info">'
|
al@898
|
577 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt & stuff</a>"
|
al@898
|
578
|
al@898
|
579 unset WEB_SITE WANTED
|
al@898
|
580 . $wok/$pkg/receipt
|
al@898
|
581
|
al@898
|
582 [ -n "$WEB_SITE" ] &&
|
al@898
|
583 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
|
al@898
|
584
|
al@898
|
585 if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
|
al@898
|
586 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
|
al@898
|
587
|
al@898
|
588 [ -f "$wok/$pkg/description.txt" ] &&
|
al@898
|
589 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
|
al@898
|
590
|
al@898
|
591 unset EXTRAVERSION
|
al@898
|
592 . $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
|
al@898
|
593 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
|
al@898
|
594 [ -f "$PKGS/$filename" ] &&
|
al@898
|
595 echo "<a class='button icon download' href='$base/get/$filename'>download</a>"
|
al@898
|
596 done
|
al@898
|
597
|
al@898
|
598 fi
|
al@898
|
599
|
al@898
|
600 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ] &&
|
al@898
|
601 echo "<a class='button icon source' href='$base/src/$TARBALL'>source</a>"
|
al@898
|
602
|
al@898
|
603 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
|
al@898
|
604
|
al@898
|
605 [ -x ./man2html -a -d "$wok/$pkg/install/usr/share/man" ] &&
|
al@898
|
606 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
|
al@898
|
607
|
al@898
|
608 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
|
al@898
|
609 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
|
al@898
|
610
|
al@898
|
611 [ -d "$wok/$pkg/install/usr/share/info" ] &&
|
al@898
|
612 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
|
al@898
|
613
|
al@898
|
614 [ -s "$log" ] &&
|
al@898
|
615 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
|
al@898
|
616
|
al@898
|
617 echo '</div>'
|
al@898
|
618 }
|
al@898
|
619
|
al@898
|
620
|
al@898
|
621 mktable() {
|
al@898
|
622 sed 's# : #|#' | awk -vc="$1" '
|
al@898
|
623 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
|
al@898
|
624 { printf("<tr><td>%s</td>", $1);
|
al@898
|
625 if (NF == 2) printf("<td>%s</td>", $2);
|
al@898
|
626 printf("</tr>\n", $2) }
|
al@898
|
627 END { print "</table>" }'
|
al@898
|
628 }
|
al@898
|
629
|
al@898
|
630
|
al@898
|
631 section() {
|
al@898
|
632 local i=$(basename "$1")
|
al@898
|
633 echo -e '\n\n<section>'
|
al@898
|
634 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
|
al@898
|
635 echo "<h2>${3%|*}</h2>"
|
al@898
|
636 mktable "$i"
|
al@898
|
637 echo '</section>'
|
al@898
|
638 }
|
al@898
|
639
|
al@898
|
640
|
al@898
|
641
|
al@898
|
642
|
al@898
|
643 #
|
al@898
|
644 # Load requested page
|
al@898
|
645 #
|
al@898
|
646
|
al@898
|
647 if [ -z "$pkg" ]; then
|
al@898
|
648
|
al@898
|
649 page_header
|
al@898
|
650 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
|
al@898
|
651
|
al@898
|
652 for list in activity cooknotes cooklist; do
|
al@898
|
653 [ -n "$(GET $list)" ] || continue
|
al@898
|
654 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
|
al@898
|
655 echo '<section id="content2">'
|
al@898
|
656 echo "<h2>DB: $list $nb</h2>"
|
al@898
|
657 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||;
|
al@898
|
658 s|\[ Done|<span class="r c20">Done|;
|
al@898
|
659 s|\[ Failed|<span class="r c10">Failed|;
|
al@898
|
660 s| \]|</span>|' | mktable $list
|
al@898
|
661 echo '</section>'
|
al@898
|
662 done
|
al@898
|
663
|
al@898
|
664 if [ -n "$(GET broken)" ]; then
|
al@898
|
665 echo '<div id="content2">'
|
al@898
|
666 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
|
al@898
|
667 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
|
al@898
|
668 echo '</div>'
|
al@898
|
669 fi
|
al@898
|
670
|
al@898
|
671 case "$QUERY_STRING" in
|
al@898
|
672 *.log)
|
al@898
|
673 log=$LOGS/$QUERY_STRING
|
al@898
|
674 name=$(basename $log)
|
al@898
|
675 if [ -f "$log" ]; then
|
al@898
|
676 echo "<h2>Log for: ${name%.log}</h2>"
|
al@898
|
677 if fgrep -q "Summary" $log; then
|
al@898
|
678 echo '<pre class="log">'
|
al@898
|
679 grep -A 20 '^Summary' $log | syntax_highlighter log
|
al@898
|
680 echo '</pre>'
|
al@898
|
681 fi
|
al@898
|
682 echo '<pre class="log">'
|
al@898
|
683 syntax_highlighter log < $log
|
al@898
|
684 echo '</pre>'
|
al@898
|
685 else
|
al@898
|
686 show_note e "No log file: $log"
|
al@898
|
687 fi
|
al@898
|
688 ;;
|
al@898
|
689 esac
|
al@898
|
690 page_footer
|
al@898
|
691 exit 0
|
al@898
|
692 fi
|
al@898
|
693
|
al@898
|
694
|
al@898
|
695 # We may have a toolchain.cgi script for cross cooker's
|
al@898
|
696 if [ -f "toolchain.cgi" ]; then
|
al@898
|
697 toolchain="toolchain.cgi"
|
al@898
|
698 else
|
al@898
|
699 toolchain="slitaz-toolchain/"
|
al@898
|
700 fi
|
al@898
|
701 # Main page with summary. Count only package include in ARCH,
|
al@898
|
702 # use 'cooker arch-db' to manually create arch.$ARCH files.
|
al@898
|
703 inwok=$(ls $WOK/*/arch.$ARCH | wc -l)
|
al@898
|
704 cooked=$(ls $PKGS/*.tazpkg | wc -l)
|
al@898
|
705 unbuilt=$(($inwok - $cooked))
|
al@898
|
706 pct=0; [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
|
al@898
|
707 cat <<EOT
|
al@898
|
708 <div id="content2">
|
al@898
|
709
|
al@898
|
710 <section>
|
al@898
|
711 <form method="get" action="" class="search r">
|
al@898
|
712 <input type="hidden" name="search" value="pkg"/>
|
al@898
|
713 <button type="submit" title="Search">Search</button>
|
al@898
|
714 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
|
al@898
|
715 </form>
|
al@898
|
716
|
al@898
|
717 <h2>Summary</h2>
|
al@898
|
718 EOT
|
al@898
|
719
|
al@898
|
720 mktable <<EOT
|
al@898
|
721 Cooker state : $(running_command)
|
al@898
|
722 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
|
al@898
|
723 Commits to cook : $(wc -l < $commits)
|
al@898
|
724 Current cooklist : $(wc -l < $cooklist)
|
al@898
|
725 Broken packages : $(wc -l < $broken)
|
al@898
|
726 Blocked packages : $(wc -l < $blocked)
|
al@898
|
727 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
|
al@898
|
728 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
|
al@898
|
729 EOT
|
al@898
|
730
|
al@898
|
731 # If command is "cook:*", update gauge and percentage periodically.
|
al@898
|
732 # If different package is cooking, reload the page (with new settings)
|
al@898
|
733 cmd="$(cat $command)"
|
al@898
|
734 case "$cmd" in
|
al@898
|
735 cook:*)
|
al@898
|
736 pkg=${cmd#*:}
|
al@898
|
737 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
|
al@898
|
738 ;;
|
al@898
|
739 esac
|
al@898
|
740
|
al@898
|
741 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
|
al@898
|
742 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
|
al@898
|
743 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
|
al@898
|
744 else
|
al@898
|
745 show_note i 'Cooker will be launched in the next 5 minutes.'
|
al@898
|
746 fi
|
al@898
|
747 fi
|
al@898
|
748
|
al@898
|
749 cat <<EOT
|
al@898
|
750 <p>Packages: $inwok in the wok · $cooked cooked · $unbuilt unbuilt</p>
|
al@898
|
751
|
al@898
|
752 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
|
al@898
|
753
|
al@898
|
754 <p>
|
al@898
|
755 Service logs:
|
al@898
|
756 <a href="?cookorder.log">cookorder</a> ·
|
al@898
|
757 <a href="?commits.log">commits</a> ·
|
al@898
|
758 <a href="?pkgdb.log">pkgdb</a>
|
al@898
|
759 </p>
|
al@898
|
760 </section>
|
al@898
|
761 EOT
|
al@898
|
762
|
al@898
|
763 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
|
al@898
|
764 s|\[ Done|<span class="r c20">Done|;
|
al@898
|
765 s|\[ Failed|<span class="r c10">Failed|;
|
al@898
|
766 s| \]|</span>|;
|
al@898
|
767 s|%2B|\+|g' | \
|
al@898
|
768 section $activity 12 "Activity|More activity"
|
al@898
|
769
|
al@898
|
770 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
|
al@898
|
771 section $cooknotes 12 "Cooknotes|More notes"
|
al@898
|
772
|
al@898
|
773 [ -s "$commits" ] &&
|
al@898
|
774 section $commits 20 "Commits|More commits" < $commits
|
al@898
|
775
|
al@898
|
776 [ -s "$cooklist" ] && head -n 20 $cooklist | \
|
al@898
|
777 section $cooklist 20 "Cooklist|Full cooklist"
|
al@898
|
778
|
al@898
|
779 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
|
al@898
|
780 section $broken 20 "Broken|All broken packages"
|
al@898
|
781
|
al@898
|
782 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
|
al@898
|
783 section $blocked 12 "Blocked|All blocked packages"
|
al@898
|
784
|
al@898
|
785 cd $PKGS
|
al@898
|
786 ls -let *.tazpkg | awk '
|
al@898
|
787 (NR<=20){
|
al@898
|
788 sub(/:[0-9][0-9]$/, "", $9);
|
al@898
|
789 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
|
al@898
|
790 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
|
al@898
|
791 }' | \
|
al@898
|
792 section $activity 1000 "Latest cook"
|
al@898
|
793
|
al@898
|
794 echo '</div>'
|
al@898
|
795 datalist
|
al@898
|
796 page_footer
|
al@898
|
797 exit 0
|
al@898
|
798 fi
|
al@898
|
799
|
al@898
|
800
|
al@898
|
801 case "$cmd" in
|
al@898
|
802 '')
|
al@898
|
803 page_header
|
al@898
|
804 log=$LOGS/$pkg.log
|
al@898
|
805
|
al@898
|
806 # Package info.
|
al@898
|
807 if [ -f "$wok/$pkg/receipt" ]; then
|
al@898
|
808 pkg_info
|
al@898
|
809 else
|
al@898
|
810 if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then
|
al@898
|
811 echo "<h2>Not Found</h2>"
|
al@898
|
812 show_note e "The requested package <b>$pkg</b> was not found on this server."
|
al@898
|
813 else
|
al@898
|
814 # Search page
|
al@898
|
815 echo "<section><h2>Package names matching “$pkg”</h2>"
|
al@898
|
816 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
|
al@898
|
817 for i in $(cd $wok; ls *$pkg*/receipt); do
|
al@898
|
818 pkg=$(dirname $i)
|
al@898
|
819 unset SHORT_DESC CATEGORY
|
al@898
|
820 . $wok/$pkg/receipt
|
al@898
|
821 echo -n "<tr><td><a href="$base/$pkg">$pkg</a></td>"
|
al@898
|
822 echo -n "<td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
|
al@898
|
823 done
|
al@898
|
824 echo '</tbody></table></section>'
|
al@898
|
825 unset pkg
|
al@898
|
826 fi
|
al@898
|
827 page_footer
|
al@898
|
828 exit 0
|
al@898
|
829 fi
|
al@898
|
830
|
al@898
|
831 # Check for a log file and display summary if it exists.
|
al@898
|
832 summary "$log"
|
al@898
|
833
|
al@898
|
834 # Display <Recook> button only for SliTaz web browser
|
al@898
|
835 if [ -f "$log" ]; then
|
al@898
|
836 case "$HTTP_USER_AGENT" in
|
al@898
|
837 *SliTaz*)
|
al@898
|
838 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
|
al@898
|
839 if grep -qs "^$pkg$" $CACHE/recook-packages; then
|
al@898
|
840 show_note i "The package “$pkg” has been requested for recook"
|
al@898
|
841 else
|
al@898
|
842 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
|
al@898
|
843 fi
|
al@898
|
844 fi
|
al@898
|
845 ;;
|
al@898
|
846 esac
|
al@898
|
847 fi
|
al@898
|
848 ;;
|
al@898
|
849
|
al@898
|
850 receipt)
|
al@898
|
851 page_header
|
al@898
|
852 pkg_info
|
al@898
|
853 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
|
al@898
|
854 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
|
al@898
|
855 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
|
al@898
|
856
|
al@898
|
857 show_code bash < $wok/$pkg/receipt
|
al@898
|
858 ;;
|
al@898
|
859
|
al@898
|
860 stuff)
|
al@898
|
861 page_header
|
al@898
|
862 pkg_info
|
al@898
|
863 file="$pkg/stuff/$arg"
|
al@898
|
864 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
|
al@898
|
865 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
|
al@898
|
866 awk -vb="$base/$pkg" -va="stuff/$arg" '{
|
al@898
|
867 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
|
al@898
|
868 }'
|
al@898
|
869
|
al@898
|
870 if [ -f "$wok/$file" ]; then
|
al@898
|
871 case $file in
|
al@898
|
872 *.desktop|*.theme) class="ini" ;;
|
al@898
|
873 *.patch|*.diff|*.u) class="diff" ;;
|
al@898
|
874 *.sh) class="bash" ;;
|
al@898
|
875 *.conf*|*.ini)
|
al@898
|
876 class="bash"
|
al@898
|
877 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
|
al@898
|
878 ;;
|
al@898
|
879 *.pl) class="perl" ;;
|
al@898
|
880 *.c|*.h|*.awk) class="clike" ;;
|
al@898
|
881 *.svg) class="svg" ;;
|
al@898
|
882 *Makefile*) class="makefile" ;;
|
al@898
|
883 *.po|*.pot) class="bash" ;;
|
al@898
|
884 *.css) class="css" ;;
|
al@898
|
885 *.htm|*.html) class="html" ;;
|
al@898
|
886 *.js) class="js" ;;
|
al@898
|
887 *.txt) class="asciidoc" ;;
|
al@898
|
888 *)
|
al@898
|
889 case $(head -n1 $wok/$file) in
|
al@898
|
890 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
|
al@898
|
891 esac
|
al@898
|
892 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
|
al@898
|
893 class="bash"
|
al@898
|
894 fi
|
al@898
|
895 if [ -z "$class" ]; then
|
al@898
|
896 # Follow Busybox restrictions. Search for non-printable chars
|
al@898
|
897 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
|
al@898
|
898 raw="true"
|
al@898
|
899 fi
|
al@898
|
900 fi
|
al@898
|
901 ;;
|
al@898
|
902 esac
|
al@898
|
903
|
al@898
|
904 # Display image
|
al@898
|
905 case $file in
|
al@898
|
906 *.png|*.svg|*.jpg|*.jpeg|*.ico)
|
al@898
|
907 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
|
al@898
|
908 ;;
|
al@898
|
909 esac
|
al@898
|
910
|
al@898
|
911 # Display colored listing for all text-based documents (also for *.svg)
|
al@898
|
912 case $file in
|
al@898
|
913 *.png|*.jpg|*.jpeg|*.ico) ;;
|
al@898
|
914 *)
|
al@898
|
915 if [ -z "$raw" ]; then
|
al@898
|
916 cat $wok/$file | show_code $class
|
al@898
|
917 fi
|
al@898
|
918 ;;
|
al@898
|
919 esac
|
al@898
|
920
|
al@898
|
921 # Display hex dump for binary files
|
al@898
|
922 if [ -n "$raw" ]; then
|
al@898
|
923 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
|
al@898
|
924 fi
|
al@898
|
925 else
|
al@898
|
926 show_note e "File “$file” absent!"
|
al@898
|
927 fi
|
al@898
|
928 ;;
|
al@898
|
929
|
al@898
|
930 files)
|
al@898
|
931 page_header
|
al@898
|
932 pkg_info
|
al@898
|
933
|
al@898
|
934 packaged=$(mktemp)
|
al@898
|
935
|
al@898
|
936 # find main package
|
al@898
|
937 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
|
al@898
|
938 main=${wanted:-$pkg}
|
al@898
|
939 # identify splitted packages
|
al@898
|
940 split="$main $(. $wok/$main/receipt; echo $SPLIT)"
|
al@898
|
941 [ -d "$wok/$main-dev" ] && split="$split $main-dev"
|
al@898
|
942 split="$(echo $split | tr ' ' '\n' | sort -u)"
|
al@898
|
943 # finally we need the version
|
al@898
|
944 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
|
al@898
|
945
|
al@898
|
946 for p in $split; do
|
al@898
|
947 namever="$p-$ver"
|
al@898
|
948 if [ -d "$wok/$p/taz/$p-$ver" ]; then
|
al@898
|
949 indir=$p
|
al@898
|
950 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
|
al@898
|
951 indir=$main
|
al@898
|
952 fi
|
al@898
|
953 dir="$wok/$indir/taz/$p-$ver/fs"
|
al@898
|
954
|
al@898
|
955 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
|
al@898
|
956
|
al@898
|
957 echo "<section><h3>Files of package “$namever” ($size):</h3>"
|
al@898
|
958 echo -en '<pre class="files">\n<span class="underline">permissions·lnk·user ·'
|
al@898
|
959 echo -en 'group · size·date & time ·file name\n</span>'
|
al@898
|
960 find $dir -not -type d -print0 | sort -z | xargs -0 ls -ld --color=always | \
|
al@898
|
961 syntax_highlighter files | \
|
al@898
|
962 sed "s|\([^>]*\)>/.*/fs\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|" | \
|
al@898
|
963 awk 'BEGIN { FS="\""; }
|
al@898
|
964 { gsub("+", "%2B", $2); print; }'
|
al@898
|
965 echo '</pre></section>'
|
al@898
|
966 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
|
al@898
|
967 done
|
al@898
|
968
|
al@898
|
969 # find repeatedly packaged files
|
al@898
|
970 repeats="$(sort $packaged | uniq -d)"
|
al@898
|
971 if [ -n "$repeats" ]; then
|
al@898
|
972 echo -n '<section><h3>Repeatedly packaged files:</h3><pre class="files">'
|
al@898
|
973 echo "$repeats" | sed 's|^|<span class="c11">!!!</span> |'
|
al@898
|
974 echo "</pre></section>"
|
al@898
|
975 fi
|
al@898
|
976
|
al@898
|
977 # find unpackaged files
|
al@898
|
978 all_files=$(mktemp)
|
al@898
|
979 cd $wok/$main/install; find ! -type d | sed 's|\.||' > $all_files
|
al@898
|
980 orphans="$(sort $all_files $packaged | uniq -u)"
|
al@898
|
981 if [ -n "$orphans" ]; then
|
al@898
|
982 echo -n '<section><h3>Unpackaged files:</h3><pre class="files">'
|
al@898
|
983 echo "$orphans" | awk '
|
al@898
|
984 function tag(text, color) { printf("<span class=\"c%s1\">%s</span> %s\n", color, text, $0); }
|
al@898
|
985 /\/perllocal.pod$/ || /\/\.packlist$/ || /\/share\/bash-completion\// { tag("---", 0); next }
|
al@898
|
986 /\.pod$/ { tag("pod", 5); next }
|
al@898
|
987 /\/share\/man\// { tag("man", 5); next }
|
al@898
|
988 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// || /\/share\/devhelp\// { tag("doc", 5); next }
|
al@898
|
989 /\/share\/icons\// { tag("ico", 2); next }
|
al@898
|
990 /\/share\/locale\// { tag("loc", 4); next }
|
al@898
|
991 /\.h$/ || /\.a$/ || /\.la$/ || /\.pc$/ || /\/bin\/.*-config$/ { tag("dev", 3); next }
|
al@898
|
992 { tag("???", 1) }
|
al@898
|
993 '
|
al@898
|
994 echo '</pre></section>'
|
al@898
|
995 fi
|
al@898
|
996 ;;
|
al@898
|
997
|
al@898
|
998 description)
|
al@898
|
999 page_header
|
al@898
|
1000 pkg_info
|
al@898
|
1001 desc="$WOK$REQUEST_URI.txt"
|
al@898
|
1002 if [ -s "$desc" ]; then
|
al@898
|
1003 echo '<div id="content2">'
|
al@898
|
1004 if [ -n "$md2html" ]; then
|
al@898
|
1005 $md2html $desc
|
al@898
|
1006 else
|
al@898
|
1007 show_code markdown < $desc
|
al@898
|
1008 fi
|
al@898
|
1009 echo '</div>'
|
al@898
|
1010 else
|
al@898
|
1011 show_note w "No description of $pkg"
|
al@898
|
1012 fi
|
al@898
|
1013 ;;
|
al@898
|
1014
|
al@898
|
1015 log)
|
al@898
|
1016 page_header
|
al@898
|
1017 pkg_info
|
al@898
|
1018 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
|
al@898
|
1019
|
al@898
|
1020 echo '<div class="btnList">'
|
al@898
|
1021 acc='l'
|
al@898
|
1022 while read log; do
|
al@898
|
1023 timestamp=$(stat -c %Y $log)
|
al@898
|
1024 class=''
|
al@898
|
1025 if [ "$arg" == "$timestamp" ]; then
|
al@898
|
1026 class=' log'
|
al@898
|
1027 logfile="$log"
|
al@898
|
1028 fi
|
al@898
|
1029 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
|
al@898
|
1030 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
|
al@898
|
1031 case $acc in
|
al@898
|
1032 l) acc=0;;
|
al@898
|
1033 *) acc=$((acc+1));;
|
al@898
|
1034 esac
|
al@898
|
1035 done <<EOT
|
al@898
|
1036 $(find $LOGS -name "$pkg.log*" | sort)
|
al@898
|
1037 EOT
|
al@898
|
1038 echo '</div>'
|
al@898
|
1039
|
al@898
|
1040 if [ -z "$logfile" ]; then
|
al@898
|
1041 show_note e "Requested log is absent"
|
al@898
|
1042 page_footer
|
al@898
|
1043 exit 0
|
al@898
|
1044 fi
|
al@898
|
1045
|
al@898
|
1046 # Define cook variables for syntax highlighter
|
al@898
|
1047 if [ -s "$WOK/$pkg/receipt" ]; then
|
al@898
|
1048 . "$WOK/$pkg/receipt"
|
al@898
|
1049 _wok='/home/slitaz/wok'
|
al@898
|
1050 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
|
al@898
|
1051 _install="$_wok/$pkg/install"
|
al@898
|
1052 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
|
al@898
|
1053 _stuff="$_wok/$pkg/stuff"
|
al@898
|
1054 fi
|
al@898
|
1055
|
al@898
|
1056 # if [ ! -f "gzlog/$pkg.$arg" ]; then
|
al@898
|
1057 # {
|
al@898
|
1058 # summary "$logfile" links
|
al@898
|
1059 #
|
al@898
|
1060 # syntax_highlighter log < $logfile | awk '
|
al@898
|
1061 # BEGIN { print "<pre class=\"log\">"; }
|
al@898
|
1062 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
|
al@898
|
1063 # END { print "</pre>"; }
|
al@898
|
1064 # '
|
al@898
|
1065 #
|
al@898
|
1066 # page_footer
|
al@898
|
1067 # } | gzip > gzlog/$pkg.$arg
|
al@898
|
1068 # fi
|
al@898
|
1069
|
al@898
|
1070 blog=$(basename $logfile)
|
al@898
|
1071 summary "$logfile" links
|
al@898
|
1072
|
al@898
|
1073 # disable next `sed` for the 'like2016' theme
|
al@898
|
1074 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
|
al@898
|
1075 cat $logfile | syntax_highlighter log | \
|
al@898
|
1076 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
|
al@898
|
1077 awk '
|
al@898
|
1078 BEGIN { print "<pre class=\"log\">"; }
|
al@898
|
1079 { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
|
al@898
|
1080 END { print "</pre>"; }
|
al@898
|
1081 '
|
al@898
|
1082 ;;
|
al@898
|
1083
|
al@898
|
1084
|
al@898
|
1085 man|doc|info)
|
al@898
|
1086 page_header
|
al@898
|
1087 pkg_info
|
al@898
|
1088 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
|
al@898
|
1089
|
al@898
|
1090 dir="wok/$pkg/install/usr/share/$cmd"
|
al@898
|
1091 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
|
al@898
|
1092 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
|
al@898
|
1093 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
|
al@898
|
1094 [ -n "$try" ] && arg="$try"
|
al@898
|
1095 fi
|
al@898
|
1096 while read i; do
|
al@898
|
1097 [ -s "$i" ] || continue
|
al@898
|
1098 case "$i" in
|
al@898
|
1099 *.jp*g|*.png|*.gif|*.svg|*.css) continue
|
al@898
|
1100 esac
|
al@898
|
1101 i=${i#$dir/}
|
al@898
|
1102 [ -n "$arg" ] || arg="$i"
|
al@898
|
1103 class=''; [ "$arg" == "$i" ] && class=" doc"
|
al@898
|
1104 case "$cmd" in
|
al@898
|
1105 man)
|
al@898
|
1106 case $i in
|
al@898
|
1107 man*) lang='';;
|
al@898
|
1108 *) lang="${i%%/*}: ";;
|
al@898
|
1109 esac
|
al@898
|
1110 man=$(basename $i .gz)
|
al@898
|
1111 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
|
al@898
|
1112 ;;
|
al@898
|
1113 doc)
|
al@898
|
1114 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
|
al@898
|
1115 ;;
|
al@898
|
1116 info)
|
al@898
|
1117 info=$(basename $i)
|
al@898
|
1118 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
|
al@898
|
1119 ;;
|
al@898
|
1120 esac
|
al@898
|
1121 done <<EOT
|
al@898
|
1122 $(for i in $dir; do find $i -type f; done | sort)
|
al@898
|
1123 EOT
|
al@898
|
1124 echo '</div>'
|
al@898
|
1125
|
al@898
|
1126 [ -f "$arg" ] || arg="$dir/$arg"
|
al@898
|
1127 if [ -f "$arg" ]; then
|
al@898
|
1128 tmp="$(mktemp)"
|
al@898
|
1129 docat "$arg" > $tmp
|
al@898
|
1130 [ -s "$tmp" ] &&
|
al@898
|
1131 case "$cmd" in
|
al@898
|
1132 info)
|
al@898
|
1133 echo '<div id="content2" class="texinfo"><pre class="first">'
|
al@898
|
1134 info2html < "$tmp"
|
al@898
|
1135 echo '</pre></div>'
|
al@898
|
1136 ;;
|
al@898
|
1137 doc)
|
al@898
|
1138 case "$arg" in
|
al@898
|
1139 *.sgml|*.devhelp2) class='xml';;
|
al@898
|
1140 *.py) class='python';; # pycurl package
|
al@898
|
1141 *.css) class='css';;
|
al@898
|
1142 *) class='asciidoc';;
|
al@898
|
1143 esac
|
al@898
|
1144 case "$arg" in
|
al@898
|
1145 *.htm*)
|
al@898
|
1146 case $arg in
|
al@898
|
1147 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
|
al@898
|
1148 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
|
al@898
|
1149 esac
|
al@898
|
1150 # make the iframe height so long to contain it's content without scrollbar
|
al@898
|
1151 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
|
al@898
|
1152 ;;
|
al@898
|
1153 *.pdf)
|
al@898
|
1154 case $arg in
|
al@898
|
1155 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
|
al@898
|
1156 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
|
al@898
|
1157 esac
|
al@898
|
1158 cat <<EOT
|
al@898
|
1159 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
|
al@898
|
1160 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
|
al@898
|
1161 </object>
|
al@898
|
1162 EOT
|
al@898
|
1163 ;;
|
al@898
|
1164 *)
|
al@898
|
1165 show_code $class < "$tmp"
|
al@898
|
1166 ;;
|
al@898
|
1167 esac
|
al@898
|
1168 ;;
|
al@898
|
1169 man)
|
al@898
|
1170 #export TEXTDOMAIN='man2html'
|
al@898
|
1171 echo "<div id='content2'>"
|
al@898
|
1172
|
al@898
|
1173 html=$(./man2html "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
|
al@898
|
1174 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
|
al@898
|
1175 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
|
al@898
|
1176
|
al@898
|
1177 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
|
al@898
|
1178 # Process the pre-formatted man-cat page
|
al@898
|
1179 echo '<pre>'
|
al@898
|
1180 sed '
|
al@898
|
1181 s|M-bM-^@M-^S|—|g;
|
al@898
|
1182 s|M-bM-^@M-^\\|<b>|g;
|
al@898
|
1183 s|M-bM-^@M-^]|</b>|g
|
al@898
|
1184 s|M-bM-^@M-^X|<u>|g;
|
al@898
|
1185 s|M-bM-^@M-^Y|</u>|g;
|
al@898
|
1186 s|M-BM-||g;
|
al@898
|
1187 ' "$tmp"
|
al@898
|
1188 echo '</pre>'
|
al@898
|
1189 else
|
al@898
|
1190 echo "$html"
|
al@898
|
1191 fi
|
al@898
|
1192 echo "</div>"
|
al@898
|
1193 ;;
|
al@898
|
1194 esac
|
al@898
|
1195 rm -f $tmp
|
al@898
|
1196 else
|
al@898
|
1197 show_note e "File “$arg” not exists!"
|
al@898
|
1198 fi
|
al@898
|
1199 ;;
|
al@898
|
1200
|
al@898
|
1201 esac
|
al@898
|
1202
|
al@898
|
1203
|
al@898
|
1204 page_footer
|
al@898
|
1205 exit 0
|