tazpanel view pkgs.cgi @ rev 87

pkgs.cgi: Reverse change to fix packages installation (please test before commit...)
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 14 03:50:59 2011 +0200 (2011-04-14)
parents 7c67737d8dfd
children 3e9b8a48e16e
line source
1 #!/bin/sh
2 #
3 # TazPKG CGI interface - Manage packages via a browser
4 #
5 # This CGI interface intensively uses tazpkg to manage packages and have
6 # its own code for some tasks. Please KISS, it is important and keep speed
7 # in mind. Thanks, Pankso.
8 #
9 # (C) 2011 SliTaz GNU/Linux - GNU gpl v3
10 #
12 . lib/libtazpanel
13 get_config
14 header
16 # Include gettext helper script.
17 . /usr/bin/gettext.sh
19 # Export package name for gettext.
20 TEXTDOMAIN='tazpanel'
21 export TEXTDOMAIN
23 # xHTML 5 header with special side bar fo categories.
24 TITLE="- Packages"
25 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
28 # We need packages information for list and search
29 parse_packages_desc() {
30 IFS="|"
31 cut -f 1,2,3,5 -d "|" | while read PACKAGE VERSION SHORT_DESC WEB_SITE
32 do
33 echo '<tr>'
34 if [ -d $INSTALLED/${PACKAGE% } ]; then
35 echo -e "<td><input type='checkbox' name='pkg' value='$PACKAGE'>\n
36 <a href='$SCRIPT_NAME?info=$PACKAGE'>
37 <img src='$IMAGES/tazpkg-installed.png'/>$PACKAGE</a></td>"
38 else
39 echo -e "<td><input type='checkbox' name='pkg' value='$PACKAGE'>\n
40 <a href='$SCRIPT_NAME?info=$PACKAGE'>
41 <img src='$IMAGES/tazpkg.png'/>$PACKAGE</a></td>"
42 fi
43 echo "<td>$VERSION</td>"
44 echo "<td class='desc'>$SHORT_DESC</td>"
45 echo "<td><a href='$WEB_SITE'>web</a></td>"
46 echo '</tr>'
47 done
48 unset IFS
49 }
51 # Remove status and ESC char from tazpkg commands output
52 filter_tazpkg_msgs() {
53 grep ^[a-zA-Z0-9] | sed s'/\.*\]//'
54 }
56 # Display a full summary of packages stats
57 packages_summary() {
58 gettext "Last recharge : "
59 stat=`stat -c %y $LOCALSTATE/packages.list | \
60 sed 's/\(:..\):.*/\1/' | awk '{print $1}'`
61 mtime=`find /var/lib/tazpkg/packages.list -mtime +10`
62 echo -n "$stat "
63 if [ "$mtime" ]; then
64 echo "(Older than 10 days)"
65 else
66 echo "(Not older than 10 days)"
67 fi
68 gettext "Installed packages : "
69 ls $INSTALLED | wc -l
70 gettext "Mirrored packages : "
71 cat $LOCALSTATE/packages.list | wc -l
72 gettext "Upgradeable packages : "
73 cat $LOCALSTATE/packages.up | wc -l
74 #gettext "Installed files : "
75 #cat $INSTALLED/*/files.list | wc -l
76 gettext "Blocked packages : "
77 cat $LOCALSTATE/blocked-packages.list | wc -l
78 }
80 # Parse mirrors list to be able to have an icon an remove link
81 list_mirrors() {
82 cat $LOCALSTATE/mirrors | while read line
83 do
84 cat << EOT
85 <li><a href="$SCRIPT_NAME?config=rm-mirror=$line"><img
86 src="$IMAGES/clear.png" /></a><a href="$line">$line</a></li>
87 EOT
88 done
89 }
91 #
92 # xHTML functions
93 #
95 # ENTER will search but user may search for a button, so put one.
96 search_form() {
97 cat << EOT
98 <div class="search">
99 <form method="get" action="$SCRIPT_NAME">
100 <p>
101 <input type="text" name="search" size="20">
102 <input type="submit" value="`gettext "Search"`">
103 <input class="radius" type="submit" name="files"
104 value="`gettext "files"`">
105 </p>
106 </form>
107 </div>
108 EOT
109 }
111 table_head() {
112 cat << EOT
113 <tr id="thead">
114 <td>`gettext "Name"`</td>
115 <td>`gettext "Version"`</td>
116 <td>`gettext "Description"`</td>
117 <td>`gettext "Web"`</td>
118 </tr>
119 EOT
120 }
122 sidebar() {
123 cat << EOT
124 <div id="sidebar">
125 <h4>Categories</h4>
126 <a class="active_base-system" href="$SCRIPT_NAME?cat=base-system">Base-system</a>
127 <a class="active_x-window" href="$SCRIPT_NAME?cat=x-window">X window</a>
128 <a class="active_utilities" href="$SCRIPT_NAME?cat=utilities">Utilities</a>
129 <a class="active_network" href="$SCRIPT_NAME?cat=network">Network</a>
130 <a class="active_games" href="$SCRIPT_NAME?cat=games">Games</a>
131 <a class="active_graphics" href="$SCRIPT_NAME?cat=graphics">Graphics</a>
132 <a class="active_office" href="$SCRIPT_NAME?cat=office">Office</a>
133 <a class="active_multimedia" href="$SCRIPT_NAME?cat=multimedia">Multimedia</a>
134 <a class="active_developement" href="$SCRIPT_NAME?cat=development">Development</a>
135 <a class="active_system-tools" href="$SCRIPT_NAME?cat=system-tools">System tools</a>
136 <a class="active_security" href="$SCRIPT_NAME?cat=security">Security</a>
137 <a class="active_misc" href="$SCRIPT_NAME?cat=misc">Misc</a>
138 <a class="active_meta" href="$SCRIPT_NAME?cat=meta">Meta</a>
139 <a class="active_non-free" href="$SCRIPT_NAME?cat=non-free">Non free</a>
140 </div>
141 EOT
142 }
144 #
145 # Commands
146 #
148 case " $(GET) " in
149 *\ list\ *)
150 #
151 # List installed packages. This is the default because parsing
152 # the full packages.desc can be long and take some resources
153 #
154 cd $INSTALLED
155 search_form
156 sidebar
157 LOADING_MSG="Listing packages..."
158 loading_msg
159 cat << EOT
160 <h2>`gettext "My packages"`</h2>
161 <form method='get' action='$SCRIPT_NAME'>
162 <div id="actions">
163 <div class="float-left">
164 `gettext "Selection:"`
165 <input type="submit" name="do" value="Remove" />
166 </div>
167 <div class="float-right">
168 `gettext "List:"`
169 <input type="submit" name="recharge" value="Recharge" />
170 <input type="submit" name="up" value="Upgrade" />
171 </div>
172 </div>
173 EOT
174 table_start
175 table_head
176 for pkg in *
177 do
178 . $pkg/receipt
179 echo '<tr>'
180 # Use default tazpkg icon since all packages displayed are
181 # installed
182 echo "<td class='pkg'>
183 <input type='checkbox' name='pkg' value=\"$pkg\" />
184 <a href='$SCRIPT_NAME?info=$pkg'><img
185 src='$IMAGES/tazpkg-installed.png'/>$pkg</a></td>"
186 echo "<td>$VERSION</td>"
187 echo "<td class='desc'>$SHORT_DESC</td>"
188 echo "<td><a href='$WEB_SITE'>web</a></td>"
189 echo '</tr>'
190 done
191 table_end
192 echo '</form>' ;;
193 *\ cat\ *)
194 #
195 # List all available packages by category on mirror. Listing all
196 # packages is too resource intensive and not useful.
197 #
198 cd $LOCALSTATE
199 category=$(GET cat)
200 [ "$category" == "cat" ] && category="base-system"
201 search_form
202 sidebar | sed s/"active_${category}"/"active"/
203 LOADING_MSG="Listing packages..."
204 loading_msg
205 cat << EOT
206 <h2>`gettext "Category:"` $category</h2>
207 <form method='get' action='$SCRIPT_NAME'>
208 <div id="actions">
209 <div class="float-left">
210 `gettext "Selection:"`
211 <input type="submit" name="do" value="Install" />
212 <input type="submit" name="do" value="Remove" />
213 </div>
214 <div class="float-right">
215 `gettext "List:"`
216 <input type="submit" name="recharge" value="Recharge" />
217 <input type="submit" name="up" value="Upgrade" />
218 <a class="button" href='$SCRIPT_NAME?list'>
219 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
220 </div>
221 EOT
222 echo '</div>'
223 table_start
224 table_head
225 grep "| $category |" packages.desc | parse_packages_desc
226 table_end
227 echo '</form>' ;;
228 *\ search\ *)
229 #
230 # Search for packages. Here default is to search in packages.desc
231 # and so get result including packages names and descriptions
232 #
233 pkg=$(GET search)
234 cd $LOCALSTATE
235 search_form
236 sidebar
237 LOADING_MSG="Searching packages..."
238 loading_msg
239 cat << EOT
240 <h2>`gettext "Search packages"`</h2>
241 <form method="get" action="$SCRIPT_NAME">
242 <div id="actions">
243 <div class="float-left">
244 `gettext "Selection:"`
245 <input type="submit" name="do" value="Install" />
246 <input type="submit" name="do" value="Remove" />
247 <a href="`cat $PANEL/lib/checkbox.js`">`gettext "Toogle all"`</a>
248 </div>
249 <div class="float-right">
250 `gettext "List:"`
251 <input type="submit" name="recharge" value="Recharge" />
252 <input type="submit" name="up" value="Upgrade" />
253 <a class="button" href='$SCRIPT_NAME?list'>
254 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
255 </div>
256 EOT
257 echo '</div>'
258 table_start
259 if [ "$(GET files)" ]; then
260 cat <<EOT
261 <tr id="thead">
262 <td>`gettext "Package"`</td>
263 <td>`gettext "File"`</td>
264 </tr>
265 $(unlzma -c files.list.lzma | grep -Ei ": .*$(GET search)" | \
266 while read PACKAGE FILE; do
267 PACKAGE=${PACKAGE%:}
268 image=tazpkg-installed.png
269 [ -d $INSTALLED/$PACKAGE ] || image=tazpkg.png
270 echo "<tr>
271 <td><input type='checkbox' name='pkg' value='$PACKAGE'>
272 <a href='$SCRIPT_NAME?info=$PACKAGE'><img src='$IMAGES/$image' />$PACKAGE</a></td>
273 <td>$FILE</td>
274 </tr>"
275 done)
276 EOT
277 else
278 table_head
279 grep -i $pkg packages.desc | parse_packages_desc
280 fi
281 table_end
282 echo '</form>' ;;
283 *\ recharge\ *)
284 #
285 # Let recharge the packages list
286 #
287 search_form
288 sidebar
289 LOADING_MSG="Recharging lists..."
290 loading_msg
291 cat << EOT
292 <h2>`gettext "Recharge"`</h2>
293 <form method='get' action='$SCRIPT_NAME'>
294 <div id="actions">
295 <div class="float-left">
296 <p>
297 `gettext "Recharge checks for new or updated packages"`
298 </p>
299 </div>
300 <div class="float-right">
301 <p>
302 <a class="button" href='$SCRIPT_NAME?up'>
303 `gettext "Check upgrade"`</a>
304 <a class="button" href='$SCRIPT_NAME?list'>
305 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
306 </p>
307 </div>
308 </div>
309 <pre>
310 EOT
311 echo "$(date +%Y%M%d-%H:%M) Recharging packages list" | log
312 tazpkg recharge | filter_tazpkg_msgs
313 cat << EOT
314 </pre>
315 <p>
316 `gettext "Packages lists are up-to-date. You should check for upgrades now."`
317 </p>
318 EOT
319 ;;
320 *\ up\ *)
321 #
322 # Ugrade packages
323 #
324 cd $LOCALSTATE
325 search_form
326 sidebar
327 LOADING_MSG="Checking for upgrades..."
328 loading_msg
329 cat << EOT
330 <h2>`gettext "Up packages"`</h2>
331 <form method="get" action="$SCRIPT_NAME">
332 <div id="actions">
333 <div class="float-left">
334 `gettext "Selection:"`
335 <input type="submit" name="do" value="Install" />
336 <input type="submit" name="do" value="Remove" />
337 <a href="`cat $PANEL/lib/checkbox.js`">`gettext "Toogle all"`</a>
338 </div>
339 <div class="float-right">
340 `gettext "List:"`
341 <input type="submit" name="recharge" value="Recharge" />
342 <a class="button" href='$SCRIPT_NAME?list'>
343 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
344 </div>
345 </div>
346 EOT
347 tazpkg up --check >/dev/null
348 table_start
349 table_head
350 for pkg in `cat packages.up`
351 do
352 grep "^$pkg |" $LOCALSTATE/packages.desc | parse_packages_desc
353 done
354 table_end
355 echo '</form>' ;;
356 *\ do\ *)
357 #
358 # Do an action on one or some packages
359 #
360 pkgs=""
361 cmdline=`echo ${QUERY_STRING#do=} | sed s'/&/ /g'`
362 cmd=`echo ${cmdline} | awk '{print $1}'`
363 pkgs=`echo $cmdline | sed -e s'/+/ /g' -e s'/pkg=//g' -e s/$cmd//`
364 case $cmd in
365 install|Install)
366 cmd=get-install opt=--forced ;;
367 remove|Remove)
368 cmd=remove ;;
369 esac
370 search_form
371 sidebar
372 LOADING_MSG="${cmd}ing packages..."
373 loading_msg
374 cat << EOT
375 <h2>Tazpkg: $cmd</h2>
376 <form method="get" action="$SCRIPT_NAME">
377 <div id="actions">
378 <div class="float-left">
379 <p>
380 `gettext "Performing tasks on packages"`
381 </p>
382 </div>
383 <div class="float-right">
384 <p>
385 <a class="button" href='$SCRIPT_NAME?list'>
386 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
387 </p>
388 </div>
389 </div>
390 EOT
391 echo '<div class="box">'
392 gettext "Executing $cmd for:$pkgs"
393 echo '</div>'
394 for pkg in $pkgs
395 do
396 echo '<pre>'
397 echo 'o' | tazpkg $cmd $pkg $opt 2>/dev/null | filter_tazpkg_msgs
398 echo '</pre>'
399 done ;;
400 *\ info\ *)
401 #
402 # Packages info
403 #
404 pkg=$(GET info)
405 search_form
406 sidebar
407 if [ -d $INSTALLED/$pkg ]; then
408 . $INSTALLED/$pkg/receipt
409 files=`cat $INSTALLED/$pkg/files.list | wc -l`
410 action=$(gettext "Remove")
411 else
412 cd $LOCALSTATE
413 LOADING_MSG=$(gettext "Getting package info...")
414 loading_msg
415 IFS='|'
416 set -- $(grep "^$pkg |" packages.desc)
417 unset IFS
418 PACKAGE=$1
419 VERSION="$(echo $2)"
420 SHORT_DESC="$(echo $3)"
421 CATEGORY="$(echo $4)"
422 WEB_SITE="$(echo $5)"
423 action=$(gettext "Install")
424 fi
425 cat << EOT
426 <h2>`gettext "Package"` $PACKAGE</h2>
427 <div id="actions">
428 <div class="float-left">
429 <p>
430 <a class="button" href='$SCRIPT_NAME?do=$action&$pkg'>$action</a>
431 </p>
432 </div>
433 <div class="float-right">
434 <p>
435 <a class="button" href='$SCRIPT_NAME?list'>
436 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
437 </p>
438 </div>
439 </div>
440 <pre>
441 Name : $PACKAGE
442 Version : $VERSION
443 Description : $SHORT_DESC
444 Category : $CATEGORY
445 EOT
446 if [ -d $INSTALLED/$pkg ]; then
447 cat << EOT
448 Maintainer : $MAINTAINER
449 Depends : `for i in $DEPENDS; do echo -n \
450 "<a href="$SCRIPT_NAME?info=$i">$i</a> "; done`
451 Website : <a href="$WEB_SITE">$WEB_SITE</a>
452 Sizes : $PACKED_SIZE/$UNPACKED_SIZE
453 </pre>
455 <p>`gettext "Installed files:"` `cat $INSTALLED/$pkg/files.list | wc -l`</p>
456 <pre>
457 `cat $INSTALLED/$pkg/files.list`
458 </pre>
459 EOT
460 else
461 cat << EOT
462 Website : <a href="$WEB_SITE">$WEB_SITE</a>
463 Sizes : `grep -A 3 ^$pkg$ packages.txt | tail -n 1 | sed 's/ *//'`
464 </pre>
466 <p>`gettext "Installed files:"`</p>
467 <pre>
468 `unlzma -c files.list.lzma | sed "/^$pkg: /!d;s/^$pkg: //"`
469 </pre>
470 EOT
471 fi
472 ;;
473 *\ config\ *)
474 #
475 # Tazpkg configuration page
476 #
477 cmd=$(GET config)
478 case "$cmd" in
479 clean)
480 rm -rf /var/cache/tazpkg/* ;;
481 add-mirror)
482 # Decode url
483 mirror=$(GET mirror)
484 case "$mirror" in
485 http://*|ftp://*)
486 echo "$mirror" >> $LOCALSTATE/mirrors ;;
487 esac ;;
488 rm-mirror=http://*|rm-mirror=ftp://*)
489 mirror=${cmd#rm-mirror=}
490 sed -i -e "s@$mirror@@" -e '/^$/d' $LOCALSTATE/mirrors ;;
491 esac
492 cache_files=`find /var/cache/tazpkg -name *.tazpkg | wc -l`
493 cache_size=`du -sh /var/cache/tazpkg`
494 sidebar
495 cat << EOT
496 <h2>`gettext "Configuration"`</h2>
497 <div>
498 <p>`gettext "Tazpkg configuration and settings"`</p>
499 </div>
500 <div>
501 <form method="get" action="$SCRIPT_NAME">
502 <p>
503 `gettext "Packages in the cache:"` $cache_files ($cache_size)
504 <input type="hidden" name="config" value="clean" />
505 <input type="submit" value="Clean" />
506 </p>
507 </form>
508 </div>
510 <h3>`gettext "Current mirror list"`</h3>
511 <div class="box">
512 <ul>
513 `list_mirrors`
514 </ul>
515 </div>
516 <form method="get" action="$SCRIPT_NAME">
517 <p>
518 <input type="hidden" name="config" value="add-mirror" />
519 <input type="text" name="mirror" size="60">
520 <input type="submit" value="Add mirror" />
521 </p>
522 </form>
523 EOT
524 ;;
525 *)
526 #
527 # Default to summary
528 #
529 search_form
530 sidebar
531 cat << EOT
532 <h2>`gettext "Summary"`</h2>
533 <div id="actions">
534 <a class="button" href='$SCRIPT_NAME?list'>
535 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
536 <a class="button" href='$SCRIPT_NAME?recharge'>
537 <img src="$IMAGES/recharge.png" />`gettext "Recharge list"`</a>
538 <a class="button" href='$SCRIPT_NAME?up'>
539 <img src="$IMAGES/update.png" />`gettext "Check upgrade"`</a>
540 <a class="button" href='$SCRIPT_NAME?config'>
541 <img src="$IMAGES/edit.png" />`gettext "Configuration"`</a>
542 </div>
543 <pre class="pre-main">
544 `packages_summary`
545 </pre>
547 <h3>`gettext "Latest log entries"`</h3>
548 <pre>
549 `tail -n 5 /var/log/tazpkg.log | fgrep "-" | \
550 awk '{print $1, $2, $3, $4, $5, $6, $7}'`
551 </pre>
553 <a name="administration"></a>
554 <h3>`gettext "Administration"`</h3>
555 <div id="actions">
556 <a class="button" href='$SCRIPT_NAME?action=saveconf#administration'>
557 <img src="$IMAGES/tazpkg.png" />`gettext "Save configuration files"`</a>
558 <a class="button" href='$SCRIPT_NAME?action=listconf#administration'>
559 <img src="$IMAGES/edit.png" />`gettext "List configuration files"`</a>
560 <a class="button" href='$SCRIPT_NAME?action=quickcheck#administration'>
561 <img src="$IMAGES/recharge.png" />`gettext "Quick check"`</a>
562 <a class="button" href='$SCRIPT_NAME?action=fullcheck#administration'>
563 <img src="$IMAGES/recharge.png" />`gettext "Full check"`</a>
564 </div>
566 EOT
567 case "$(GET action)" in
568 saveconf)
569 echo "<pre>"
570 cd $HOME
571 tazpkg repack-config | sed 's/.\[[^mG]*.//g'
572 ls -l $HOME/config-*.tazpkg
573 echo "</pre>" ;;
574 listconf)
575 echo "<h4>`gettext "Configuration files"`</h4>"
576 echo "<ul>"
577 tazpkg list-config | sed \
578 '/^\//!d;s/.*/<li><a href="index.cgi?file=&">&<\/a><\/li>/'
579 echo "</ul>"
580 echo "</pre>" ;;
581 quickcheck)
582 echo "<pre>"
583 tazpkg check
584 echo "</pre>" ;;
585 fullcheck)
586 echo "<pre>"
587 tazpkg check --full
588 echo "</pre>" ;;
589 esac
590 ;;
591 esac
593 # xHTML 5 footer
594 xhtml_footer
595 exit 0