tazpanel view pkgs.cgi @ rev 280

Added support for get-* packages
author Christian Mesh meshca@clarkson.edu
date Mon Mar 19 15:24:19 2012 +0000 (2012-03-19)
parents ba47fb2fc52a
children c6f67539bf90
line source
1 #!/bin/sh
2 #
3 # TazPKG CGI interface - Manage packages via a browser
4 #
5 # This CGI interface extensively 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 - BSD License
10 #
12 . lib/libtazpanel
13 get_config
14 header
16 # xHTML 5 header with special side bar for categories.
17 TITLE="- Packages"
18 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
21 # We need packages information for list and search
22 parse_packages_desc() {
23 IFS="|"
24 cut -f 1,2,3,5 -d "|" | while read PACKAGE VERSION SHORT_DESC WEB_SITE
25 do
26 echo '<tr>'
27 if [ -d $INSTALLED/${PACKAGE% } ]; then
28 echo -e "<td><input type='checkbox' name='pkg' value='$PACKAGE'>\n
29 <a href='$SCRIPT_NAME?info=$PACKAGE'>
30 <img src='$IMAGES/tazpkg-installed.png'/>$PACKAGE</a></td>"
31 else
32 echo -e "<td><input type='checkbox' name='pkg' value='$PACKAGE'>\n
33 <a href='$SCRIPT_NAME?info=$PACKAGE'>
34 <img src='$IMAGES/tazpkg.png'/>$PACKAGE</a></td>"
35 fi
36 echo "<td>$VERSION</td>"
37 echo "<td class='desc'>$SHORT_DESC</td>"
38 echo "<td><a href='$WEB_SITE'><img src='$IMAGES/browser.png'/></a></td>"
39 echo '</tr>'
40 done
41 unset IFS
42 }
44 # Display a full summary of packages stats
45 packages_summary() {
46 gettext "Last recharge : "
47 stat=`stat -c %y $LOCALSTATE/packages.list | \
48 sed 's/\(:..\):.*/\1/' | awk '{print $1}'`
49 mtime=`find $LOCALSTATE/packages.list -mtime +10`
50 echo -n "$stat "
51 if [ "$mtime" ]; then
52 echo "(Older than 10 days)"
53 else
54 echo "(Not older than 10 days)"
55 fi
56 gettext "Installed packages : "
57 ls $INSTALLED | wc -l
58 gettext "Mirrored packages : "
59 cat $LOCALSTATE/packages.list | wc -l
60 gettext "Upgradeable packages : "
61 cat $LOCALSTATE/packages.up | wc -l
62 #gettext "Installed files : "
63 #cat $INSTALLED/*/files.list | wc -l
64 gettext "Blocked packages : "
65 cat $LOCALSTATE/blocked-packages.list | wc -l
66 }
68 # Parse mirrors list to be able to have an icon and remove link
69 list_mirrors() {
70 while read line
71 do
72 cat << EOT
73 <li>
74 <a href="$SCRIPT_NAME?admin=rm-mirror=$line&amp;file=$(httpd -e $1)">
75 <img src="$IMAGES/clear.png" />
76 </a>
77 <a href="$SCRIPT_NAME?admin=select-mirror&amp;mirror=$line">
78 <img src="$IMAGES/start.png" />
79 </a>
80 <a href="$line">$line</a>
81 </li>
82 EOT
83 done < $1
84 }
86 # Parse repositories list to be able to have an icon and remove link
87 list_repos() {
88 ls $LOCALSTATE/undigest 2> /dev/null | while read repo ; do
89 cat <<EOT
90 <li><a href="$SCRIPT_NAME?admin=rm-repo=$repo">
91 <img src="$IMAGES/clear.png">$repo</a></li>
92 EOT
93 done
94 }
96 #
97 # xHTML functions
98 #
100 # ENTER will search but user may search for a button, so put one.
101 search_form() {
102 [ -n "$repo" ] || repo="$(GET repo)"
103 [ -n "$repo" ] || repo=Any
104 cat << EOT
105 <div class="search">
106 <form method="get" action="$SCRIPT_NAME">
107 <p>
108 <input type="text" name="search" size="20">
109 <input type="submit" value="`gettext "Search"`">
110 <input class="radius" type="submit" name="files"
111 value="`gettext "Files"`">
112 <input type="hidden" name="repo" value="$repo" />
113 </p>
114 </form>
115 </div>
116 EOT
117 }
119 table_head() {
120 cat << EOT
121 <tr id="thead">
122 <td>`gettext "Name"`</td>
123 <td>`gettext "Version"`</td>
124 <td>`gettext "Description"`</td>
125 <td>`gettext "Web"`</td>
126 </tr>
127 EOT
128 }
130 sidebar() {
131 [ -n "$repo" ] || repo=Public
132 cat << EOT
133 <div id="sidebar">
134 <h4>Categories</h4>
135 <a class="active_base-system" href="$SCRIPT_NAME?cat=base-system&repo=$repo">Base-system</a>
136 <a class="active_x-window" href="$SCRIPT_NAME?cat=x-window&repo=$repo">X window</a>
137 <a class="active_utilities" href="$SCRIPT_NAME?cat=utilities&repo=$repo">Utilities</a>
138 <a class="active_network" href="$SCRIPT_NAME?cat=network&repo=$repo">Network</a>
139 <a class="active_games" href="$SCRIPT_NAME?cat=games&repo=$repo">Games</a>
140 <a class="active_graphics" href="$SCRIPT_NAME?cat=graphics&repo=$repo">Graphics</a>
141 <a class="active_office" href="$SCRIPT_NAME?cat=office&repo=$repo">Office</a>
142 <a class="active_multimedia" href="$SCRIPT_NAME?cat=multimedia&repo=$repo">Multimedia</a>
143 <a class="active_development" href="$SCRIPT_NAME?cat=development&repo=$repo">Development</a>
144 <a class="active_system-tools" href="$SCRIPT_NAME?cat=system-tools&repo=$repo">System tools</a>
145 <a class="active_security" href="$SCRIPT_NAME?cat=security&repo=$repo">Security</a>
146 <a class="active_misc" href="$SCRIPT_NAME?cat=misc&repo=$repo">Misc</a>
147 <a class="active_meta" href="$SCRIPT_NAME?cat=meta&repo=$repo">Meta</a>
148 <a class="active_non-free" href="$SCRIPT_NAME?cat=non-free&repo=$repo">Non free</a>
149 <a class="active_all" href="$SCRIPT_NAME?cat=all&repo=$repo">All</a>
150 EOT
152 if [ -d $LOCALSTATE/undigest ]; then
153 [ -n "$category" ] || category="base-system"
154 cat << EOT
155 <p></p>
156 <h4>Repositories</h4>
157 <a class="repo_Public" href="$SCRIPT_NAME?repo=Public&cat=$category">Public</a>
158 EOT
159 for i in $(ls $LOCALSTATE/undigest); do
160 cat << EOT
161 <a class="repo_$i" href="$SCRIPT_NAME?repo=$i&cat=$category">$i</a>
162 EOT
163 done
164 cat << EOT
165 <a class="repo_Any" href="$SCRIPT_NAME?repo=Any&cat=$category">Any</a>
166 EOT
167 fi
168 echo "</div>"
169 }
171 repo_list() {
172 if [ -n "$(ls $LOCALSTATE/undigest/ 2> /dev/null)" ]; then
173 case "$repo" in
174 Public) ;;
175 ""|Any) for i in $LOCALSTATE/undigest/* ; do
176 [ -d "$i" ] && echo "$i$1"
177 done ;;
178 *) echo "$LOCALSTATE/undigest/$repo$1"
179 return ;;
180 esac
181 fi
182 echo "$LOCALSTATE$1"
183 }
185 repo_name() {
186 case "$1" in
187 $LOCALSTATE) echo "Public" ;;
188 $LOCALSTATE/undigest/*) echo ${1#$LOCALSTATE/undigest/} ;;
189 esac
190 }
192 #
193 # Commands
194 #
196 case " $(GET) " in
197 *\ list\ *)
198 #
199 # List installed packages. This is the default because parsing
200 # the full packages.desc can be long and take up some resources
201 #
202 cd $INSTALLED
203 search_form
204 sidebar
205 LOADING_MSG="Listing packages..."
206 loading_msg
207 cat << EOT
208 <h2>`gettext "My packages"`</h2>
209 <form method='get' action='$SCRIPT_NAME'>
210 <div id="actions">
211 <div class="float-left">
212 `gettext "Selection:"`
213 <input type="submit" name="do" value="Remove" />
214 </div>
215 <div class="float-right">
216 `gettext "List:"`
217 <input type="submit" name="recharge" value="Recharge" />
218 <input type="submit" name="up" value="Upgrade" />
219 </div>
220 </div>
221 EOT
222 table_start
223 table_head
224 for pkg in *
225 do
226 . $pkg/receipt
227 echo '<tr>'
228 # Use default tazpkg icon since all packages displayed are
229 # installed
230 colorpkg=$pkg
231 grep -qs "^$pkg$" $LOCALSTATE/blocked-packages.list &&
232 colorpkg="<span style='color: red;'>$pkg</span>"
233 echo "<td class='pkg'>
234 <input type='checkbox' name='pkg' value=\"$pkg\" />
235 <a href='$SCRIPT_NAME?info=$pkg'><img
236 src='$IMAGES/tazpkg-installed.png'/>$colorpkg</a></td>"
237 echo "<td>$VERSION</td>"
238 echo "<td class='desc'>$SHORT_DESC</td>"
239 echo "<td><a href='$WEB_SITE'><img src='$IMAGES/browser.png'/></a></td>"
240 echo '</tr>'
241 done
242 table_end
243 echo '</form>' ;;
244 *\ linkable\ *)
245 #
246 # List linkable packages.
247 #
248 cd $INSTALLED
249 search_form
250 sidebar
251 LOADING_MSG="Listing linkable packages..."
252 loading_msg
253 cat << EOT
254 <h2>`gettext "Linkable packages"`</h2>
255 <form method='get' action='$SCRIPT_NAME'>
256 <div id="actions">
257 <div class="float-left">
258 `gettext "Selection:"`
259 <input type="submit" name="do" value="Link" />
260 </div>
261 <div class="float-right">
262 `gettext "List:"`
263 <input type="submit" name="recharge" value="Recharge" />
264 <input type="submit" name="up" value="Upgrade" />
265 </div>
266 </div>
267 EOT
268 table_start
269 table_head
270 target=$(readlink $LOCALSTATE/fslink)
271 for pkg in $(ls $target/$INSTALLED)
272 do
273 [ -s $pkg/receipt ] && continue
274 . $target/$INSTALLED/$pkg/receipt
275 echo '<tr>'
276 echo "<td class='pkg'>
277 <input type='checkbox' name='pkg' value=\"$pkg\" />
278 <a href='$SCRIPT_NAME?info=$pkg'><img
279 src='$IMAGES/tazpkg.png'/>$pkg</a></td>"
280 echo "<td>$VERSION</td>"
281 echo "<td class='desc'>$SHORT_DESC</td>"
282 echo "<td><a href='$WEB_SITE'><img src='$IMAGES/browser.png'/></a></td>"
283 echo '</tr>'
284 done
285 table_end
286 echo '</form>' ;;
287 *\ cat\ *)
288 #
289 # List all available packages by category on mirror. Listing all
290 # packages is too resource intensive and not useful.
291 #
292 cd $LOCALSTATE
293 repo=$(GET repo)
294 category=$(GET cat)
295 [ "$category" == "cat" ] && category="base-system"
296 grep_category=$category
297 [ "$grep_category" == "all" ] && grep_category=".*"
298 search_form
299 sidebar | sed "s/active_$category/active/;s/repo_$repo/active/"
300 LOADING_MSG="Listing packages..."
301 loading_msg
302 cat << EOT
303 <h2>`gettext "Category:"` $category</h2>
304 <form method='get' action='$SCRIPT_NAME'>
305 <div id="actions">
306 <div class="float-left">
307 `gettext "Selection:"`
308 <input type="submit" name="do" value="Install" />
309 <input type="submit" name="do" value="Remove" />
310 <input type="hidden" name="repo" value="$repo" />
311 </div>
312 <div class="float-right">
313 `gettext "List:"`
314 <input type="submit" name="recharge" value="Recharge" />
315 <input type="submit" name="up" value="Upgrade" />
316 <a class="button" href='$SCRIPT_NAME?list'>
317 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
318 </div>
319 </div>
320 EOT
321 for i in $(repo_list ""); do
322 [ "$repo" != "Public" ] &&
323 echo "<h3>Repository: $(repo_name $i)</h3>"
324 table_start
325 table_head
326 grep "| $grep_category |" $i/packages.desc | \
327 parse_packages_desc
328 table_end
329 done
330 echo '</form>' ;;
331 *\ search\ *)
332 #
333 # Search for packages. Here default is to search in packages.desc
334 # and so get result including packages names and descriptions
335 #
336 pkg=$(GET search)
337 repo=$(GET repo)
338 cd $LOCALSTATE
339 search_form
340 sidebar | sed "s/repo_$repo/active/"
341 LOADING_MSG="Searching packages..."
342 loading_msg
343 cat << EOT
344 <h2>`gettext "Search packages"`</h2>
345 <form method="get" action="$SCRIPT_NAME">
346 <div id="actions">
347 <div class="float-left">
348 `gettext "Selection:"`
349 <input type="submit" name="do" value="Install" />
350 <input type="submit" name="do" value="Remove" />
351 <a href="`cat $PANEL/lib/checkbox.js`">`gettext "Toogle all"`</a>
352 </div>
353 <div class="float-right">
354 `gettext "List:"`
355 <input type="submit" name="recharge" value="Recharge" />
356 <input type="submit" name="up" value="Upgrade" />
357 <a class="button" href='$SCRIPT_NAME?list'>
358 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
359 </div>
360 </div>
361 <input type="hidden" name="repo" value="$repo" />
362 EOT
363 table_start
364 if [ "$(GET files)" ]; then
365 cat <<EOT
366 <tr id="thead">
367 <td>`gettext "Package"`</td>
368 <td>`gettext "File"`</td>
369 </tr>
370 $(unlzma -c $(repo_list /files.list.lzma) \
371 | grep -Ei ": .*$(GET search)" | \
372 while read PACKAGE FILE; do
373 PACKAGE=${PACKAGE%:}
374 image=tazpkg-installed.png
375 [ -d $INSTALLED/$PACKAGE ] || image=tazpkg.png
376 echo "<tr>
377 <td><input type='checkbox' name='pkg' value='$PACKAGE'>
378 <a href='$SCRIPT_NAME?info=$PACKAGE'><img src='$IMAGES/$image' />$PACKAGE</a></td>
379 <td>$FILE</td>
380 </tr>"
381 done)
382 EOT
383 else
384 table_head
385 grep -ih $pkg $(repo_list /packages.desc) | \
386 parse_packages_desc
387 fi
388 table_end
389 echo '</form>' ;;
390 *\ recharge\ *)
391 #
392 # Lets recharge the packages list
393 #
394 search_form
395 sidebar
396 LOADING_MSG="Recharging lists..."
397 loading_msg
398 cat << EOT
399 <h2>`gettext "Recharge"`</h2>
400 <form method='get' action='$SCRIPT_NAME'>
401 <div id="actions">
402 <div class="float-left">
403 <p>
404 `gettext "Recharge checks for new or updated packages"`
405 </p>
406 </div>
407 <div class="float-right">
408 <p>
409 <a class="button" href='$SCRIPT_NAME?up'>
410 <img src="$IMAGES/update.png" />`gettext "Check upgrades"`</a>
411 <a class="button" href='$SCRIPT_NAME?list'>
412 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
413 </p>
414 </div>
415 </div>
416 <pre>
417 EOT
418 gettext "Recharging packages list" | log
419 tazpkg recharge | filter_taztools_msgs
420 cat << EOT
421 </pre>
422 <p>
423 `gettext "Packages lists are up-to-date. You should check for upgrades now."`
424 </p>
425 EOT
426 ;;
427 *\ up\ *)
428 #
429 # Upgrade packages
430 #
431 cd $LOCALSTATE
432 search_form
433 sidebar
434 LOADING_MSG="Checking for upgrades..."
435 loading_msg
436 cat << EOT
437 <h2>`gettext "Up packages"`</h2>
438 <form method="get" action="$SCRIPT_NAME">
439 <div id="actions">
440 <div class="float-left">
441 `gettext "Selection:"`
442 <input type="submit" name="do" value="Install" />
443 <input type="submit" name="do" value="Remove" />
444 <a href="`cat $PANEL/lib/checkbox.js`">`gettext "Toogle all"`</a>
445 </div>
446 <div class="float-right">
447 `gettext "List:"`
448 <input type="submit" name="recharge" value="Recharge" />
449 <a class="button" href='$SCRIPT_NAME?list'>
450 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
451 </div>
452 </div>
453 EOT
454 tazpkg up --check >/dev/null
455 table_start
456 table_head
457 for pkg in `cat packages.up`
458 do
459 grep -hs "^$pkg |" $LOCALSTATE/packages.desc \
460 $LOCALSTATE/undigest/*/packages.desc | \
461 parse_packages_desc
462 done
463 table_end
464 echo '</form>' ;;
465 *\ do\ *)
466 #
467 # Do an action on one or some packages
468 #
469 opt=""
470 pkgs=""
471 cmdline=$(echo ${QUERY_STRING#do=} | sed s'/&/ /g')
472 cmd=$(echo ${cmdline} | awk '{print $1}')
473 cmdline=${cmdline#*repo=* }
474 pkgs=$(echo $cmdline | sed -e s'/+/ /g' -e s'/pkg=//g' -e s/$cmd//)
475 pkgs="$(httpd -d "$pkgs")"
476 cmd=$(echo $cmd | tr [:upper:] [:lower:])
477 case $cmd in
478 install)
479 cmd=get-install opt=--forced ;;
480 link)
481 opt=$(readlink $LOCALSTATE/fslink) ;;
482 esac
483 search_form
484 sidebar
485 LOADING_MSG="${cmd}ing packages..."
486 loading_msg
487 cat << EOT
488 <h2>Tazpkg: $cmd</h2>
489 <form method="get" action="$SCRIPT_NAME">
490 <div id="actions">
491 <div class="float-left">
492 <p>
493 `gettext "Performing tasks on packages"`
494 </p>
495 </div>
496 <div class="float-right">
497 <p>
498 <a class="button" href='$SCRIPT_NAME?list'>
499 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
500 </p>
501 </div>
502 </div>
503 EOT
504 echo '<div class="box">'
505 gettext "Executing $cmd for:$pkgs"
506 echo '</div>'
507 for pkg in $pkgs
508 do
509 echo '<pre>'
510 echo 'y' | tazpkg $cmd $pkg $opt 2>/dev/null | filter_taztools_msgs
511 echo '</pre>'
512 done ;;
513 *\ info\ *)
514 #
515 # Packages info
516 #
517 pkg=$(GET info)
518 search_form
519 sidebar
520 if [ -d $INSTALLED/$pkg ]; then
521 . $INSTALLED/$pkg/receipt
522 files=`cat $INSTALLED/$pkg/files.list | wc -l`
523 action=$(gettext "Remove")
524 else
525 cd $LOCALSTATE
526 LOADING_MSG=$(gettext "Getting package info...")
527 loading_msg
528 IFS='|'
529 set -- $(grep -hs "^$pkg |" packages.desc \
530 undigest/*/packages.desc)
531 unset IFS
532 PACKAGE=$1
533 VERSION="$(echo $2)"
534 SHORT_DESC="$(echo $3)"
535 CATEGORY="$(echo $4)"
536 WEB_SITE="$(echo $5)"
537 action=$(gettext "Install")
538 temp="$(echo $pkg | sed 's/get-//g')"
539 fi
540 cat << EOT
541 <h2>`gettext "Package"` $PACKAGE</h2>
542 <div id="actions">
543 <div class="float-left">
544 <p>
545 EOT
546 if [ "$temp" != "$pkg" -a "$action" == $(gettext "Install") ]; then
547 temp="$(echo $pkg | sed 's/get-//g')"
548 echo "<a class='button' href='$SCRIPT_NAME?do=$action&$temp'>$action (Non Free)</a>"
549 else
551 echo "<a class='button' href='$SCRIPT_NAME?do=$action&$pkg'>$action</a>"
552 fi
554 if [ -d $INSTALLED/$pkg ]; then
555 if grep -qs "^$pkg$" $LOCALSTATE/blocked-packages.list; then
556 block=$(gettext "Unblock")
557 else
558 block=$(gettext "Block")
559 fi
560 cat << EOT
561 <a class="button" href='$SCRIPT_NAME?do=$block&$pkg'>$block</a>
562 <a class="button" href='$SCRIPT_NAME?do=Repack&$pkg'>Repack</a>
563 EOT
564 fi
565 cat << EOT
566 </p>
567 </div>
568 <div class="float-right">
569 <p>
570 <a class="button" href='$SCRIPT_NAME?list'>
571 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
572 </p>
573 </div>
574 </div>
575 <pre>
576 Name : $PACKAGE
577 Version : $VERSION
578 Description : $SHORT_DESC
579 Category : $CATEGORY
580 EOT
581 if [ -d $INSTALLED/$pkg ]; then
582 cat << EOT
583 Maintainer : $MAINTAINER
584 Website : <a href="$WEB_SITE">$WEB_SITE</a>
585 Sizes : $PACKED_SIZE/$UNPACKED_SIZE
586 EOT
587 if [ -n "$DEPENDS" ]; then
588 echo -n "Depends : "
589 for i in $DEPENDS; do
590 echo -n "<a href="$SCRIPT_NAME?info=$i">$i</a> "
591 done
592 echo ""
593 fi
594 if [ -n "$SUGGESTED" ]; then
595 echo -n "Suggested : "
596 for i in $SUGGESTED; do
597 echo -n "<a href="$SCRIPT_NAME?info=$i">$i</a> "
598 done
599 echo ""
600 fi
601 [ -n "$TAGS" ] && echo "Tags : $TAGS"
602 cat << EOT
603 </pre>
605 <p>`gettext "Installed files:"` `cat $INSTALLED/$pkg/files.list | wc -l`</p>
606 <pre>
607 `cat $INSTALLED/$pkg/files.list`
608 </pre>
609 EOT
610 else
611 cat << EOT
612 Website : <a href="$WEB_SITE">$WEB_SITE</a>
613 Sizes : `grep -hsA 3 ^$pkg$ packages.txt undigest/*/packages.txt | \
614 tail -n 1 | sed 's/ *//'`
615 </pre>
617 <p>`gettext "Installed files:"`</p>
618 <pre>
619 `unlzma -c files.list.lzma undigest/*/files.list.lzma 2> /dev/null | \
620 sed "/^$pkg: /!d;s/^$pkg: //"`
621 </pre>
622 EOT
623 fi
624 ;;
625 *\ admin\ * )
626 #
627 # Tazpkg configuration page
628 #
629 cmd=$(GET admin)
630 case "$cmd" in
631 clean)
632 rm -rf /var/cache/tazpkg/* ;;
633 add-mirror)
634 # Decode url
635 mirror=$(GET mirror)
636 case "$mirror" in
637 http://*|ftp://*)
638 echo "$mirror" >> $(GET file) ;;
639 esac ;;
640 rm-mirror=http://*|rm-mirror=ftp://*)
641 mirror=${cmd#rm-mirror=}
642 sed -i -e "s@$mirror@@" -e '/^$/d' $(GET file) ;;
643 select-mirror*)
644 release=`cat /etc/slitaz-release`
645 mirror="$(GET mirror)packages/$release/"
646 tazpkg setup-mirror $mirror | log
647 ;;
648 add-repo)
649 # Decode url
650 mirror=$(GET mirror)
651 repository=$LOCALSTATE/undigest/$(GET repository)
652 case "$mirror" in
653 http://*|ftp://*)
654 mkdir -p $repository
655 echo "$mirror" > $repository/mirror
656 echo "$mirror" > $repository/mirrors ;;
657 esac ;;
658 rm-repo=*)
659 repository=${cmd#rm-repo=}
660 rm -rf $LOCALSTATE/undigest/$repository ;;
661 esac
662 [ "$cmd" == "$(gettext "Set link")" ] &&
663 [ -d "$(GET link)/$INSTALLED" ] &&
664 ln -fs $(GET link) $LOCALSTATE/fslink
665 [ "$cmd" == "$(gettext "Remove link")" ] &&
666 rm -f $LOCALSTATE/fslink
667 cache_files=`find /var/cache/tazpkg -name *.tazpkg | wc -l`
668 cache_size=`du -sh /var/cache/tazpkg`
669 sidebar
670 cat << EOT
671 <h2>$(gettext "Administration")</h2>
672 <div>
673 <p>$(gettext "Tazpkg administration and settings")</p>
674 </div>
675 <div id="actions">
676 <a class="button" href='$SCRIPT_NAME?admin=&action=saveconf'>
677 <img src="$IMAGES/tazpkg.png" />`gettext "Save configuration"`</a>
678 <a class="button" href='$SCRIPT_NAME?admin=&action=listconf'>
679 <img src="$IMAGES/edit.png" />`gettext "List configuration files"`</a>
680 <a class="button" href='$SCRIPT_NAME?admin=&action=quickcheck'>
681 <img src="$IMAGES/recharge.png" />`gettext "Quick check"`</a>
682 <a class="button" href='$SCRIPT_NAME?admin=&action=fullcheck'>
683 <img src="$IMAGES/recharge.png" />`gettext "Full check"`</a>
684 </div>
685 EOT
686 case "$(GET action)" in
687 saveconf)
688 LOADING_MSG=$(gettext "Creating the package...")
689 loading_msg
690 echo "<pre>"
691 cd $HOME
692 tazpkg repack-config | filter_taztools_msgs
693 gettext "Path : " && ls $HOME/config-*.tazpkg
694 echo "</pre>" ;;
695 listconf)
696 echo "<h4>`gettext "Configuration files"`</h4>"
697 echo "<ul>"
698 tazpkg list-config | while read file; do
699 [ "${file:0:1}" == "/" ] || continue
700 if [ -e $file ]; then
701 echo "<li><a href=\"index.cgi?file=$file\">$file</a></li>"
702 else
703 echo "<li>$file</li>"
704 fi
705 done
706 echo "</ul>"
707 echo "</pre>" ;;
708 quickcheck)
709 LOADING_MSG=$(gettext "Checking packages consistency...")
710 loading_msg
711 echo "<pre>"
712 tazpkg check
713 echo "</pre>" ;;
714 fullcheck)
715 LOADING_MSG=$(gettext "Full packages check...")
716 loading_msg
717 echo "<pre>"
718 tazpkg check --full
719 echo "</pre>" ;;
720 esac
721 cat << EOT
722 <h3>$(gettext "Packages cache")</h3>
723 <div>
724 <form method="get" action="$SCRIPT_NAME">
725 <p>
726 `gettext "Packages in the cache:"` $cache_files ($cache_size)
727 <input type="hidden" name="admin" value="clean" />
728 <input type="submit" value="Clean" />
729 </p>
730 </form>
731 </div>
732 <h3>`gettext "Default mirror"`</h3>
733 `cat /var/lib/tazpkg/mirror`
734 <h3>`gettext "Current mirror list"`</h3>
735 EOT
736 for i in $LOCALSTATE/mirrors $LOCALSTATE/undigest/*/mirrors; do
737 [ -s $i ] || continue
738 echo '<div class="box">'
739 [ $i != $LOCALSTATE/mirrors ] &&
740 echo "<h4>Repository: $(repo_name $(dirname $i))</h4>"
741 echo "<ul>"
742 list_mirrors $i
743 echo "</ul>"
744 cat << EOT
745 </div>
746 <form method="get" action="$SCRIPT_NAME">
747 <p>
748 <input type="hidden" name="admin" value="add-mirror" />
749 <input type="hidden" name="file" value="$i" />
750 <input type="text" name="mirror" size="60">
751 <input type="submit" value="Add mirror" />
752 </p>
753 </form>
754 EOT
755 done
756 echo "<h3>"
757 gettext "Private repositories"
758 echo "</h3>"
759 [ -n "$(ls $LOCALSTATE/undigest 2> /dev/null)" ] && cat << EOT
760 <div class="box">
761 <ul>
762 $(list_repos)
763 </ul>
764 </div>
765 EOT
766 cat << EOT
767 <form method="get" action="$SCRIPT_NAME">
768 <p>
769 <input type="hidden" name="admin" value="add-repo" />
770 Name <input type="text" name="repository" size="10">
771 mirror
772 <input type="text" name="mirror" value="http://" size="50">
773 <input type="submit" value="Add repository" />
774 </p>
775 </form>
776 <h3>`gettext "Link to another SliTaz installation"`</h3>
777 <p>
778 $(gettext "This link points to the root of another SliTaz installation. \
779 You will be able to install packages using soft links to it.")
780 </p>
781 <form method="get" action="$SCRIPT_NAME">
782 <p>
783 <input type="hidden" name="admin" value="add-link" />
784 <input type="text" name="link"
785 value="$(readlink $LOCALSTATE/fslink 2> /dev/null)" size="50">
786 <input type="submit" name="admin" value="$(gettext "Set link")" />
787 <input type="submit" name="admin" value="$(gettext "Remove link")" />
788 </p>
789 </form>
790 EOT
791 version=$(cat /etc/slitaz-release)
792 cat << EOT
794 <a name="dvd"></a>
795 <h3>`gettext "SliTaz packages DVD"`</h3>
796 <p>
797 $(gettext "A bootable DVD image of all available packages for \
798 the $version version is generated every day. It also contains a copy of \
799 the website and can be used without an internet connection. This image can be \
800 installed on a DVD or an USB key.")
801 </p>
802 <div>
803 <form method="post" action='$SCRIPT_NAME?admin&action=dvdimage#dvd'>
804 <p>
805 <a class="button"
806 href='http://mirror.slitaz.org/iso/$version/packages-$version.iso'>
807 <img src="$IMAGES/tazpkg.png" />$(gettext "Download DVD image")</a>
808 <a class="button" href='$SCRIPT_NAME?admin&action=dvdusbkey#dvd'>
809 <img src="$IMAGES/tazpkg.png" />$(gettext "Install from DVD/USB key")</a>
810 </p>
811 <div class="box">
812 $(gettext "Install from ISO image: ")
813 <input type="text" name="dvdimage" size="40" value="/root/packages-$version.iso">
814 </div>
815 </form>
816 </div>
817 EOT
818 if [ "$(GET action)" == "dvdimage" ]; then
819 dev=$(POST dvdimage)
820 mkdir -p /mnt/packages 2> /dev/null
821 echo "<pre>"
822 mount -t iso9660 -o loop,ro $dev /mnt/packages &&
823 /mnt/packages/install.sh &&
824 echo "$dev is installed on /mnt/packages"
825 echo "</pre>"
826 fi
827 if [ "$(GET action)" == "dvdusbkey" ]; then
828 mkdir -p /mnt/packages 2> /dev/null
829 for tag in "LABEL=\"packages-$version\" TYPE=\"iso9660\"" \
830 "LABEL=\"sources-$version\" TYPE=\"iso9660\"" ; do
831 dev=$(blkid | grep "$tag" | cut -d: -f1)
832 [ -n "$dev" ] || continue
833 echo "<pre>"
834 mount -t iso9660 -o ro $dev /mnt/packages &&
835 /mnt/packages/install.sh &&
836 echo "$dev is installed on /mnt/packages"
837 echo "</pre>"
838 break
839 done
840 fi
841 ;;
842 *)
843 #
844 # Default to summary
845 #
846 search_form
847 sidebar
848 [ -n "$(GET block)" ] && tazpkg block $(GET block)
849 [ -n "$(GET unblock)" ] && tazpkg unblock $(GET unblock)
850 cat << EOT
851 <h2>`gettext "Summary"`</h2>
852 <div id="actions">
853 <a class="button" href='$SCRIPT_NAME?list'>
854 <img src="$IMAGES/tazpkg.png" />`gettext "My packages"`</a>
855 EOT
856 fslink=$(readlink $LOCALSTATE/fslink)
857 [ -n "$fslink" -a -d "$fslink/$INSTALLED" ] &&
858 cat << EOT
859 <a class="button" href='$SCRIPT_NAME?linkable'>
860 <img src="$IMAGES/tazpkg.png" />`gettext "Linkable packages"`</a>
861 EOT
862 cat << EOT
863 <a class="button" href='$SCRIPT_NAME?recharge'>
864 <img src="$IMAGES/recharge.png" />`gettext "Recharge list"`</a>
865 <a class="button" href='$SCRIPT_NAME?up'>
866 <img src="$IMAGES/update.png" />`gettext "Check upgrades"`</a>
867 <a class="button" href='$SCRIPT_NAME?admin'>
868 <img src="$IMAGES/edit.png" />`gettext "Administration"`</a>
869 </div>
870 <pre class="pre-main">
871 `packages_summary`
872 </pre>
874 <h3>`gettext "Latest log entries"`</h3>
875 <pre>
876 `tail -n 5 /var/log/tazpkg.log | fgrep "-" | \
877 awk '{print $1, $2, $3, $4, $5, $6, $7}'`
878 </pre>
879 EOT
880 ;;
881 esac
883 # xHTML 5 footer
884 xhtml_footer
885 exit 0