tazpkg view tazpanel/pkgs.cgi @ rev 729

pkgs.cgi: remove debug changes.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Dec 27 17:41:56 2014 +0200 (2014-12-27)
parents a16752d6a1b1
children 891dbeab2453
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-2014 SliTaz GNU/Linux - BSD License
10 #
12 . /lib/libtaz.sh
13 . lib/libtazpanel
15 . /etc/slitaz/slitaz.conf
16 . /etc/slitaz/tazpkg.conf
18 get_config
19 header
22 # xHTML 5 header with special side bar for categories.
23 TITLE=$(TEXTDOMAIN='tazpkg'; _ 'TazPanel - Packages')
24 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
26 export TEXTDOMAIN='tazpkg'
28 pkg_info_link()
29 {
30 echo "<a class=\"$2\" href=\"?info=${1//+/%2B}\">$1</a>" | sed 's| class=""||'
31 }
34 # Display localized short description
36 i18n_desc() {
37 for L in $LANG ${LANG%%_*}; do
38 if [ -e "$PKGS_DB/packages-desc.$L" ]; then
39 LOCDESC=$(awk -F$'\t' -vp=$1 '{if ($1 == p) print $2}' $PKGS_DB/packages-desc.$L)
40 if [ -n "$LOCDESC" ]; then
41 SHORT_DESC="$LOCDESC"
42 break
43 fi
44 fi
45 done
46 }
49 # We need packages information for list and search
51 parse_packages_desc() {
52 IFS="|"
53 cut -f 1,2,3,5 -d "|" | while read PACKAGE VERSION SHORT_DESC WEB_SITE
54 do
55 class=pkg; [ -d $INSTALLED/${PACKAGE% } ] && class=pkgi
56 i18n_desc $PACKAGE
57 cat << EOT
58 <tr>
59 <td><input type="checkbox" name="pkg" value="$PACKAGE">$(pkg_info_link $PACKAGE $class)</td>
60 <td>$VERSION</td>
61 <td>$SHORT_DESC</td>
62 <td><a class="w" href="$WEB_SITE"></a></td>
63 </tr>
64 EOT
65 done
66 unset IFS
67 }
70 parse_packages_info() {
71 IFS=$'\t'
72 while read PACKAGE VERSION CATEGORY SHORT_DESC WEB_SITE TAGS SIZES DEPENDS; do
73 class=pkg; grep -q "^$PACKAGE$'\t'" $PKGS_DB/installed.info && class=pkgi
74 i18n_desc $PACKAGE
75 cat << EOT
76 <tr>
77 <td><input type="checkbox" name="pkg" value="$PACKAGE">$(pkg_info_link $PACKAGE $class)</td>
78 <td>$VERSION</td>
79 <td>$SHORT_DESC</td>
80 <td><a class="w" href="$WEB_SITE"></a></td>
81 </tr>
82 EOT
83 done
84 unset IFS
85 }
88 # Display a full summary of packages stats
90 packages_summary() {
91 cat << EOT
92 <table class="zebra outbox">
93 <tbody>
94 <tr><td>$(_ 'Last recharge:')</td><td>
95 EOT
96 ls -l $PKGS_DB/packages.list | awk '{print $6, $7, $8}'
97 if [ -n "$(find $PKGS_DB/packages.list -mtime +10)" ]; then
98 _ '(Older than 10 days)'
99 else
100 _ '(Not older than 10 days)'
101 fi
102 cat << EOT
103 </td></tr>
104 <tr><td>$(_ 'Installed packages:')</td>
105 <td>$(cat $PKGS_DB/installed.info | wc -l)</td></tr>
106 <tr><td>$(_ 'Mirrored packages:')</td>
107 <td>$(cat $PKGS_DB/packages.list | wc -l)</td></tr>
108 <tr><td>$(_ 'Upgradeable packages:')</td>
109 <td>$(cat $PKGS_DB/packages.up | wc -l)</td></tr>
110 <tr><td>$(_ 'Installed files:')</td>
111 <td>$(cat $INSTALLED/*/files.list | wc -l)</td></tr>
112 <tr><td>$(_ 'Blocked packages:')</td>
113 <td>$(cat $PKGS_DB/blocked-packages.list | wc -l)</td></tr>
114 </tbody>
115 </table>
116 EOT
117 }
120 # Parse mirrors list to be able to have an icon and remove link
122 list_mirrors() {
123 while read line
124 do
125 cat << EOT
126 <li>
127 <a href="$SCRIPT_NAME?admin=rm-mirror=$line&amp;file=$(httpd -e $1)">
128 <img src="$IMAGES/clear.png" title="$(_ 'Delete')" />
129 </a>
130 <a href="$SCRIPT_NAME?admin=select-mirror&amp;mirror=$line">
131 <img src="$IMAGES/start.png" title="$(_ 'Use as default')" />
132 </a>
133 <a href="$line">$line</a>
134 </li>
135 EOT
136 done < $1
137 }
140 # Parse repositories list to be able to have an icon and remove link
142 list_repos() {
143 ls $PKGS_DB/undigest 2> /dev/null | while read repo ; do
144 cat <<EOT
145 <li><a href="$SCRIPT_NAME?admin=rm-repo=$repo">
146 <img src="$IMAGES/clear.png">$repo</a></li>
147 EOT
148 done
149 }
152 # Show button
153 show_button() {
154 case $1 in
155 recharge) img='recharge'; label="$(_ 'Recharge list')" ;;
156 up) img='update'; label="$(_ 'Check upgrades')" ;;
157 list) img='tazpkg'; label="$(_ 'My packages')" ;;
158 linkable) img='tazpkg'; label="$(_ 'Linkable packages')" ;;
159 admin) img='edit'; label="$(_ 'Administration')" ;;
160 *Install*nf*) img=''; label="$(_ 'Install (Non Free)')" ;;
161 *Install*) img=''; label="$(_ 'Install')" ;;
162 *Remove*) img='stop'; label="$(_ 'Remove')" ;;
163 *Block*) img=''; label="$(_ 'Block')" ;;
164 *Unblock*) img=''; label="$(_ 'Unblock')" ;;
165 *Repack*) img=''; label="$(_ 'Repack')" ;;
166 *saveconf*) img='tazpkg'; label="$(_ 'Save configuration')" ;;
167 *listconf*) img='edit'; label="$(_ 'List configuration files')" ;;
168 *quickcheck*) img='recharge'; label="$(_ 'Quick check')" ;;
169 *fullcheck*) img='recharge'; label="$(_ 'Full check')" ;;
170 esac
171 echo -n "<a class=\"button\" href=\"?$1\">"
172 [ -n "$img" ] && echo -n "<img src=\"$IMAGES/$img.png\" />"
173 echo "$label</a>"
174 }
178 #
179 # xHTML functions
180 #
183 # ENTER will search but user may search for a button, so put one.
185 search_form() {
186 [ -z "$repo" ] && repo="$(GET repo)"
187 [ -z "$repo" ] && repo="Any"
188 cat << EOT
189 <div class="search">
190 <form method="get" action="$SCRIPT_NAME">
191 <p>
192 <input type="text" name="search" size="20">
193 <input type="submit" value="$(gettext 'Search')">
194 <input class="radius" type="submit" name="files"
195 value="$(_n 'Files')">
196 <input type="hidden" name="repo" value="$repo" />
197 </p>
198 </form>
199 </div>
200 EOT
201 }
204 table_head() {
205 cat << EOT
206 <thead>
207 <tr>
208 <td>$(_ 'Name')</td>
209 <td>$(_ 'Version')</td>
210 <td>$(_ 'Description')</td>
211 <td>$(_ 'Web')</td>
212 </tr>
213 </thead>
214 EOT
215 }
218 sidebar() {
219 [ -n "$repo" ] || repo=Public
220 cat << EOT
221 <div id="sidebar">
222 <h4>$(_ 'Categories')</h4>
223 <a class="active_base-system" href="$SCRIPT_NAME?cat=base-system&repo=$repo" >$(_ 'base-system')</a>
224 <a class="active_x-window" href="$SCRIPT_NAME?cat=x-window&repo=$repo" >$(_ 'x-window')</a>
225 <a class="active_utilities" href="$SCRIPT_NAME?cat=utilities&repo=$repo" >$(_ 'utilities')</a>
226 <a class="active_network" href="$SCRIPT_NAME?cat=network&repo=$repo" >$(_ 'network')</a>
227 <a class="active_games" href="$SCRIPT_NAME?cat=games&repo=$repo" >$(_ 'games')</a>
228 <a class="active_graphics" href="$SCRIPT_NAME?cat=graphics&repo=$repo" >$(_ 'graphics')</a>
229 <a class="active_office" href="$SCRIPT_NAME?cat=office&repo=$repo" >$(_ 'office')</a>
230 <a class="active_multimedia" href="$SCRIPT_NAME?cat=multimedia&repo=$repo" >$(_ 'multimedia')</a>
231 <a class="active_development" href="$SCRIPT_NAME?cat=development&repo=$repo" >$(_ 'development')</a>
232 <a class="active_system-tools" href="$SCRIPT_NAME?cat=system-tools&repo=$repo">$(_ 'system-tools')</a>
233 <a class="active_security" href="$SCRIPT_NAME?cat=security&repo=$repo" >$(_ 'security')</a>
234 <a class="active_misc" href="$SCRIPT_NAME?cat=misc&repo=$repo" >$(_ 'misc')</a>
235 <a class="active_meta" href="$SCRIPT_NAME?cat=meta&repo=$repo" >$(_ 'meta')</a>
236 <a class="active_non-free" href="$SCRIPT_NAME?cat=non-free&repo=$repo" >$(_ 'non-free')</a>
237 <a class="active_all" href="$SCRIPT_NAME?cat=all&repo=$repo" >$(_ 'all')</a>
238 <a class="active_extra" href="$SCRIPT_NAME?cat=extra&repo=$repo" >$(_ 'extra')</a>
239 EOT
241 if [ -d $PKGS_DB/undigest ]; then
242 [ -n "$category" ] || category="base-system"
243 cat << EOT
244 <h4>$(_ 'Repositories')</h4>
245 <a class="repo_Public" href="$SCRIPT_NAME?repo=Public&cat=$category">$(_ 'Public')</a>
246 EOT
248 for i in $(ls $PKGS_DB/undigest); do
249 cat << EOT
250 <a class="repo_$i" href="$SCRIPT_NAME?repo=$i&cat=$category">$i</a>
251 EOT
252 done
254 cat << EOT
255 <a class="repo_Any" href="$SCRIPT_NAME?repo=Any&cat=$category">$(_ 'Any')</a>
256 EOT
257 fi
258 echo "</div>"
259 }
262 repo_list() {
263 if [ -n "$(ls $PKGS_DB/undigest/ 2> /dev/null)" ]; then
264 case "$repo" in
265 Public)
266 ;;
267 ""|Any)
268 for i in $PKGS_DB/undigest/* ; do
269 [ -d "$i" ] && echo "$i$1"
270 done ;;
271 *)
272 echo "$PKGS_DB/undigest/$repo$1"
273 return ;;
274 esac
275 fi
276 echo "$PKGS_DB$1"
277 }
280 repo_name() {
281 case "$1" in
282 $PKGS_DB)
283 echo "Public" ;;
284 $PKGS_DB/undigest/*)
285 echo ${1#$PKGS_DB/undigest/} ;;
286 esac
287 }
290 make_mixed_list() {
291 for L in $LANG ${LANG%%_*}; do
292 if [ -e "$PKGS_DB/packages-desc.$L" ]; then
293 sed '/^#/d' $PKGS_DB/packages-desc.$L
294 break
295 fi
296 done
298 [ -e "$i/blocked-packages.list" ] && cat $i/blocked-packages.list
300 sed 's|.*|&\ti|' $i/installed.info
302 cat $i/packages.info
303 }
306 # Print links to the pages
308 pager() {
309 awk -F'"' -vpage="$page" -vnum_lines="$(wc -l < $1)" -vtext="$(_ 'Pages:') " -vurl="?cat=$category&amp;repo=$repo&amp;page=" '
310 BEGIN{
311 num_pages = int(num_lines / 100) + (num_lines % 100 != 0)
312 if (num_pages != 1) printf "<p>%s", text
313 }
314 {
315 if (num_pages == 1) exit
316 r = NR % 100
317 if (r == 1) {
318 p = int(NR / 100) + 1
319 printf "<a class=\"pages%s\" href=\"%s%s\" title=\"%s\n···\n", p==page?" current":"", url, p, $6
320 } else if (r == 0)
321 printf "%s\">%s</a> ", $6, int(NR / 100)
322 }
323 END{
324 if (num_pages == 1) exit
325 if (r != 0) printf "%s\">%s</a>", $6, int(NR / 100) + 1
326 print "</p>"
327 }' $1
328 }
331 # Show links for "info" page
333 show_info_links() {
334 if [ -n "$1" ]; then
335 echo -n "<tr><td><b>$2</b></td><td>"
336 echo $1 | tr ' ' $'\n' | awk -vt="$3" '{
337 printf "<a href=\"?%s=%s\">%s</a> ", t, gensub(/\+/, "%2B", "g", $1), $1
338 }'
339 echo "</td></tr>"
340 fi
341 }
345 #
346 # Commands
347 #
350 case " $(GET) " in
351 *\ list\ *)
352 #
353 # List installed packages. This is the default because parsing
354 # the full packages.desc can be long and take up some resources
355 #
356 cd $INSTALLED
357 search_form
358 sidebar
359 LOADING_MSG="$(_ 'Listing packages...')"
360 loading_msg
361 cat << EOT
362 <h2>$(_ 'My packages')</h2>
363 <form method='get' action='$SCRIPT_NAME'>
364 <input type="hidden" name="do" value="Remove" />
365 <div id="actions">
366 <div class="float-left">
367 $(_ 'Selection:')
368 <input type="submit" value="$(_ 'Remove')" />
369 </div>
370 <div class="float-right">
371 $(show_button recharge)
372 $(show_button up)
373 </div>
374 </div>
376 <table class="zebra outbox pkglist">
377 $(table_head)
378 <tbody>
379 EOT
380 for pkg in *; do
381 . $pkg/receipt
382 echo '<tr>'
383 # Use default tazpkg icon since all packages displayed are
384 # installed
385 blocked=
386 grep -qs "^$pkg$" $PKGS_DB/blocked-packages.list && blocked="b"
387 i18n_desc $pkg
388 cat << EOT
389 <td><input type="checkbox" name="pkg" value="$pkg" />$(pkg_info_link $pkg pkgi$blocked)</td>
390 <td>$VERSION</td>
391 <td>$SHORT_DESC</td>
392 <td><a class="w" href="$WEB_SITE"></a></td>
393 </tr>
394 EOT
395 done
396 cat << EOT
397 </tbody>
398 </table>
399 </form>
400 EOT
401 ;;
404 *\ linkable\ *)
405 #
406 # List linkable packages.
407 #
408 cd $INSTALLED
409 search_form
410 sidebar
411 LOADING_MSG=$(_ 'Listing linkable packages...')
412 loading_msg
413 cat << EOT
414 <h2>$(_ 'Linkable packages')</h2>
416 <form method='get' action='$SCRIPT_NAME'>
417 <input type="hidden" name="do" value="Link" />
418 <div id="actions">
419 <div class="float-left">
420 $(_ 'Selection:')
421 <input type="submit" value="$(_ 'Link')" />
422 </div>
423 <div class="float-right">
424 $(show_button recharge)
425 $(show_button up)
426 </div>
427 </div>
428 EOT
429 cat << EOT
430 <table class="zebra outbox pkglist">
431 $(table_head)
432 <tbody>
433 EOT
434 target=$(readlink $PKGS_DB/fslink)
435 for pkg in $(ls $target/$INSTALLED); do
436 [ -s $pkg/receipt ] && continue
437 . $target/$INSTALLED/$pkg/receipt
438 i18n_desc $pkg
439 cat << EOT
440 <tr>
441 <td><input type="checkbox" name="pkg" value="$pkg" />$(pkg_info_link $pkg pkg)</td>
442 <td>$VERSION</td>
443 <td>$SHORT_DESC</td>
444 <td><a class="w" href="$WEB_SITE"></a></td>
445 </tr>
446 EOT
447 done
448 cat << EOT
449 </tbody>
450 </table>
451 </form>
452 EOT
453 ;;
456 *\ cat\ *)
457 #
458 # List all available packages by category on mirror.
459 #
460 cd $PKGS_DB
461 repo=$(GET repo)
462 category=$(GET cat)
463 search_form
464 sidebar | sed "s/active_$category/active/;s/repo_$repo/active/"
465 if [ -z "$category" ] || [ "$category" == 'cat' ]; then
466 cat << EOT
467 <h2>$(_ 'Categories list')</h2>
468 <table class="zebra outbox">
469 <thead>
470 <tr><td>$(_ 'Category')</td><td>$(_ 'Repository')</td><td>$(_ 'Installed')</td></tr>
471 </thead><tbody>
472 EOT
473 {
474 awk -F$'\t' '{print $3}' $PKGS_DB/packages.info | sort | uniq -c
475 awk -F$'\t' '{print $3}' $PKGS_DB/installed.info | sed 's|.*|& i|' | sort | uniq -c
476 } | sort -k2,2 | awk '
477 {
478 c [$2] = "."
479 if ($3) { i[$2] = $1; } else { m[$2] = $1; }
480 }
481 END {
482 for (n in c) print n, m[n], i[n]
483 }' | sort | awk '{
484 printf "<tr><td><a href=\"?cat=%s\">%s</a></td><td>%d</td><td>%d</td></tr>", $1, $1, $2, $3
485 }'
486 echo '</tbody></table>'
487 else
488 LOADING_MSG="$(_ 'Listing packages...')"
489 loading_msg
490 cat << EOT
491 <h2>$(_ 'Category: %s' $category)</h2>
493 <form method='get' action='$SCRIPT_NAME'>
494 <div id="actions">
495 <div class="float-left">
496 $(_ 'Selection:')
497 <input type="submit" name="do" value="Install" />
498 <input type="submit" name="do" value="Remove" />
499 <input type="hidden" name="repo" value="$repo" />
500 </div>
501 <div class="float-right">
502 $(show_button recharge)
503 $(show_button up)
504 $(show_button list)
505 </div>
506 </div>
507 EOT
508 for i in $(repo_list ""); do
509 if [ "$repo" != "Public" ]; then
510 Repo_Name="$(repo_name $i)"
511 cat << EOT
512 <h3>$(_ 'Repository: %s' $Repo_Name)</h3>
513 EOT
514 fi
516 case $category in
517 extra)
518 echo '<table class="zebra outbox pkglist">'
519 table_head
520 echo '<tbody>'
521 NA="$(_n 'n/a')"
522 for pkg in $(cat $i/extra.list); do
523 PKG="$(grep ^$pkg$'\t' $i/installed.info)"
524 if [ -n "$PKG" ]; then
525 echo "$PKG"
526 else
527 echo "$pkg $NA - $NA http://mirror.slitaz.org/packages/get/$pkg - - -"
528 fi
529 done | parse_packages_info
530 echo "</tbody></table>"
531 ;;
532 *)
533 cached="$CACHE_DIR/$repo-$category"
534 make_mixed_list | sort -t$'\t' -k1,1 | awk -F$'\t' -vc="$category" '
535 {
536 if (PKG && PKG != $1) {
537 if (CAT) {
538 if (DSCL) DSC = DSCL
539 printf "<tr><td><input type=\"checkbox\" name=\"pkg\" value=\"%s\"><a class=\"pkg%s%s\" href=\"?info=%s\">%s</a></td><td>%s</td><td>%s</td><td><a href=\"%s\"></a></td></tr>\n", PKG, INS, BLK, gensub(/\+/, "%2B", "g", PKG), PKG, VER, DSC, WEB
540 }
541 VER = DSC = WEB = DSCL = INS = BLK = CAT = ""
542 }
544 PKG = $1
545 if (NF == 1) { BLK = "b"; next }
546 if (NF == 2) { DSCL = $2; next }
547 if (c == "all" || $3 == c) {
548 CAT = c
549 if ($9 == "i") { PKG = $1; VER = $2; DSC = $4; WEB = $5; INS = "i"; next}
550 if (! INS) { PKG = $1; VER = $2; DSC = $4; WEB = $5 }
551 }
552 }' > $cached
553 page=$(GET page); [ -z "$page" ] && page=1
554 pager="$(pager $cached)"
556 echo "$pager"
557 echo '<table class="zebra outbox pkglist">'
558 table_head
559 echo '<tbody>'
560 tail -n+$((($page-1)*100+1)) $cached | head -n100
561 echo "</tbody></table>"
562 echo "$pager"
563 rm -f $cached
564 ;;
565 esac
566 done
567 echo '</form>'
568 fi
569 ;;
572 *\ search\ *)
573 #
574 # Search for packages. Here default is to search in packages.desc
575 # and so get result including packages names and descriptions
576 #
577 pkg=$(GET search); [ -z "$pkg" ] && xhtml_footer && exit
578 repo=$(GET repo)
579 cd $PKGS_DB
580 search_form
581 sidebar | sed "s/repo_$repo/active/"
582 LOADING_MSG="$(_ 'Searching packages...')"
583 loading_msg
584 cat << EOT
585 <h2>$(_ 'Search packages')</h2>
586 <form method="get" action="$SCRIPT_NAME">
587 <div id="actions">
588 <div class="float-left">
589 $(_ 'Selection:')
590 <input type="submit" name="do" value="Install" />
591 <input type="submit" name="do" value="Remove" />
592 <a href="$(cat $PANEL/lib/checkbox.js)">$(_ 'Toogle all')</a>
593 </div>
594 <div class="float-right">
595 $(show_button recharge)
596 $(show_button up)
597 $(show_button list)
598 </div>
599 </div>
600 <input type="hidden" name="repo" value="$repo" />
601 EOT
602 if [ -n "$(GET files)" ]; then
603 cat <<EOT
604 <table class="zebra outbox filelist">
605 <thead>
606 <tr>
607 <td>$(_ 'Package')</td>
608 <td>$(_ 'File')</td>
609 </tr>
610 <thead>
611 <tbody>
612 EOT
613 lzcat $(repo_list /files.list.lzma) | grep -Ei ": .*$(GET search)" | \
614 while read PACKAGE FILE; do
615 PACKAGE=${PACKAGE%:}
616 class=pkg; [ -d $INSTALLED/$PACKAGE ] && class=pkgi
617 cat << EOT
618 <tr>
619 <td><input type="checkbox" name="pkg" value="$PACKAGE">$(pkg_info_link $PACKAGE $class)</td>
620 <td>$(echo "$FILE" | sed "s|$pkg|<span class=\"diff-add\">$pkg</span>|g")</td>
621 </tr>
622 EOT
623 done
624 else
625 echo ' <table class="zebra outbox pkglist">'
626 table_head
627 echo " <tbody>"
628 awk -F$'\t' 'BEGIN{IGNORECASE = 1}
629 $1 $4 ~ /'$pkg'/{print $0}' $(repo_list /packages.info) | parse_packages_info
630 fi
631 cat << EOT
632 </tbody>
633 </table>
634 </form>
635 EOT
636 ;;
639 *\ recharge\ *)
640 #
641 # Lets recharge the packages list
642 #
643 search_form
644 sidebar
645 LOADING_MSG="$(_ 'Recharging lists...')"
646 loading_msg
647 cat << EOT
648 <h2>$(_ 'Recharge')</h2>
650 <form method='get' action='$SCRIPT_NAME'>
651 <div id="actions">
652 <div class="float-left">
653 <p>$(_ 'Recharge checks for new or updated packages')</p>
654 </div>
655 <div class="float-right">
656 $(show_button up)
657 $(show_button list)
658 </div>
659 </div>
660 <div class="wrapper">
661 <pre>
662 EOT
663 echo $(_ 'Recharging packages list') | log
664 tazpkg recharge | filter_taztools_msgs
665 cat << EOT
666 </pre>
667 </div>
668 <p>$(_ 'Packages lists are up-to-date. You should check for upgrades now.')</p>
669 EOT
670 ;;
673 *\ up\ *)
674 #
675 # Upgrade packages
676 #
677 cd $PKGS_DB
678 search_form
679 sidebar
680 LOADING_MSG="$(_ 'Checking for upgrades...')"
681 loading_msg
682 cat << EOT
683 <h2>$(_ 'Up packages')</h2>
685 <form method="get" action="$SCRIPT_NAME">
686 <div id="actions">
687 <div class="float-left">
688 $(_ 'Selection:')
689 <input type="submit" name="do" value="Install" />
690 <input type="submit" name="do" value="Remove" />
691 <a href="$(cat $PANEL/lib/checkbox.js)">$(_ 'Toogle all')</a>
692 </div>
693 <div class="float-right">
694 $(show_button recharge)
695 $(show_button list)
696 </div>
697 </div>
698 EOT
699 tazpkg up --check >/dev/null
700 cat << EOT
701 <table class="zebra outbox">
702 $(table_head)
703 <tbody>
704 EOT
705 for pkg in $(cat packages.up); do
706 grep -hs "^$pkg |" $PKGS_DB/packages.desc $PKGS_DB/undigest/*/packages.desc | \
707 parse_packages_desc
708 done
709 cat << EOT
710 </tbody>
711 </table>
712 </form>
713 EOT
714 ;;
717 *\ do\ *)
718 #
719 # Do an action on one or some packages
720 #
721 opt=""
722 pkgs=""
723 cmdline=$(echo ${QUERY_STRING#do=} | sed s'/&/ /g')
724 cmd=$(echo ${cmdline} | awk '{print $1}')
725 cmdline=${cmdline#*repo=* }
726 pkgs=$(echo $cmdline | sed -e s'/+/ /g' -e s'/pkg=//g' -e s/$cmd//)
727 pkgs="$(httpd -d "$pkgs")"
728 cmd=$(echo $cmd | tr [:upper:] [:lower:])
729 case $cmd in
730 install)
731 cmd=get-install opt=--forced
732 LOADING_MSG="get-installing packages..."
733 ;;
734 link)
735 opt=$(readlink $PKGS_DB/fslink)
736 LOADING_MSG="linking packages..."
737 ;;
738 esac
739 search_form
740 sidebar
741 loading_msg
742 cat << EOT
743 <h2>TazPkg: $cmd</h2>
745 <form method="get" action="$SCRIPT_NAME">
746 <div id="actions">
747 <div class="float-left">
748 <p>$(_ 'Performing tasks on packages')</p>
749 </div>
750 <div class="float-right">
751 $(show_button list)
752 </div>
753 </div>
754 <div class="box">
755 $(_ 'Executing %s for: %s' $cmd $pkgs)
756 </div>
757 EOT
758 for pkg in $pkgs; do
759 echo '<pre>'
760 echo $(_n 'y') | tazpkg $cmd $pkg $opt 2>/dev/null | filter_taztools_msgs
761 echo '</pre>'
762 done ;;
765 *\ info\ *)
766 #
767 # Packages info
768 #
769 pkg=$(GET info)
770 search_form
771 sidebar
772 if [ -d $INSTALLED/$pkg ]; then
773 . $INSTALLED/$pkg/receipt
774 files=$(wc -l < $INSTALLED/$pkg/files.list)
775 action="Remove"
776 else
777 cd $PKGS_DB
778 LOADING_MSG=$(_ 'Getting package info...')
779 loading_msg
780 eval "$(awk -F$'\t' -vp=$pkg '
781 $1==p{
782 printf "PACKAGE=\"%s\"; VERSION=\"%s\"; CATEGORY=\"%s\"; ", $1, $2, $3
783 printf "SHORT_DESC=\"%s\"; WEB_SITE=\"%s\"; TAGS=\"%s\"; ", $4, $5, $6
784 printf "SIZES=\"%s\"; DEPENDS=\"%s\"", $7, $8
785 }' packages.info undigest/*/packages.info)"
786 PACKED_SIZE=${SIZES% *}
787 UNPACKED_SIZE=${SIZES#* }
789 action="Install"
790 temp="${pkg#get-}"
791 fi
792 cat << EOT
793 <h2>$(_ 'Package %s' $PACKAGE)</h2>
795 <div id="actions">
796 <div class="float-left">
797 <p>
798 EOT
799 if [ "$temp" != "$pkg" -a "$action" == "Install" ]; then
800 show_button "do=Install&$temp&nf"
801 else
802 show_button "do=$action&$pkg"
803 fi
805 if [ -d $INSTALLED/$pkg ]; then
806 if grep -qs "^$pkg$" $PKGS_DB/blocked-packages.list; then
807 show_button "do=Unblock&$pkg"
808 else
809 show_button "do=Block&$pkg"
810 fi
811 show_button "do=Repack&$pkg"
812 fi
813 i18n_desc $pkg
814 cat << EOT
815 </p>
816 </div>
817 <div class="float-right">
818 $(show_button list)
819 </div>
820 </div>
821 <table class="zebra outbox">
822 <tbody>
823 <tr><td><b>$(_ 'Name')</b></td><td>$PACKAGE</td></tr>
824 <tr><td><b>$(_ 'Version')</b></td><td>$VERSION</td></tr>
825 <tr><td><b>$(_ 'Category')</b></td><td><a href="?cat=$CATEGORY">$CATEGORY</a></td></tr>
826 <tr><td><b>$(_ 'Description')</b></td><td>$SHORT_DESC</td></tr>
827 $([ -n "$MAINTAINER" ] && echo "<tr><td><b>$(_ 'Maintainer')</b></td><td>$MAINTAINER</td></tr>")
828 $([ -n "$LICENSE" ] && echo "<tr><td><b>$(_ 'License')</b></td><td><a href=\"?license=$pkg\">$LICENSE</a></td></tr>")
829 <tr><td><b>$(_ 'Website')</b></td><td><a href="$WEB_SITE">$WEB_SITE</a></td></tr>
830 $(show_info_links "$TAGS" "$(_ 'Tags')" 'tag')
831 <tr><td><b>$(_ 'Sizes')</b></td><td>$PACKED_SIZE/$UNPACKED_SIZE</td></tr>
832 $(show_info_links "$DEPENDS" "$(_ 'Depends')" 'info')
833 $(show_info_links "$SUGGESTED" "$(_ 'Suggested')" 'info')
834 </tbody>
835 </table>
836 EOT
837 DESC="$(tazpkg desc $pkg)"
838 [ -n "$DESC" ] && echo "<pre>$DESC</pre>"
840 if [ -d $INSTALLED/$pkg ]; then
841 cat << EOT
842 <p>$(_ 'Installed files: %s' $(wc -l < $INSTALLED/$pkg/files.list))</p>
844 <pre>$(sort $INSTALLED/$pkg/files.list)</pre>
845 EOT
846 else
847 cat << EOT
848 <p>$(_ 'Installed files: %s' ' ')</p>
850 <pre>
851 $(lzcat files.list.lzma undigest/*/files.list.lzma 2> /dev/null | awk -vp="$pkg:" '$1==p{print $2}' | sort)
852 </pre>
853 EOT
854 fi
855 ;;
858 *\ admin\ * )
859 #
860 # TazPkg configuration page
861 #
862 cmd=$(GET admin)
863 case "$cmd" in
864 clean)
865 rm -rf $CACHE_DIR/* ;;
866 add-mirror)
867 # Decode url
868 mirror=$(GET mirror)
869 case "$mirror" in
870 http://*|ftp://*)
871 echo "$mirror" >> $(GET file) ;;
872 esac ;;
873 rm-mirror=http://*|rm-mirror=ftp://*)
874 mirror=${cmd#rm-mirror=}
875 sed -i -e "s@$mirror@@" -e '/^$/d' $(GET file) ;;
876 select-mirror*)
877 release=$(cat /etc/slitaz-release)
878 mirror="$(GET mirror)packages/$release/"
879 tazpkg setup-mirror $mirror | log
880 ;;
881 add-repo)
882 # Decode url
883 mirror=$(GET mirror)
884 repository=$PKGS_DB/undigest/$(GET repository)
885 case "$mirror" in
886 http://*|ftp://*)
887 mkdir -p $repository
888 echo "$mirror" > $repository/mirror
889 echo "$mirror" > $repository/mirrors ;;
890 esac ;;
891 rm-repo=*)
892 repository=${cmd#rm-repo=}
893 rm -rf $PKGS_DB/undigest/$repository ;;
894 esac
895 [ "$cmd" == "$(_n 'Set link')" ] &&
896 [ -d "$(GET link)/$INSTALLED" ] && ln -fs $(GET link) $PKGS_DB/fslink
897 [ "$cmd" == "$(_n 'Remove link')" ] && rm -f $PKGS_DB/fslink
898 cache_files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
899 cache_size=$(du -sh $CACHE_DIR | cut -f1 | sed 's|\.0||')
900 sidebar
901 cat << EOT
902 <h2>$(_ 'Administration')</h2>
903 <div>
904 <p>$(_ 'TazPkg administration and settings')</p>
905 </div>
906 <div id="actions">
907 $(show_button 'admin=&action=saveconf')
908 $(show_button 'admin=&action=listconf')
909 $(show_button 'admin=&action=quickcheck')
910 $(show_button 'admin=&action=fullcheck')
911 </div>
912 EOT
913 case "$(GET action)" in
914 saveconf)
915 LOADING_MSG=$(_ 'Creating the package...')
916 loading_msg
917 echo "<pre>"
918 cd $HOME
919 tazpkg repack-config | filter_taztools_msgs
920 echo -n "$(_ 'Path:') "; ls $HOME/config-*.tazpkg
921 echo "</pre>" ;;
922 listconf)
923 echo "<h4>$(_ 'Configuration files')</h4>"
924 echo "<ul>"
925 tazpkg list-config | while read file; do
926 if [ -e $file ]; then
927 echo "<li><a href=\"index.cgi?file=$file\">$file</a></li>"
928 else
929 echo "<li>$file</li>"
930 fi
931 done
932 echo "</ul>"
933 ;;
934 quickcheck)
935 LOADING_MSG=$(_ 'Checking packages consistency...')
936 loading_msg
937 echo "<pre>"
938 tazpkg check
939 echo "</pre>" ;;
940 fullcheck)
941 LOADING_MSG=$(_ 'Full packages check...')
942 loading_msg
943 echo "<pre>"
944 tazpkg check --full
945 echo "</pre>" ;;
946 esac
947 cat << EOT
948 <h3>$(_ 'Packages cache')</h3>
950 <div>
951 <form method="get" action="$SCRIPT_NAME">
952 <p>
953 $(_ 'Packages in the cache: %s (%s)' $cache_files $cache_size)
954 <input type="hidden" name="admin" value="clean" />
955 <input type="submit" value="Clean" />
956 </p>
957 </form>
958 </div>
960 <h3>$(_ 'Default mirror')</h3>
962 <pre>$(cat $PKGS_DB/mirror)</pre>
964 <h3>$(_ 'Current mirror list')</h3>
965 EOT
966 for i in $PKGS_DB/mirrors $PKGS_DB/undigest/*/mirrors; do
967 [ -s $i ] || continue
968 echo '<div class="box">'
969 if [ $i != $PKGS_DB/mirrors ]; then
970 Repo_Name="$(repo_name $(dirname $i))"
971 echo "<h4>$(_ 'Repository: %s' $Repo_Name)</h4>"
972 fi
973 echo "<ul>"
974 list_mirrors $i
975 echo "</ul>"
976 cat << EOT
977 </div>
978 <form method="get" action="$SCRIPT_NAME">
979 <p>
980 <input type="hidden" name="admin" value="add-mirror" />
981 <input type="hidden" name="file" value="$i" />
982 <input type="text" name="mirror" size="60">
983 <input type="submit" value="Add mirror" />
984 </p>
985 </form>
986 EOT
987 done
988 echo "<h3>$(_ 'Private repositories')</h3>"
989 [ -n "$(ls $PKGS_DB/undigest 2> /dev/null)" ] && cat << EOT
990 <div class="box">
991 <ul>
992 $(list_repos)
993 </ul>
994 </div>
995 EOT
996 cat << EOT
997 <form method="get" action="$SCRIPT_NAME">
998 <p>
999 <input type="hidden" name="admin" value="add-repo" />
1000 $(_ 'Name') <input type="text" name="repository" size="10">
1001 $(_ 'mirror')
1002 <input type="text" name="mirror" value="http://" size="50">
1003 <input type="submit" value="Add repository" />
1004 </p>
1005 </form>
1007 <h3>$(_ 'Link to another SliTaz installation')</h3>
1009 <p>$(_ "This link points to the root of another SliTaz installation. \
1010 You will be able to install packages using soft links to it.")</p>
1012 <form method="get" action="$SCRIPT_NAME">
1013 <p>
1014 <input type="hidden" name="admin" value="add-link" />
1015 <input type="text" name="link"
1016 value="$(readlink $PKGS_DB/fslink 2> /dev/null)" size="50">
1017 <input type="submit" name="admin" value="$(_ 'Set link')" />
1018 <input type="submit" name="admin" value="$(_ 'Remove link')" />
1019 </p>
1020 </form>
1021 EOT
1022 version=$(cat /etc/slitaz-release)
1023 cat << EOT
1025 <h3 id="dvd">$(_ 'SliTaz packages DVD')</h3>
1027 <p>$(_ "A bootable DVD image of all available packages for the %s version is \
1028 generated every day. It also contains a copy of the website and can be used \
1029 without an internet connection. This image can be installed on a DVD or a USB \
1030 key." $version)</p>
1032 <div>
1033 <form method="post" action='$SCRIPT_NAME?admin&action=dvdimage#dvd'>
1034 <p>
1035 <a class="button"
1036 href='http://mirror.slitaz.org/iso/$version/packages-$version.iso'>
1037 <img src="$IMAGES/tazpkg.png" />$(_ 'Download DVD image')</a>
1038 <a class="button" href='$SCRIPT_NAME?admin&action=dvdusbkey#dvd'>
1039 <img src="$IMAGES/tazpkg.png" />$(_ 'Install from DVD/USB key')</a>
1040 </p>
1041 <div class="box">
1042 $(_ 'Install from ISO image:')
1043 <input type="text" name="dvdimage" size="40" value="/root/packages-$version.iso">
1044 </div>
1045 </form>
1046 </div>
1047 EOT
1048 if [ "$(GET action)" == "dvdimage" ]; then
1049 dev=$(POST dvdimage)
1050 mkdir -p /mnt/packages 2> /dev/null
1051 echo "<pre>"
1052 mount -t iso9660 -o loop,ro $dev /mnt/packages &&
1053 /mnt/packages/install.sh &&
1054 _ '%s is installed on /mnt/packages' $dev
1055 echo "</pre>"
1056 fi
1057 if [ "$(GET action)" == "dvdusbkey" ]; then
1058 mkdir -p /mnt/packages 2> /dev/null
1059 for tag in "LABEL=\"packages-$version\" TYPE=\"iso9660\"" \
1060 "LABEL=\"sources-$version\" TYPE=\"iso9660\"" ; do
1061 dev=$(blkid | grep "$tag" | cut -d: -f1)
1062 [ -n "$dev" ] || continue
1063 echo "<pre>"
1064 mount -t iso9660 -o ro $dev /mnt/packages &&
1065 /mnt/packages/install.sh &&
1066 _ '%s is installed on /mnt/packages' $dev
1067 echo "</pre>"
1068 break
1069 done
1070 fi
1071 ;;
1074 *\ license\ *)
1076 # Show licenses for installed packages
1078 search_form
1079 sidebar
1080 pkg=$(GET license)
1081 case $pkg in
1082 /*)
1083 [ -e $pkg ] && {
1084 echo "<h2>${pkg#/usr/share/licenses/}</h2>"
1085 case $pkg in
1086 *.htm*)
1087 cat $pkg ;;
1088 *)
1089 echo "<pre style=\"white-space: pre-wrap\">"
1090 cat $pkg | htmlize | sed 's|\([hf]t*t*ps*://[a-zA-Z0-9./_-]*[a-zA-Z0-9/_-]\)|<a href="\1">\1</a>|'
1091 echo "</pre>"
1092 ;;
1093 esac
1094 } ;;
1095 *)
1096 echo "<h2>$(_ 'Licenses for package %s' $pkg)</h2>"
1097 ONLINE=''; OFFLINE=''
1099 if [ -e "$PKGS_DB/installed/$pkg" ]; then
1100 for license in $(. $PKGS_DB/installed/$pkg/receipt; echo "$LICENSE"); do
1101 OSL=''; GNU=''; USR=''; LIC=''
1102 case $license in
1103 Apache) OSL='Apache-2.0'; URL='http://www.apache.org/licenses/' ;;
1104 Artistic) OSL='Artistic-2.0' ;;
1105 BSD) OSL='BSD-2-Clause' ;;
1106 BSD3) OSL='BSD-3-Clause' ;;
1108 CC-BY-SA*|CC-SA*) CCO='by-sa/4.0/' ;;
1109 CC-BY-ND*) CCO='by-nd/4.0/' ;;
1110 CC-BY-NC-SA*) CCO='by-nc-sa/4.0/' ;;
1111 CC-BY-NC-ND*) CCO='by-nc-nd/4.0/' ;;
1112 CC-BY-NC*) CCO='by-nc/4.0/' ;;
1113 CC-BY*) CCO='by/4.0/' ;;
1115 cc-pd) URL='http://creativecommons.org/publicdomain/' ;;
1116 CCPL) ;;
1117 CDDL*) OSL='CDDL-1.0' ;;
1118 CECILL*) OSL='CECILL-2.1' ;;
1119 Eclipse|EPL*) OSL='EPL-1.0' ;;
1120 FDL) GNU='fdl' ;;
1121 GPL) GNU='gpl'; OSL='gpl-license'; LIC='gpl.txt' ;;
1122 GPL2) GNU='old-licenses/gpl-2.0'; OSL='GPL-2.0' ;;
1123 GPL3) GNU='gpl'; OSL='GPL-3.0'; LIC='gpl.txt' ;;
1124 ISC) OSL='ISC' ;;
1125 LGPL) GNU='lgpl'; OSL='lgpl-license' ;;
1126 LGPL2) GNU='old-licenses/lgpl-2.0' ;;
1127 LGPL2.1) GNU='old-licenses/lgpl-2.1'; OSL='LGPL-2.1'; LIC='lgpl.txt' ;;
1128 LGPL3) GNU='lgpl'; OSL='LGPL-3.0' ;;
1129 LPPL*) OSL='LPPL-1.3c' ;;
1130 MIT) OSL='MIT'; LIC='mit.txt' ;;
1131 MPL) OSL='MPL-2.0'; LIC='mozilla.txt' ;;
1132 MPL2) OSL='MPL-2.0' ;;
1133 FL) OSL='Fair' ;; # ?
1134 PSL) ;;
1135 PublicDomain) ;;
1136 QPL*) OSL='QPL-1.0' ;;
1137 SIL_OFL*) OSL='OFL-1.1' ;;
1138 zlib/libpng) OSL='Zlib' ;;
1139 esac
1141 [ -n "$OSL" ] && ONLINE="$ONLINE <li><a href=\"http://opensource.org/licenses/$OSL\">$(_ '%s license on %s website' "<b>$OSL</b>" "OSL")</a></li>\n"
1142 [ -n "$GNU" ] && ONLINE="$ONLINE <li><a href=\"https://www.gnu.org/licenses/$GNU.html\">$(_ '%s license on %s website' "<b>${GNU#*/}</b>" "GNU")</a></li>\n"
1143 [ -n "$CCO" ] && ONLINE="$ONLINE <li><a href=\"http://creativecommons.org/licenses/$CCO\">$(_ '%s license on %s website' "<b>${CCO%%/*}</b>" "Creative Commons")</a></li>\n"
1144 [ -n "$URL" ] && ONLINE="$ONLINE <li><a href=\"$URL\">$URL</a></li>\n"
1145 [ -n "$LIC" ] && OFFLINE="$OFFLINE <li><a href=\"?license=/usr/share/licenses/$LIC\">licenses/<b>$LIC</b></a></li>\n"
1146 done
1148 for lic in $(grep /usr/share/licenses/ $PKGS_DB/installed/$pkg/files.list); do
1149 OFFLINE="$OFFLINE <li><a href=\"?license=$lic\">licenses/<b>${lic#/usr/share/licenses/}</b></a></li>\n"
1150 done
1151 fi
1152 [ -n "$ONLINE" ] && echo -e "<p>$(_ 'Read online:')</p>\n<ul>\n$ONLINE</ul>\n"
1153 [ -n "$OFFLINE" ] && echo -e "<p>$(_ 'Read local:')</p>\n<ul>\n$OFFLINE</ul>\n"
1154 ;;
1155 esac
1156 ;;
1159 *\ tag\ *)
1161 # Show packages with matching tag; show tag cloud
1163 search_form
1164 sidebar
1165 tag=$(GET tag)
1166 if [ -n "$tag" ]; then
1167 echo "<h2>$(_ 'Tag "%s"' $tag)</h2>"
1168 echo '<table class="zebra outbox pkglist">'
1169 table_head
1170 echo '<tbody>'
1171 awk -F$'\t' '$6 ~ /(^| )'$tag'( |$)/{
1172 printf "<tr><td><input type=\"checkbox\" name=\"pkg\" value=\"%s\"><a class=\"pkg%s%s\" href=\"?info=%s\">%s</a></td><td>%s</td><td>%s</td><td><a href=\"%s\"></a></td></tr>\n", $1, INS, BLK, gensub(/\+/, "%2B", "g", $1), $1, $2, $4, $5
1173 }' $PKGS_DB/packages.info
1174 echo "</tbody></table>"
1175 else
1176 echo "<h2>$(_ 'Tags list')</h2>"
1177 echo "<p>"
1178 awk -F$'\t' '{if($6){print $6}}' $PKGS_DB/packages.info | tr ' ' $'\n' | sort -u | sed 's|.*|<a href="?tag=&">&</a> |'
1179 echo "</p>"
1180 fi
1181 ;;
1184 *)
1186 # Default to summary
1188 search_form
1189 sidebar
1190 [ -n "$(GET block)" ] && tazpkg block $(GET block)
1191 [ -n "$(GET unblock)" ] && tazpkg unblock $(GET unblock)
1192 cat << EOT
1193 <h2>$(_ 'Summary')</h2>
1195 <div id="actions">
1196 $(show_button list)
1197 EOT
1198 fslink=$(readlink $PKGS_DB/fslink)
1199 [ -n "$fslink" -a -d "$fslink/$INSTALLED" ] && show_button linkable
1200 show_button recharge
1201 show_button up
1202 show_button admin
1203 cat << EOT
1204 </div>
1206 $(packages_summary)
1209 <h3>$(_ 'Latest log entries')</h3>
1211 <pre>
1212 $(tail -n 5 $LOG | fgrep "-" | awk '{print $1, $2, $3, $4, $5, $6, $7}')
1213 </pre>
1214 EOT
1215 ;;
1216 esac
1218 # xHTML 5 footer
1219 export TEXTDOMAIN='tazpkg'
1220 xhtml_footer
1221 exit 0