tazpkg view tazpanel/pkgs.cgi @ rev 811

Update documentation (attempt to describe all the commands both with all options). Strongly need to review and update translations and docs! Add TazPkg help system for commandline (based on the HTML docs). Attempt to drop all package lists but "packages.info". Small improvements and code prettify.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jun 04 00:15:13 2015 +0300 (2015-06-04)
parents 6ac7d1bf450b
children 92ae73ca4a4a
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-2015 SliTaz GNU/Linux - BSD License
10 #
12 . lib/libtazpanel
14 . /etc/slitaz/slitaz.conf
15 . /etc/slitaz/tazpkg.conf
17 export TEXTDOMAIN='tazpkg'
19 get_config
21 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
22 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
23 _p() {
24 local S="$1" P="$2" N="$3"; shift 3;
25 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
28 #------
29 # menu
30 #------
32 case "$1" in
33 menu)
34 TEXTDOMAIN_original=$TEXTDOMAIN
35 export TEXTDOMAIN='tazpkg'
37 cat <<EOT
38 <li tabindex="0">
39 <span>$(gettext 'Packages')</span>
40 <menu>
41 <li><a data-icon="info" href="pkgs.cgi">$(gettext 'Summary')</a></li>
42 <li><a data-icon="list" href="pkgs.cgi?list&amp;my=my&amp;cat=all&amp;repo=Any">$(gettext 'My packages')</a></li>
43 <li><a data-icon="refresh" href="pkgs.cgi?recharge" data-root>$(gettext 'Recharge list')</a></li>
44 <li><a data-icon="upgrade" href="pkgs.cgi?up" data-root>$(gettext 'Check updates')</a></li>
45 <li><a data-icon="admin" href="pkgs.cgi?admin" data-root>$(gettext 'Administration')</a></li>
46 </menu>
47 </li>
48 EOT
49 export TEXTDOMAIN=$TEXTDOMAIN_original
50 exit
51 esac
55 #
56 # AJAX commands
57 #
59 case " $(GET) " in
62 *\ filelist\ * )
63 # Show installed files list
64 pkg=$(GET pkg)
65 cd $PKGS_DB
67 header
68 if [ -d $INSTALLED/$pkg ]; then
69 files="$(wc -l < $INSTALLED/$pkg/files.list)"
70 cat <<EOT
71 <pre class="scroll">$(sort $INSTALLED/$pkg/files.list)</pre>
72 <footer>$(_p '%s file' '%s files' $files $files)</footer>
73 EOT
74 else
75 cat <<EOT
76 <pre class="scroll">$(lzcat files.list.lzma undigest/*/files.list.lzma \
77 2>/dev/null | awk -vp="$pkg:" '$1==p{print $2}' | sort)</pre>
78 EOT
79 fi
80 exit 0 ;;
83 *\ status\ * )
84 # Show package status
85 pkg=$(GET pkg)
86 class='pkg'
88 if grep -q "^$pkg"$'\t' $PKGS_DB/installed.info; then
89 class='pkgi'
90 grep -q "^$pkg$" $PKGS_DB/blocked-packages.list && class='pkgib'
91 fi
93 header
94 echo -n "<a data-icon=\"$class\" href=\"?info=${pkg//+/%2B}\">$pkg</a>"
95 exit 0 ;;
98 *\ app_img\ * )
99 # Show application image
100 pkg=$(GET app_img)
102 # check for icons defined with packages.icons file
103 if [ -f "$PKGS_DB/packages.icons" ]; then
104 predefined_icon="$(awk -F$'\t' -vpkg="$pkg" '{if ($1 == pkg) print $2}' $PKGS_DB/packages.icons)"
105 fi
106 predefined_icon="${predefined_icon:-package-x-generic}.png"
108 current_user="$(who | cut -d' ' -f1)"
109 if [ -n "$current_user" ]; then
110 current_user_home="$(awk -F: -vu=$current_user '{if($1==u) print $6}' /etc/passwd)"
111 current_icon_theme="$(grep gtk-icon-theme-name $current_user_home/.gtkrc-2.0 | cut -d'"' -f2)"
112 fi
113 current_icon_theme="/usr/share/icons/$current_icon_theme"
115 # Preferred default icon is 48px package-x-generic
116 default_pkg_icon="$(find -L $current_icon_theme -type f -path '*48*' -name $predefined_icon | head -n1)"
117 # ... or package-x-generic with the bigger size
118 if [ -z "$default_pkg_icon" ]; then
119 default_pkg_icon="$(find -L $current_icon_theme -type f -name $predefined_icon | sort | tail -n1)"
120 fi
122 # Preferred package icon size is 48px
123 pkg_icon="$(find -L $current_icon_theme -type f -path '*48*' -name "$pkg.png" | head -n1)"
124 # ... or just bigger one
125 if [ -z "$pkg_icon" ]; then
126 pkg_icon="$(find -L $current_icon_theme -type f -name "$pkg.png" | sort | tail -n1)"
127 fi
128 # ... or one from pixmaps
129 if [ -z "$pkg_icon" ]; then
130 pkg_icon="$(find -L /usr/share/pixmaps -type f -name "$pkg.png" | head -n1)"
131 fi
133 header "Content-Type: image/png"
134 cat "${pkg_icon:-$default_pkg_icon}"
135 exit 0 ;;
138 *\ show_receipt\ * )
139 # Show package receipt
140 pkg=$(GET show_receipt)
141 if [ -d "$INSTALLED/$pkg" ]; then
142 # Redirects to the receipt view
143 header "HTTP/1.1 301 Moved Permanently" "Location: index.cgi?file=$INSTALLED/$pkg/receipt"
144 exit 0
145 else
146 temp_receipt=$(mktemp -d)
147 wget -O $temp_receipt/receipt -T 5 http://hg.slitaz.org/wok/raw-file/tip/$pkg/receipt
148 if [ -e "$temp_receipt" ]; then
149 # Redirects to the receipt view
150 header "HTTP/1.1 301 Moved Permanently" "Location: index.cgi?file=$temp_receipt/receipt"
151 exit 0
152 else
153 header; xhtml_header
154 msg err "$(_ 'Receipt for package %s unavailable' $pkg)"
155 xhtml_footer
156 exit 0
157 fi
158 fi
159 ;;
161 esac
164 header
167 # xHTML 5 header with special side bar for categories.
168 TITLE=$(TEXTDOMAIN='tazpkg'; _ 'TazPanel - Packages')
169 xhtml_header | sed 's/id="content"/id="content-sidebar"/'
172 pkg_info_link() {
173 echo "<a data-icon=\"$2\" href=\"?info=${1//+/%2B}\">$1</a>" | sed 's| data-icon=""||'
174 }
177 # Display localized short description
179 i18n_desc() {
180 for L in $LANG ${LANG%%_*}; do
181 if [ -e "$PKGS_DB/packages-desc.$L" ]; then
182 LOCDESC=$(awk -F$'\t' -vp=$1 '{if ($1 == p) print $2}' $PKGS_DB/packages-desc.$L)
183 if [ -n "$LOCDESC" ]; then
184 SHORT_DESC="$LOCDESC"
185 break
186 fi
187 fi
188 done
189 }
192 # We need packages information for list and search
194 parse_packages_desc() {
195 IFS="|"
196 cut -f 1,2,3 -d "|" | while read PACKAGE VERSION SHORT_DESC
197 do
198 class=pkg; [ -d $INSTALLED/${PACKAGE% } ] && class=pkgi
199 i18n_desc $PACKAGE
200 cat <<EOT
201 <tr>
202 <td><input type="checkbox" name="pkg" value="$PACKAGE">$(pkg_info_link $PACKAGE $class)</td>
203 <td>$VERSION</td>
204 <td>$SHORT_DESC</td>
205 </tr>
206 EOT
207 done
208 unset IFS
209 }
212 parse_packages_info() {
213 IFS=$'\t'
214 while read PACKAGE VERSION CATEGORY SHORT_DESC WEB_SITE TAGS SIZES DEPENDS; do
215 class='pkg'
216 if grep -q "^$PACKAGE"$'\t' $PKGS_DB/installed.info; then
217 class='pkgi'
218 grep -q "^$PACKAGE$" $PKGS_DB/blocked-packages.list && class='pkgib'
219 fi
220 i18n_desc $PACKAGE
221 cat <<EOT
222 <tr>
223 <td><input type="checkbox" name="pkg" value="$PACKAGE">$(pkg_info_link $PACKAGE $class)</td>
224 <td>$VERSION</td>
225 <td>$SHORT_DESC</td>
226 </tr>
227 EOT
228 done
229 unset IFS
230 }
233 # Show button
234 show_button() {
235 for button in $@; do
236 class=''; misc=''
237 case $button in
238 recharge) class='refresh'; label="$(_ 'Recharge list')"; misc=' data-root' ;;
239 up) class='upgrade'; label="$(_ 'Check upgrades')"; misc=' data-root' ;;
240 list) class='list'; label="$(_ 'My packages')" ;;
241 tags) class='tags'; label="$(_ 'Tags')" ;;
242 linkable) class='link'; label="$(_ 'Linkable packages')" ;;
243 admin) class='admin'; label="$(_ 'Administration')"; misc=' data-root' ;;
244 *Install*nf*) class='install'; label="$(_ 'Install (Non Free)')" ;;
245 *Install*) class='install'; label="$(_ 'Install')" ;;
246 *Remove*) class='remove'; label="$(_ 'Remove')" ;;
247 *Link*) class='link'; label="$(_ 'Link')" ;;
248 *Block*) class='lock'; label="$(_ 'Block')" ;;
249 *Unblock*) class='unlock'; label="$(_ 'Unblock')" ;;
250 *Chblock*) class='chlock'; label="$(_ '(Un)block')" ;;
251 *Repack*) class='repack'; label="$(_ 'Repack')" ;;
252 *saveconf*) class='save'; label="$(_ 'Save configuration')" ;;
253 *listconf*) class='list'; label="$(_ 'List configuration files')" ;;
254 *quickcheck*) class='check'; label="$(_ 'Quick check')" ;;
255 *fullcheck*) class='check'; label="$(_ 'Full check')" ;;
256 *clean*) class='remove'; label="$(_ 'Clean')" ;;
257 *setlink*) class='link'; label="$(_ 'Set link')" ;;
258 *removelink*) class='unlink'; label="$(_ 'Remove link')" ;;
259 *add-mirror) class='add'; label="$(_n 'Add mirror')" ;;
260 *add-repo) class='add'; label="$(_n 'Add repository')" ;;
261 toggle) class='toggle'; label="$(_n 'Toggle all')" ;;
262 esac
263 if [ "$button" == 'toggle' ]; then
264 echo -n "<span class=\"float-right\"><button data-icon=\"$class\" onclick=\"checkBoxes()\">$label</button></span>"
265 else
266 echo -n "<button data-icon=\"$class\" name=\"${button%%=*}\" value=\"${button#*=}\"$misc>$label</button>"
267 fi
268 done
269 }
273 #
274 # xHTML functions
275 #
278 # ENTER will search but user may search for a button, so put one.
280 search_form() {
281 cat <<EOT
282 <form class="search"><!--
283 --><a data-icon="web" href="http://pkg.slitaz.org/" target="_blank" title="$(_n 'Web search tool')"></a> <!--
284 --><input type="search" name="search" results="5" autosave="pkgsearch" autocomplete="on"><!--
285 --><button type="submit">$(_n 'Search')</button><!--
286 --><button name="files" value="yes">$(_n 'Files')</button><!--
287 --></form>
288 EOT
289 }
292 table_head() {
293 cat <<EOT
294 <table class="wide zebra pkglist" id="head1">
295 <thead id="head2">
296 <tr>
297 <td>$(_ 'Name')</td>
298 <td>$(_ 'Version')</td>
299 <td>$(_ 'Description')</td>
300 </tr>
301 </thead>
302 <tbody>
303 EOT
304 }
307 sidebar() {
308 repo=$(COOKIE repo); repo=${repo:-Public}; [ -n "$(GET repo)" ] && repo=$(GET repo)
309 my=$(COOKIE my); my=${my:-my}; [ -n "$(GET my)" ] && my=$(GET my)
310 cat=$(COOKIE cat); cat=${cat:-all}; [ -n "$(GET cat)" ] && cat=$(GET cat)
312 cat <<EOT
313 <script type="text/javascript">
314 function setCookie(name) {
315 if (name=='cat') {
316 var cats = document.getElementsByName('cat');
317 for (var i = 0; i < cats.length; i++) {
318 if (cats[i].checked) {
319 document.cookie = name + "=" + cats[i].value;
320 break;
321 }
322 }
323 } else {
324 document.cookie = name+"="+document.getElementById(name).value;
325 }
326 }
327 function setValue(name, value) {
328 document.getElementById(name).value=value;
329 setCookie(name);
330 }
331 </script>
332 <form method="post" action="?list" style="position: absolute">
334 <div id="sidebar">
335 <select id="my" value="$my" onchange="setCookie('my'); this.form.submit()">
336 <option value="my">$(_ 'My packages')</option>
337 <option value="no">$(_ 'All packages')</option>
338 </select>
339 <script type="text/javascript">setValue('my', "$my")</script>
341 <h4>$(_ 'Categories')</h4>
343 <div class="wide zebra">
344 $(echo 'base-system x-window utilities network games graphics office
345 multimedia development system-tools security misc meta non-free all
346 extra' | tr ' ' '\n' | awk -vcat="$cat" -vn="1" '{
347 system("gettext " $1 | getline tr)
348 printf "<input type=\"radio\" name=\"cat\" id=\"c%s\" ", n
349 printf "value=\"%s\"%s ", $1, $1==cat?" checked":""
350 printf "onclick=\"setCookie(&#39;cat&#39;); this.form.submit()\">"
351 printf "<label for=\"c%s\">%s</label>\n", n, tr
352 n++
353 }')
354 </div>
355 EOT
356 #reminder; gettext 'all'; gettext 'extra'
358 if [ -d $PKGS_DB/undigest ]; then
359 cat <<EOT
360 <h4>$(_ 'Repository')</h4>
362 <select id="repo" onchange="setCookie('repo')">
363 <option value="Public">$(_ 'Public')</option>
364 $(for i in $(ls $PKGS_DB/undigest); do
365 echo "<option value=\"$i\">$i</option>"
366 done)
367 <option value="Any">$(_ 'Any')</option>
368 </select>
369 <script type="text/javascript">setValue('repo', "$repo")</script>
370 EOT
371 fi
372 cat <<EOT
373 <a data-icon="tags" href="?tags">$(_ 'All tags...')</a><br/>
374 <a data-icon="list" href="?cats">$(_ 'All categories...')</a>
375 </div>
376 </form>
377 EOT
378 }
381 repo_list() {
382 if [ -n "$(ls $PKGS_DB/undigest/ 2> /dev/null)" ]; then
383 case "$repo" in
384 Public)
385 ;;
386 ""|Any)
387 for i in $PKGS_DB/undigest/* ; do
388 [ -d "$i" ] && echo "$i$1"
389 done ;;
390 *)
391 echo "$PKGS_DB/undigest/$repo$1"
392 return ;;
393 esac
394 fi
395 echo "$PKGS_DB$1"
396 }
399 repo_name() {
400 case "$1" in
401 $PKGS_DB)
402 echo "Public" ;;
403 $PKGS_DB/undigest/*)
404 echo ${1#$PKGS_DB/undigest/} ;;
405 esac
406 }
409 header_repo_name() {
410 [ -d $PKGS_DB/undigest ] && [ "$repo" != "Public" ] && \
411 _ 'Repository: %s' $(repo_name $1)
412 }
415 # Print links to the pages
417 pager() {
418 PAGE_SIZE=${PAGE_SIZE:-100}
419 [ "$PAGE_SIZE" != "0" ] && \
420 awk -F'"' -vpage="$page" -vsize="$PAGE_SIZE" -vnum_lines="$(wc -l < $1)" -vtext="$(_ 'Pages:') " -vurl="?list&amp;page=" '
421 BEGIN{
422 num_pages = int(num_lines / size) + (num_lines % size != 0)
423 if (num_pages != 1) printf "<p>%s", text
424 }
425 {
426 if (num_pages == 1) exit
427 r = NR % size
428 if (r == 1) {
429 p = int(NR / size) + 1
430 printf "<button class=\"pages%s\" name=\"page\" value=\"%s\" title=\"%s\n···\n", p==page?" current":"", p, $6
431 } else if (r == 0)
432 printf "%s\">%s</button> ", $6, int(NR / size)
433 }
434 END{
435 if (num_pages == 1) exit
436 if (r != 0) printf "%s\">%s</button>", $6, int(NR / size) + 1
437 print "</p>"
438 }' $1
439 }
442 # Show packages list by category or tag
444 show_list() {
445 PAGE_SIZE=${PAGE_SIZE:-100}
446 page=$(GET page); page=${page:-1}
447 cached=$(mktemp)
448 [ -n "$tag" ] && cat=''
449 {
450 for L in $LANG ${LANG%%_*}; do
451 if [ -e "$PKGS_DB/packages-desc.$L" ]; then
452 sed '/^#/d' $PKGS_DB/packages-desc.$L; break
453 fi
454 done
455 [ -e "$i/blocked-packages.list" ] && cat $i/blocked-packages.list
456 sed 's|.*|&\ti|' $i/installed.info
457 [ "$cat" == 'extra' ] || [ $1 == 'my' ] || cat $i/packages.info
458 [ "$cat" == 'extra' ] &&
459 sed 's,\([^|]*\)|\([^|]*\)|\([^|]*\)|\([^|]*\)|\([^|]*\).*,\1\t\5\textra\t\2\thttp://mirror.slitaz.org/packages/get/\1\t-\t-\t-,' $PKGS_DB/extra.list
460 } | sort -t$'\t' -k1,1 | sed '/^$/d' | awk -F$'\t' -vc="${cat:--}" -vt="${tag:--}" '
461 {
462 if (PKG && PKG != $1) {
463 if (SEL) {
464 if (DSCL) DSC = DSCL
465 printf "<tr><td><input type=\"checkbox\" name=\"pkg\" value=\"%s\" id=\"%s\">", PKG, PKG
466 printf "<a data-icon=\"pkg%s%s\" href=\"?info=%s\">%s</a></td>", INS, BLK, gensub(/\+/, "%2B", "g", PKG), PKG
467 printf "<td>%s</td><td>%s</td><td><a href=\"%s\"></a></td></tr>\n", VER, DSC, WEB
468 }
469 VER = DSC = WEB = DSCL = INS = BLK = SEL = ""
470 }
472 PKG = $1
473 if (NF == 1) { BLK = "b"; next }
474 if (NF == 2) { DSCL = $2; next }
475 if (c == "all" || $3 == c || index(" "$6" ", " "t" ")) { SEL = 1 }
476 if (SEL) {
477 if ($9 == "i") { VER = $2; DSC = $4; WEB = $5; INS = "i"; next}
478 if (! INS) { VER = $2; DSC = $4; WEB = $5 }
479 }
480 }' > $cached
482 pager="$(pager $cached)"
483 case $PAGE_SIZE in
484 0) list="$(cat $cached)";;
485 *) list="$(tail -n+$((($page-1)*$PAGE_SIZE+1)) $cached | head -n$PAGE_SIZE)";;
486 esac
488 if [ "$pager" != "<p>$(_ 'Pages:') </p>" ] && [ -n "${list:1:1}" ]; then
489 cat <<EOT
490 <h3>$(header_repo_name $i)</h3>
491 $pager
492 $(table_head)
493 $list
494 </tbody></table>
495 $pager
496 EOT
497 fi
498 rm -f $cached
501 ### Re-select packages when you return to the page
503 # Find the packages list
504 pkgs=$(echo "$QUERY_STRING&" | awk 'BEGIN{RS="&";FS="="}
505 {if ($1=="pkg") printf "\"%s\", ", $2}')
506 pkgs=$(httpd -d "${pkgs%, }")
507 # now pkgs='"pkg1", "pkg2", ... "pkgn"'
509 if [ -n "$pkgs" ]; then
510 cat <<EOT
511 <script type="text/javascript">
512 var pkgs = [$pkgs];
513 var theForm = document.getElementById('pkglist');
514 for (index = 0; index < pkgs.length; index++) {
515 if (document.getElementById(pkgs[index])) {
516 // check existing
517 document.getElementById(pkgs[index]).checked = 'true';
518 }
519 else {
520 // add other as hidden
521 var hInput = document.createElement('input');
522 hInput.type = 'hidden';
523 hInput.name = 'pkg';
524 hInput.value = pkgs[index];
525 theForm.appendChild(hInput);
526 }
527 }
528 document.getElementById('countSelected').innerText = pkgs.length;
529 </script>
530 EOT
531 fi
532 }
535 # Show links for "info" page
537 show_info_links() {
538 if [ -n "$1" ]; then
539 if [ "$3" == 'tag' ]; then icon='tag'; else icon='clock'; fi
540 echo -n "<tr><td><b>$2</b></td><td>"
541 echo $1 | tr ' ' $'\n' | awk -vt="$3" -vi="$icon" '{
542 printf "<span><a data-icon=\"%s\" ", i;
543 printf "href=\"?%s=%s\">%s</a></span>   ", t, gensub(/\+/, "%2B", "g", $1), $1
544 }'
545 echo "</td></tr>"
546 fi
547 }
551 #
552 # Commands
553 #
556 case " $(GET) " in
559 *\ linkable\ *)
560 #
561 # List linkable packages.
562 #
563 search_form; sidebar
564 loading_msg "$(_ 'Listing linkable packages...')"
566 cat <<EOT
567 <h2>$(_ 'Linkable packages')</h2>
569 <form class="wide">
570 $(_ 'Selection:') $(show_button do=Link)
571 EOT
572 table_head
573 target=$(readlink $PKGS_DB/fslink)
574 for pkg in $(ls $target/$INSTALLED); do
575 [ -s $pkg/receipt ] && continue
576 . $target/$INSTALLED/$pkg/receipt
577 i18n_desc $pkg
578 cat <<EOT
579 <tr>
580 <td><input type="checkbox" name="pkg" value="$pkg" /><a data-icon="pkg" href="?info=${pkg//+/%2B}">$pkg</a></td>
581 <td>$VERSION</td>
582 <td>$SHORT_DESC</td>
583 <td><a data-img="web" href="$WEB_SITE"></a></td>
584 </tr>
585 EOT
586 done
587 cat <<EOT
588 </tbody>
589 </table>
590 </form>
591 EOT
592 ;;
595 *\ cats\ *)
596 #
597 # List of all categories.
598 #
599 search_form; sidebar
601 echo "<h2>$(_ 'Categories list')</h2>"
603 for pkgsinfo in $(repo_list /packages.info); do
604 cat <<EOT
605 <section>
606 <header>$(header_repo_name $(dirname $pkgsinfo))</header>
607 <table class="wide zebra center">
608 <thead>
609 <tr>
610 <td>$(_ 'Category')</td>
611 <td>$(_ 'Available packages')</td>
612 <td>$(_ 'Installed packages')</td>
613 </tr>
614 </thead>
615 <tbody>
616 EOT
617 {
618 awk -F$'\t' '{print $3}' $pkgsinfo | sort | uniq -c
619 awk -F$'\t' '{print $3}' $PKGS_DB/installed.info | sed 's|.*|& i|' | sort | uniq -c
620 } | sort -k2,2 | awk '
621 {
622 c [$2] = "."
623 if ($3) { i[$2] = $1; } else { m[$2] = $1; }
624 }
625 END {
626 for (n in c) print n, m[n], i[n]
627 }' | sort | awk '{
628 printf "<tr><td><a href=\"?list&amp;cat=%s\">%s</a></td><td>%d</td><td>%d</td></tr>", $1, $1, $2, $3
629 }'
630 cat <<EOT
631 </tbody>
632 </table>
633 </section>
634 EOT
635 done
636 ;;
639 *\ list\ *|*\ page\ *)
640 #
641 # List all packages by category.
642 #
643 search_form; sidebar
644 loading_msg "$(_ 'Listing packages...')"
646 bcat="<b>$cat</b>"; brepo="<b>$repo</b>"
647 case $repo in
648 Any)
649 case $my in
650 my) title="$(_ 'Installed packages of category "%s"' "$bcat")" ;;
651 *) title="$(_ 'All packages of category "%s"' "$bcat")" ;;
652 esac ;;
653 *)
654 case $my in
655 my) title="$(_ 'Installed packages of category "%s" in repository "%s"' "$bcat" "$brepo")" ;;
656 *) title="$(_ 'All packages of category "%s" in repository "%s"' "$bcat" "$brepo")" ;;
657 esac ;;
658 esac
660 cat <<EOT
661 <h2>$(_ 'Packages list')</h2>
662 <p>$title</p>
664 EOT
666 [ ! -f $PKGS_DB/packages.info ] && msg warn \
667 "$(_ 'You can not view a list of all packages until recharging lists.')"
669 [ "$REMOTE_USER" == "root" ] && cat <<EOT
670 <section>
671 <div>$(_ 'Selected packages:') <span id="countSelected"></span></div>
672 <footer>
673 $({
674 [ "$my" != 'my' ] && show_button do=Install
675 show_button do=Chblock do=Remove
676 } | sed 's|button |button form="pkglist" |g')
677 $(show_button toggle)
678 </footer>
679 </section>
680 EOT
681 cat <<EOT
683 <form id="pkglist" class="wide">
684 EOT
685 for i in $(repo_list ""); do
686 show_list ${my#no}
687 done
688 cat <<EOT
689 </form>
690 <script type="text/javascript">window.onscroll = scrollHandler; setCountSelPkgs();</script>
691 EOT
692 ;;
695 *\ search\ *)
696 #
697 # Search for packages. Here default is to search in packages.desc
698 # and so get result including packages names and descriptions
699 #
700 pkg=$(GET search); [ -z "$pkg" ] && xhtml_footer && exit
701 cd $PKGS_DB
703 search_form | sed "s|name=\"search\"|& value=\"$pkg\"|"
704 sidebar
705 loading_msg "$(_ 'Searching packages...')"
707 cat <<EOT
708 <h2>$(_ 'Search packages')</h2>
710 <section>
711 <div>$(_ 'Selected packages:') <span id="countSelected"></span></div>
712 <footer>
713 $(show_button do=Install do=Chblock do=Remove | sed 's|button |button form="pkglist" |g')
714 $(show_button toggle)
715 </footer>
716 </section>
718 <form id="pkglist" class="wide">
719 EOT
720 if [ -n "$(GET files)" -o -n "$(echo $pkg | grep '/')" ]; then
721 cat <<EOT
722 <table class="wide zebra filelist">
723 <thead>
724 <tr>
725 <td>$(_ 'Package')</td>
726 <td>$(_ 'File')</td>
727 </tr>
728 <thead>
729 <tbody>
730 EOT
731 lzcat $(repo_list /files.list.lzma) | grep -Ei ": .*$(GET search)" | \
732 while read PACKAGE FILE; do
733 PACKAGE=${PACKAGE%:}
734 class='pkg'
735 if [ -d $INSTALLED/$PACKAGE ]; then
736 class='pkgi'
737 grep -q "^$PACKAGE$" $PKGS_DB/blocked-packages.list && class='pkgib'
738 fi
739 cat <<EOT
740 <tr>
741 <td><input type="checkbox" name="pkg" value="$PACKAGE">$(pkg_info_link $PACKAGE $class)</td>
742 <td>$(echo "$FILE" | sed "s|$pkg|<span class=\"diff-add\">&</span>|gI")</td>
743 </tr>
744 EOT
745 done
746 else
747 table_head
748 awk -F$'\t' 'BEGIN{IGNORECASE = 1}
749 $1 " " $4 ~ /'$pkg'/{print $0}' $(repo_list /packages.info) | parse_packages_info
750 fi
751 cat <<EOT
752 </tbody>
753 </table>
754 </form>
755 <script type="text/javascript">window.onscroll = scrollHandler; setCountSelPkgs();</script>
756 EOT
757 ;;
760 *\ recharge\ *)
761 #
762 # Lets recharge the packages list
763 #
764 search_form; sidebar
765 loading_msg "$(_ 'Recharging lists...')"
767 cat <<EOT
768 <h2>$(_ 'Recharge')</h2>
769 <p>$(_ 'Recharge checks for new or updated packages')</p>
771 <section>
772 <header>
773 <span data-icon="sync">$(_ 'Recharging log')</span>
774 <form>$(show_button up)</form>
775 </header>
776 EOT
777 echo $(_ 'Recharging packages list') | log
778 export output="html"; tazpkg recharge
779 cat <<EOT
780 <footer>$(_ 'Packages lists are up-to-date. You should check for upgrades now.')</footer>
781 </section>
782 EOT
783 ;;
786 *\ up\ *)
787 #
788 # Upgrade packages
789 #
790 search_form; sidebar
791 loading_msg "$(_ 'Checking for upgrades...')"
793 cat <<EOT
794 <h2>$(_ 'Up packages')</h2>
796 <section>
797 <div>$(_ 'Selected packages:') <span id="countSelected"></span></div>
798 <footer>
799 $(show_button do=Install do=Chblock do=Remove | sed 's|button |button form="pkglist" |g')
800 $(show_button toggle)
801 </footer>
802 </section>
804 <form id="pkglist" class="wide">
805 EOT
806 # Ask tazpkg to make "packages.up" file
807 tazpkg up --check >/dev/null
808 table_head
810 for pkg in $(cat $PKGS_DB/packages.up); do
811 grep -hs "^$pkg " $PKGS_DB/packages.info $PKGS_DB/undigest/*/packages.info | parse_packages_info
812 done
814 cat <<EOT
815 </tbody>
816 </table>
817 </form>
818 <script type="text/javascript">window.onscroll = scrollHandler; setCountSelPkgs();</script>
819 EOT
820 ;;
823 *\ do\ *)
824 #
825 # Do an action on one or some packages
826 #
827 search_form; sidebar
828 loading_msg
830 # Find the command
831 cmd=$(echo $(GET do) | tr [:upper:] [:lower:])
833 # Find the packages list
834 pkgs=$(echo $QUERY_STRING | awk 'BEGIN{RS="&";FS="="}{if($1=="pkg")print $2}')
835 pkgs=$(httpd -d "$pkgs")
837 # Describe the command
838 bpkgs="<b>$pkgs</b>"; opt=''
839 case $cmd in
840 install) MSG="$(_ 'Installing: %s' "$bpkgs")"; opt='--forced'; cmd='get-install' ;;
841 remove) MSG="$(_ 'Removing: %s' "$bpkgs")" ;;
842 link) MSG="$(_ 'Linking: %s' "$bpkgs")"; opt="$(readlink $PKGS_DB/fslink)" ;;
843 block) MSG="$(_ 'Blocking: %s' "$bpkgs")" ;;
844 unblock) MSG="$(_ 'Unblocking: %s' "$bpkgs")" ;;
845 chblock) MSG="$(_ '(Un)blocking: %s' "$bpkgs")" ;;
846 repack) MSG="$(_ 'Repacking: %s' "$bpkgs")" ;;
847 esac
849 cat <<EOT
850 <h2>TazPkg: $(GET do)</h2>
852 <div>$MSG</div>
853 EOT
854 # Do the command for all asked packages
855 cd /tmp
856 export output='html'
858 for pkg in $pkgs; do
859 #echo $(_n 'y') |
860 tazpkg $cmd $pkg $opt 2>/dev/null | filter_taztools_msgs
861 done
862 ;;
865 *\ info\ *)
866 #
867 # Packages info
868 #
869 pkg=$(GET info)
870 search_form; sidebar
871 loading_msg "$(_ 'Getting package info...')"
873 cat <<EOT
874 <section>
875 <header>
876 $(_ 'Package %s' $pkg)
877 <form>
878 <input type="hidden" name="pkg" value="${pkg#get-}"/>
879 EOT
881 # Get receipt variables, show Install/Remove buttons
882 if [ -d $INSTALLED/$pkg ]; then
883 . $INSTALLED/$pkg/receipt
884 files=$(wc -l < $INSTALLED/$pkg/files.list)
885 [ "$REMOTE_USER" == "root" ] &&
886 show_button do=Remove
887 else
888 cd $PKGS_DB
889 eval "$(awk -F$'\t' -vp=$pkg '
890 $1==p{
891 printf "PACKAGE=\"%s\"; VERSION=\"%s\"; CATEGORY=\"%s\"; ", $1, $2, $3
892 printf "SHORT_DESC=\"%s\"; WEB_SITE=\"%s\"; TAGS=\"%s\"; ", $4, $5, $6
893 printf "SIZES=\"%s\"; DEPENDS=\"%s\"", $7, $8
894 }' packages.info undigest/*/packages.info)"
895 if [ -z "$PACKAGE" ]; then
896 eval "$(awk -F'|' -vp=$pkg '
897 $1==p{
898 printf "PACKAGE=\"%s\"; SHORT_DESC=\"%s\"; WEB_SITE=\"%s\"; ", $1, $2, $3
899 printf "CATEGORY=\"%s\"; VERSION=\"%s\"; LICENSE=\"%s\"; ", $4, $5, $6
900 }' extra.list undigest/*/extra.list)"
901 [ "$CATEGORY" ] || CATEGORY="non-free"
902 fi
903 PACKED_SIZE=${SIZES% *}
904 UNPACKED_SIZE=${SIZES#* }
905 [ "$REMOTE_USER" == "root" ] &&
906 if [ "${pkg#get-}" != "$pkg" ]; then
907 show_button "do=Install&amp;nf"
908 else
909 show_button do=Install
910 fi
911 fi
913 # Show Block/Unblock, and Repack buttons
914 [ "$REMOTE_USER" == "root" ] &&
915 if [ -d $INSTALLED/$pkg ]; then
916 if grep -qs "^$pkg$" $PKGS_DB/blocked-packages.list; then
917 show_button do=Unblock
918 else
919 show_button do=Block
920 fi
921 show_button do=Repack
922 fi
924 # Translate short description
925 i18n_desc $pkg
927 # Show info table
928 cat <<EOT
929 </form>
930 </header>
932 <table class="wide summary">
933 <tr><td id="appImg"><img src="pkgs.cgi?app_img=$PACKAGE"/></td><td>
934 <table class="wide zebra summary" id="infoTable">
935 <tbody>
936 <tr><td><b>$(_ 'Name')</b></td><td>$PACKAGE</td></tr>
937 <tr><td><b>$(_ 'Version')</b></td><td>$VERSION</td></tr>
938 <tr><td><b>$(_ 'Category')</b></td><td><a href="?list&amp;cat=$CATEGORY">$CATEGORY</a></td></tr>
939 <tr><td><b>$(_ 'Description')</b></td><td>$SHORT_DESC</td></tr>
940 $([ -n "$MAINTAINER" ] && echo "<tr><td><b>$(_ 'Maintainer')</b></td><td>$MAINTAINER</td></tr>")
941 $([ -n "$LICENSE" ] && echo "<tr><td><b>$(_ 'License')</b></td><td><a href=\"?license=$pkg\">$LICENSE</a></td></tr>")
942 <tr><td><b>$(_ 'Website')</b></td><td><a href="$WEB_SITE" target="_blank">$WEB_SITE</a></td></tr>
943 $(show_info_links "$TAGS" "$(_ 'Tags')" 'tag')
944 <tr><td><b>$(_ 'Sizes')</b></td><td>${PACKED_SIZE/.0/}/${UNPACKED_SIZE/.0/}</td></tr>
945 $(show_info_links "$DEPENDS" "$(_ 'Depends')" 'info')
946 $(show_info_links "$SUGGESTED" "$(_ 'Suggested')" 'info')
947 </tbody>
948 </table>
949 </td></tr></table>
951 <footer>
952 <a data-icon="text" href="?show_receipt=$pkg">$(_ 'View receipt')</a>
953 <a data-icon="slitaz" href="?improve=$pkg">$(_ 'Improve package')</a>
954 </footer>
955 </section>
956 <span id="ajaxStatus" style="display:none"></span>
958 <script type="text/javascript">
959 var links = document.getElementById('infoTable').getElementsByTagName('a');
960 for (var i = 0; i < links.length; i++) {
961 console.log('i=%s, icon=%s.', i, links[i].dataset.icon);
962 if (links[i].dataset.icon == 'clock') {
963 links[i].parentNode.id = 'link' + i;
964 pkg = links[i].innerText.replace(/\+/g, '%2B');
965 ajax('pkgs.cgi?status&pkg=' + pkg, '1', 'link' + i);
966 }
967 }
969 </script>
970 EOT
972 # Show description
973 DESC="$(tazpkg desc $pkg)"
974 [ -n "$DESC" ] && echo "<section><pre class="pre-wrap">$DESC</pre></section>"
976 # Show configuration files list
977 CONFIGS="$(tazpkg list-config $pkg | sed 's|\(.*\)|\1 \1|')"
978 [ -n "$CONFIGS" ] && cat <<EOT
979 <section>
980 <header>$(_ 'Configuration files')</header>
981 <pre>$(printf '<a href="index.cgi?file=%s">%s</a>\n' $CONFIGS)</pre>
982 </section>
983 EOT
985 # Show installed files list
986 pkg=${pkg//+/%2B}
987 cat <<EOT
988 <section>
989 <header>$(_ 'Installed files')</header>
990 <span id="fileList">
991 <div style="text-align: center;"><span id="ajaxStatus"></span>$(_ 'Please wait')</div>
992 </span>
993 </section>
994 <script type="text/javascript">ajax('pkgs.cgi?filelist&pkg=$pkg', '1', 'fileList');</script>
995 EOT
996 ;;
999 *\ admin\ * )
1001 # TazPkg configuration page
1003 cmd=$(GET admin)
1004 pager="$(GET pager)"; pager=${pager:-$PAGE_SIZE}; pager=${pager:-100}
1005 mirror="$(GET mirror)"; mirror="${mirror%/}/"
1006 repository="$PKGS_DB/undigest/$(GET repository)"
1007 link="$(GET link)"; link=${link%/}
1008 search_form; sidebar
1009 loading_msg
1011 case "$cmd" in
1012 clean)
1013 rm -rf $CACHE_DIR/* ;;
1014 add-mirror)
1015 echo "$mirror" >> $(GET file) ;;
1016 rm-mirror)
1017 sed -i "/^"$(echo $mirror | sed 's|/|\\/|g')"$/d" $(GET file) ;;
1018 select-mirror)
1019 tazpkg setup-mirror "${mirror}packages/$(cat /etc/slitaz-release)/" | log ;;
1020 add-repo)
1021 mkdir -p $repository
1022 echo "$mirror" > $repository/mirror
1023 echo "$mirror" > $repository/mirrors ;;
1024 rm-repo)
1025 rm -rf $repository ;;
1026 setlink)
1027 [ -d "$link/$INSTALLED" ] && ln -fs $link $PKGS_DB/fslink ;;
1028 removelink)
1029 rm -f $PKGS_DB/fslink ;;
1030 pager)
1031 TP_CONF=/etc/slitaz/tazpanel.conf
1032 if [ -z "$PAGE_SIZE" ]; then
1033 echo -e "\n# Size of packages list page\nPAGE_SIZE=\"$pager\"" >> $TP_CONF
1034 else
1035 sed -i "s|PAGE_SIZE=.*|PAGE_SIZE=\"$pager\"|" $TP_CONF
1036 fi ;;
1037 esac
1039 cat <<EOT
1040 <h2>$(_ 'Administration')</h2>
1042 <p>$(_ 'TazPkg administration and settings')</p>
1044 <form id="actions">
1045 <input type="hidden" name="admin"/>
1046 $(show_button action=saveconf action=listconf action=quickcheck action=fullcheck)
1047 </form>
1048 EOT
1049 case "$(GET action)" in
1050 saveconf)
1051 loading_msg "$(_ 'Creating the package...')"
1052 echo "<pre>"
1053 cd /tmp
1054 tazpkg repack-config | filter_taztools_msgs
1055 echo -n "$(_ 'Path:') "; ls /tmp/config-*.tazpkg
1056 echo "</pre>" ;;
1057 listconf)
1058 echo "<h4>$(_ 'Configuration files')</h4>"
1059 echo "<ul>"
1060 tazpkg list-config | while read file; do
1061 if [ -e $file ]; then
1062 echo "<li><a href=\"index.cgi?file=$file\">$file</a></li>"
1063 else
1064 echo "<li>$file</li>"
1065 fi
1066 done
1067 echo "</ul>" ;;
1068 quickcheck)
1069 loading_msg "$(_ 'Checking packages consistency...')"
1070 tazpkg check
1071 ;;
1072 fullcheck)
1073 loading_msg "$(_ 'Full packages check...')"
1074 tazpkg check --full
1075 ;;
1076 dvdimage)
1077 dev=$(POST dvdimage)
1078 mkdir -p /mnt/packages 2> /dev/null
1079 echo "<pre>"
1080 mount -t iso9660 -o loop,ro $dev /mnt/packages &&
1081 /mnt/packages/install.sh &&
1082 _ '%s is installed on /mnt/packages' $dev
1083 echo "</pre>" ;;
1084 dvdusbkey)
1085 mkdir -p /mnt/packages 2> /dev/null
1086 for tag in "LABEL=\"packages-$version\" TYPE=\"iso9660\"" \
1087 "LABEL=\"sources-$version\" TYPE=\"iso9660\"" ; do
1088 dev=$(blkid | grep "$tag" | cut -d: -f1)
1089 [ -n "$dev" ] || continue
1090 echo "<pre>"
1091 mount -t iso9660 -o ro $dev /mnt/packages &&
1092 /mnt/packages/install.sh &&
1093 _ '%s is installed on /mnt/packages' $dev
1094 echo "</pre>"
1095 break
1096 done ;;
1097 esac
1099 cache_files=$(find $CACHE_DIR -name '*.tazpkg' | wc -l)
1100 cache_size=$(du -sh $CACHE_DIR | cut -f1 | sed 's|\.0||')
1101 [ "$cache_files" == 0 ] && cache_size="0K"
1102 mirror=$(cat $PKGS_DB/mirror)
1103 default_mirror=${mirror%/packages/*}
1104 cat <<EOT
1105 <section>
1106 <header>$(_ 'Packages cache')</header>
1107 <form class="wide">
1108 <div>$(_ 'Packages in the cache: %s (%s)' $cache_files $cache_size)</div>
1109 <footer>$(show_button admin=clean)</footer>
1110 </form>
1111 </section>
1114 <section>
1115 <header>$(_ 'Current mirror list')</header>
1116 EOT
1118 # List mirrors
1119 version=$(cat /etc/slitaz-release)
1120 for i in $PKGS_DB/mirrors $PKGS_DB/undigest/*/mirrors; do
1121 [ -s $i ] || continue
1122 if [ $i != $PKGS_DB/mirrors ]; then
1123 echo "<h4>$(_ 'Repository: %s' "$(repo_name $(dirname $i))")</h4>"
1124 fi
1125 cat <<EOT
1126 <form class="wide">
1127 <input type="hidden" name="admin" value="select-mirror"/>
1128 <table class="wide zebra">
1129 EOT
1130 while read line; do
1131 cat <<EOT
1132 <tr>
1133 <td>
1134 <input type="radio" name="mirror" id="$line" value="$line" onchange="this.form.submit()"
1135 $([ "$line" == "$default_mirror/" ] && echo -n 'checked="checked"')>
1136 <label for="$line"><code>$line</code></label></td>
1137 <td><a data-img="web" href="$line" target="_blank"></a></td>
1138 <td><a data-img="remove" href="?admin=rm-mirror&amp;mirror=$line&amp;file=$i" title="$(_ 'Delete')"></a></td>
1139 </tr>
1140 EOT
1141 done < $i
1142 cat <<EOT
1143 </table>
1144 </form>
1146 <form class="wide">
1147 <footer>
1148 <input type="hidden" name="file" value="$i" />
1149 <input type="text" name="mirror" size="40" />
1150 $(show_button admin=add-mirror)
1151 </footer>
1152 </form>
1153 EOT
1154 done
1155 cat <<EOT
1156 </section>
1159 <section>
1160 <header>$(_ 'Private repositories')</header>
1161 EOT
1162 if [ -n "$(ls $PKGS_DB/undigest 2> /dev/null)" ]; then
1163 cat <<EOT
1164 <table class="wide zebra">
1165 EOT
1166 ls $PKGS_DB/undigest 2> /dev/null | while read repo ; do
1167 cat <<EOT
1168 <tr>
1169 <td><code>$repo</code></td>
1170 <td><a data-img="remove" href="?admin=rm-repo&amp;repository=$repo" title="$(_ 'Delete')"></a></td>
1171 </tr>
1172 EOT
1173 done
1174 cat <<EOT
1175 </table>
1176 EOT
1177 fi
1179 cat <<EOT
1180 <form class="wide">
1181 <table>
1182 <tr><td>$(_ 'Name')</td><td><input type="text" name="repository" size="10"/></td></tr>
1183 <tr><td>$(_ 'URL:')</td><td><input type="text" name="mirror" value="http://"></td></tr>
1184 </table>
1185 <footer>
1186 $(show_button admin=add-repo)
1187 </footer>
1188 </form>
1189 </section>
1192 <section>
1193 <header>$(_ 'Link to another SliTaz installation')</header>
1194 <form class="wide">
1195 <div>
1196 $(_ "This link points to the root of another SliTaz installation. You will be able to install packages using soft links to it.")
1197 </div>
1198 <input type="text" name="link" value="$(readlink $PKGS_DB/fslink 2> /dev/null)"/>
1199 <footer>
1200 $(show_button admin=setlink admin=removelink)
1201 </footer>
1202 </form>
1203 </section>
1206 <section>
1207 <header id="dvd">$(_ 'SliTaz packages DVD')</header>
1209 <div>
1210 $(_ "A bootable DVD image of all available packages for the %s version is generated every day. It also contains a copy of the website and can be used without an internet connection. This image can be installed on a DVD or a USB key." $version)
1212 <form method="post" action='?admin&amp;action=dvdimage'>
1213 $(_ 'Install from ISO image:')
1214 <input type="text" name="dvdimage" size="40" value="/root/packages-$version.iso" />
1215 </form>
1216 </div>
1218 <footer>
1219 <button data-icon="download" onclick='http://mirror.slitaz.org/iso/$version/packages-$version.iso'>
1220 $(_ 'Download DVD image')</button>
1221 <button data-icon="link" onclick='?admin&amp;action=dvdusbkey'>
1222 $(_ 'Install from DVD/USB key')</button>
1223 </footer>
1224 </section>
1227 <section>
1228 <header>$(_ 'Packages list')</header>
1229 <form class="wide">
1230 <div>
1231 $(_ 'Long list of packages is paginated. Here you can set the page size (default: 100, turning off the pager: 0).')
1232 </div>
1233 <input type="hidden" name="admin" value="pager"/>
1234 <input type="number" name="pager" value="$pager" min="0" step="10" size="4"/>
1235 <footer>
1236 <button data-icon="ok" type="submit">$(_ 'Set')</button>
1237 </footer>
1238 </form>
1239 </section>
1240 EOT
1241 ;;
1244 *\ license\ *)
1246 # Show licenses for installed packages
1248 search_form; sidebar
1250 pkg=$(GET license)
1251 case $pkg in
1252 /*) [ -e $pkg ] && {
1253 echo "<h2>${pkg#/usr/share/licenses/}</h2>"
1254 case $pkg in
1255 *.htm*) cat $pkg ;;
1256 *) echo "<pre style=\"white-space: pre-wrap\">"
1257 cat $pkg | htmlize | sed 's|\([hf]t*t*ps*://[a-zA-Z0-9./_-]*[a-zA-Z0-9/_-]\)|<a href="\1">\1</a>|'
1258 echo "</pre>"
1259 ;;
1260 esac
1261 } ;;
1262 *) echo "<h2>$(_ 'Licenses for package %s' $pkg)</h2>"
1263 OFFLINE=''
1264 if [ -e "$PKGS_DB/installed/$pkg" ]; then
1265 for lic in $(grep /usr/share/licenses/ $PKGS_DB/installed/$pkg/files.list); do
1266 OFFLINE="$OFFLINE <li><a href=\"?license=$lic\">licenses/<b>${lic#/usr/share/licenses/}</b></a></li>\n"
1267 done
1268 echo "\
1269 Apache|Apache-2.0||||http://www.apache.org/licenses/#Artistic|Artistic-2.0||||#\
1270 BSD|BSD-2-Clause||||#BSD3|BSD-3-Clause||||#CC-BY-SA||by-sa/4.0/|||#\
1271 CC-SA||by-sa/4.0/|||#CC-BY-ND||by-nd/4.0/|||#CC-BY-NC-SA||by-nc-sa/4.0/|||#\
1272 CC-BY-NC-ND||by-nc-nd/4.0/|||#CC-BY-NC||by-nc/4.0/|||#CC-BY||by/4.0/|||#\
1273 cc-pd|||||http://creativecommons.org/publicdomain/#CDDL|CDDL-1.0||||#\
1274 CECILL|CECILL-2.1||||#Eclipse|EPL-1.0||||#EPL|EPL-1.0||||#FDL|||fdl||#\
1275 GPL|gpl-license||gpl|gpl.txt|#GPL2|GPL-2.0||old-licenses/gpl-2.0||#\
1276 GPL3|GPL-3.0||gpl|gpl.txt|#ISC|ISC||||#LGPL|lgpl-license||lgpl||#\
1277 LGPL2|||old-licenses/lgpl-2.0||#\
1278 LGPL2.1|LGPL-2.1||old-licenses/lgpl-2.1|lgpl.txt|#LGPL3|LGPL-3.0||lgpl||#\
1279 LPPL|LPPL-1.3c||||#MIT|MIT|||mit.txt|#MPL|MPL-2.0|||mozilla.txt|#\
1280 MPL2|MPL-2.0||||#PublicDomain|||||http://creativecommons.org/publicdomain/#\
1281 QPL|QPL-1.0||||#SIL_OFL|OFL-1.1||||#OFL|OFL-1.1||||#zlib/libpng|Zlib||||" | \
1282 awk -vlicenses="$(. $PKGS_DB/installed/$pkg/receipt; echo "$LICENSE")" \
1283 -vtext="$(_ '%s license on %s website' %s %s)" \
1284 -vro="$(_ 'Read online:')" -vrl="$(_ 'Read local:')" \
1285 -vofflic="$OFFLINE" '
1286 BEGIN{ FS="|"; RS="#"; split(licenses, lic, " "); if (offlic) OFFLINE[0]=offlic }
1287 function link1(u, l, ll, w) {
1288 return sprintf("\t<li><a href=\"%s%s\">" text "</a></li>", u, l, "<b>" ll "</b>", w) }
1289 function link2(u, l, ll) {
1290 return sprintf("\t<li><a href=\"%s%s\">%s</b></a></li>", u, l, ll) }
1291 function link_osl(n) {
1292 return link1("http://opensource.org/licenses/", n, n, "OSL") }
1293 function link_cc(n) {
1294 split(n, ll, "/")
1295 return link1("http://creativecommons.org/licenses/", n, ll[1], "Creative Commons") }
1296 function link_gnu(n) {
1297 split(n, ll, "/")
1298 return link1("https://www.gnu.org/licenses/", n ".html", ll[2] ? ll[2] : ll[1], "GNU") }
1299 function link_loc(n) {
1300 return link2("?license=/usr/share/licenses/", n, "licenses/<b>" n "</b>") }
1301 function link_url(n) {
1302 return link2(n, "", n) }
1304 if ($1 == lic[1] || $1 == lic[2] || $1 == lic[3] || $1 == lic[4]) {
1305 if ($2) ONLINE[$2]=link_osl($2)
1306 if ($3) ONLINE[$3]=link_cc($3)
1307 if ($4) ONLINE[$4]=link_gnu($4)
1308 if ($5) OFFLINE[$5]=link_loc($5)
1309 if ($6) OFFLINE[$6]=link_url($6)
1312 END{
1313 if (length(ONLINE) > 0) { print "<p>" ro "</p>\n<ul>"; for (o in ONLINE) print ONLINE[o]; print "</ul>" }
1314 if (length(OFFLINE) > 0) { print "<p>" rl "</p>\n<ul>"; for (o in OFFLINE) print OFFLINE[o]; print "</ul>" }
1315 }'
1316 fi ;;
1317 esac
1318 ;;
1321 *\ tags\ *)
1323 # Show tag cloud
1325 search_form; sidebar
1327 echo "<h2>$(_ 'Tags list')</h2>"
1328 brepo="<b>$repo</b>"
1329 case $repo in
1330 Any) title="$(_ 'List of tags in all repositories')" ;;
1331 *) title="$(_ 'List of tags in repository "%s"' "$brepo")" ;;
1332 esac
1333 echo "<p>$title</p><p id=\"tags\">"
1334 to_read=""
1335 for i in $(repo_list ""); do
1336 if [ ! -e $i/packages.info ]; then
1337 list=installed
1338 else
1339 list=packages
1340 fi
1341 to_read="$to_read $i/$list.info"
1342 done
1343 TAGS="$(awk -F$'\t' '{if($6){print $6}}' $to_read | tr ' ' $'\n' | sort | uniq -c)"
1344 MAX="$(echo "$TAGS" | awk '{if ($1 > MAX) MAX = $1} END{print MAX}')"
1345 echo "$TAGS" | awk -vMAX="$MAX" '{
1346 printf "<a class=\"tag%s\" href=\"?tag=%s\" title=\"%s\">%s</a> ", int($1 * 7 / MAX + 1), $2, $1, $2
1347 }'
1348 echo "</p>"
1349 ;;
1352 *\ tag\ *)
1354 # Show packages with matching tag
1356 search_form; sidebar
1358 tag=$(GET tag)
1359 cat <<EOT
1360 <h2 data-icon="tag">$(_ 'Tag "%s"' $tag)</h2>
1361 EOT
1362 [ "$REMOTE_USER" == "root" ] && cat <<EOT
1363 <section>
1364 <div>$(_ 'Selected packages:') <span id="countSelected"></span></div>
1365 <footer>
1366 $(show_button do=Install do=Chblock do=Remove | sed 's|button |button form="pkglist" |g')
1367 $(show_button toggle)
1368 </footer>
1369 </section>
1370 EOT
1371 cat <<EOT
1372 <form id="pkglist" class="wide">
1373 EOT
1374 for i in $(repo_list ""); do
1375 show_list all
1376 done
1377 cat <<EOT
1378 </form>
1379 <script type="text/javascript">window.onscroll = scrollHandler; setCountSelPkgs();</script>
1380 EOT
1381 ;;
1384 *\ blocked\ *)
1386 # Show blocked packages list
1388 search_form; sidebar
1390 cat <<EOT
1391 <h2>$(_ 'Blocked packages list')</h2>
1393 <section>
1394 <div>$(_ 'Selected packages:') <span id="countSelected"></span></div>
1395 <footer>
1396 $(show_button do=Unblock | sed 's|button |button form="pkglist" |g')
1397 $(show_button toggle)
1398 </footer>
1399 </section>
1401 <form id="pkglist" class="wide">
1402 EOT
1403 table_head
1404 for i in $(cat $PKGS_DB/blocked-packages.list); do
1405 awk -F$'\t' -vp="$i" '{
1406 if ($1 == p)
1407 printf "<tr><td><input type=\"checkbox\" name=\"pkg\" value=\"%s\"><a data-icon=\"pkgib\" href=\"?info=%s\">%s</a></td><td>%s</td><td>%s</td><td><a href=\"%s\"></a></td></tr>\n", $1, gensub(/\+/, "%2B", "g", $1), $1, $2, $4, $5
1408 }' $PKGS_DB/installed.info
1409 done
1410 cat <<EOT
1411 </tbody>
1412 </table>
1413 </form>
1414 <script type="text/javascript">window.onscroll = scrollHandler; setCountSelPkgs();</script>
1415 EOT
1416 ;;
1419 *\ improve\ *)
1421 # Improving packages by the community effort
1423 search_form; sidebar
1424 msg warn 'Under construction!<br/>It is only imitation of working'
1426 pkg=$(GET improve)
1427 user=$(POST user); type=$(POST type); text="$(POST text)"
1428 login=$(POST login); password=$(POST password)
1430 login_c=$(COOKIE login); password_c=$(COOKIE password)
1431 mail_hash=$(COOKIE mail_hash); user_name=$(COOKIE user_name)
1433 n=$'\n'
1435 if [ -n "$login" ]; then
1436 # Get mail hash and user Name from bugs.slitaz.org
1437 page="$(busybox wget --post-data "auth=${login}&pass=${password}&id=" \
1438 -O- "http://bugs.slitaz.org/bugs.cgi?user=${login}")"
1439 # Parse page and get:
1440 mail_hash="$(echo "$page" | fgrep '<h2>' | cut -d/ -f5 | cut -c 1-32)"
1441 user_name="$(echo "$page" | fgrep '<h2>' | cut -d'>' -f3 | cut -d'<' -f1)"
1443 # Put variables to the session Cookies (they clean in browser close)
1444 cat <<EOT
1445 <script type="text/javascript">
1446 document.cookie = "login=$login";
1447 document.cookie = "password=$password";
1448 document.cookie = "mail_hash=$mail_hash";
1449 document.cookie = "user_name=$user_name";
1450 </script>
1451 EOT
1452 login_c="$login"; password_c="$password"
1453 fi
1455 if [ -z "$login_c" ]; then
1456 cat <<EOT
1457 <section>
1458 <div>$(_ 'Please log in using your TazBug account.')</div>
1459 <form method="post">
1460 <input type="hidden" name="improve" value="$pkg"/>
1461 <table>
1462 <tr><td>$(_ 'Login:')</td>
1463 <td><input type="text" name="login"/></td></tr>
1464 <tr><td>$(_ 'Password:')</td>
1465 <td><input type="password" name="password"/></td></tr>
1466 <tr><td colspan="2">
1467 <button type="submit" data-icon="user">$(_ 'Log in')</button></td></tr>
1468 </table>
1469 </form>
1470 <footer>
1471 <a href="http://bugs.slitaz.org/bugs.cgi?signup&online" target="_blank">$(_ 'Create new account')</a>
1472 </footer>
1473 </section>
1474 EOT
1475 xhtml_footer; exit 0
1476 fi
1479 # Get receipt variables, show Install/Remove buttons
1480 if [ -d $INSTALLED/$pkg ]; then
1481 . $INSTALLED/$pkg/receipt
1482 else
1483 cd $PKGS_DB
1484 eval "$(awk -F$'\t' -vp=$pkg '
1485 $1==p{
1486 printf "VERSION=\"%s\"; SHORT_DESC=\"%s\"; TAGS=\"%s\"; ", $2, $4, $6
1487 }' packages.info undigest/*/packages.info)"
1488 fi
1490 RECEIPT="$(wget -O - http://hg.slitaz.org/wok/raw-file/tip/$pkg/receipt | htmlize)"
1491 DESCRIPTION="$(wget -O - http://hg.slitaz.org/wok/raw-file/tip/$pkg/description.txt | htmlize)"
1492 DESCRIPTION="$(separator)$n${DESCRIPTION:-(empty)}$n$(separator)"
1494 if [ -z "$type" ]; then
1495 cat <<EOT
1496 <section>
1497 <header>
1498 $(_ 'Improve package "%s"' $pkg)
1499 <form><button name="info" value="$pkg" data-icon="back">$(_ 'Back')</button></form>
1500 </header>
1502 <div style="display:none">
1503 <span id="newVersion">Current version: $VERSION${n}New version: $VERSION${n}Link to announce: http://</span>
1504 <span id="improveShortDesc">Short description (English):$n$SHORT_DESC</span>
1505 <span id="translateShortDesc">Short description (English):$n$SHORT_DESC$n${n}Language: $LANG${n}Short description:$n$SHORT_DESC</span>
1506 <span id="improveDesc">Description (English):$n$DESCRIPTION</span>
1507 <span id="translateDesc">Language: $LANG${n}Description:$n$DESCRIPTION</span>
1508 <span id="improveCategory">Old category: $CATEGORY${n}New category: $CATEGORY</span>
1509 <span id="improveTags">Tags: $TAGS</span>
1510 <span id="addIcon">Link to application icon (48x48px): http://</span>
1511 <span id="addScreenshot">Link to application screenshot: http://</span>
1512 <span id="improveReceipt">$RECEIPT</span>
1513 <span id="improveOther"></span>
1514 </div>
1516 <form method="post" class="wide">
1518 <table class="wide">
1519 <tr><td style="vertical-align:bottom">
1520 <input type="hidden" name="improve" value="$pkg"/>
1521 <input type="hidden" name="user" value="$login_c"/>
1522 &nbsp;$(_ 'How can you help:')<br/>
1523 <select name='type' id="improveType" onchange="improveAction()">
1524 <option value=''>$(_ 'Please select an action')
1525 <option value='newVersion'>$(_ 'Report new version')
1526 <option value='improveShortDesc'>$(_ 'Improve short description')
1527 <option value='translateShortDesc'>$(_ 'Translate short description')
1528 <option value='improveDesc'>$(_ 'Add or improve description')
1529 <option value='translateDesc'>$(_ 'Translate description')
1530 <option value='improveCategory'>$(_ 'Improve category')
1531 <option value='improveTags'>$(_ 'Add or improve tags')
1532 <option value='addIcon'>$(_ 'Add application icon')
1533 <option value='addScreenshot'>$(_ 'Add application screenshot')
1534 <option value='improveReceipt'>$(_ 'Improve receipt')
1535 <option value='improveOther'>$(_ 'Other')
1536 </select>
1537 </td>
1538 <td id="user_info">$user_name
1539 <img src="http://www.gravatar.com/avatar/$mail_hash?s=48&amp;d=identicon"
1540 style="border-radius: 0.3rem"/>
1541 </td></tr>
1542 </table>
1544 <textarea name="text" id="improveText" style="width:100%; resize: vertical; min-height:10rem"></textarea>
1545 <button type="submit" data-icon="slitaz">$(_ 'Send')</button>
1546 </form>
1547 </section>
1548 EOT
1549 else
1550 cat <<EOT
1551 <section>
1552 <header>
1553 $(_ 'Thank you!')
1554 <form><button name="info" value="$pkg" data-icon="back">$(_ 'Back')</button></form>
1555 </header>
1556 <div>The following information was sent to SliTaz developers:</div>
1557 <pre class="scroll"><b>User:</b> $user
1558 <b>Type:</b> $type
1559 <b>Package:</b> $pkg
1560 <b>Message:</b>
1561 $(echo "$text" | htmlize)</pre>
1562 </section>
1563 EOT
1564 fi
1565 ;;
1568 *)
1570 # Default to summary
1572 search_form; sidebar; loading_msg
1574 cat <<EOT
1575 <form>
1576 EOT
1577 fslink=$(readlink $PKGS_DB/fslink)
1578 [ -n "$fslink" -a -d "$fslink/$INSTALLED" ] && show_button linkable
1579 show_button recharge up admin
1580 cat <<EOT
1581 </form>
1583 <section>
1584 <header>$(_ 'Summary')</header>
1586 <table class="wide zebra">
1587 <tr>
1588 <td>$(_ 'Last recharge:')</td>
1589 <td>$(list=$PKGS_DB/ID
1590 if [ -e $list ]; then
1591 # Timezone offset as string, ex. '+0200' for EET (+2 hours)
1592 ohhmm="$(date +%z)"
1593 # Timezone offset in the seconds
1594 offset=$(( 60 * (60 * ${ohhmm:0:3} + ${ohhmm:3:2}) ))
1595 daynow=$(( ($(date +%s) + $offset) / 86400 ))
1596 dayupd=$(( ($(date -r $list +%s) + $offset) / 86400 ))
1597 days=$(( $daynow - $dayupd ))
1598 time=$(date -r $list +%R)
1599 ago="$(_p '%d day ago.' '%d days ago.' $days $days)"
1600 case $days in
1601 0) _ 'Today at %s.' $time;;
1602 1) _ 'Yesterday at %s.' $time;;
1603 [2-9]) echo $ago;;
1604 *) echo "<span style='color:red'>$ago</span>"
1605 _ 'It is recommended to [recharge] the lists.' | \
1606 sed 's|\[|<a data-icon="refresh" href="?recharge">|;s|\]|</a>|';;
1607 esac
1608 else
1609 _ 'never.'
1610 _ 'You need to [download] the lists for further work.' | \
1611 sed 's|\[|<a data-icon="download" href="?recharge" data-root>|;s|\]|</a>|'
1612 fi)</td></tr>
1613 <tr>
1614 <td>$(_ 'Installed packages:')</td>
1615 <td><a href="?list&amp;my=my&amp;cat=all&amp;repo=Any">
1616 <b>$(cat $PKGS_DB/installed.info | wc -l)</b>
1617 </a></td></tr>
1618 <tr>
1619 <td>$(_ 'Mirrored packages:')</td>
1620 <td><a href="?list&amp;my=no&amp;cat=all&amp;repo=Any">
1621 <b>$(cat $PKGS_DB/packages.list | wc -l)</b>
1622 </a></td></tr>
1623 <tr>
1624 <td>$(_ 'Upgradeable packages:')</td>
1625 <td><a href="?up">
1626 <b>$(cat $PKGS_DB/packages.up | wc -l)</b>
1627 </a></td></tr>
1628 <tr>
1629 <td>$(_ 'Installed files:')</td>
1630 <td><b>$(cat $INSTALLED/*/files.list | wc -l)</b></td></tr>
1631 <tr>
1632 <td>$(_ 'Blocked packages:')</td>
1633 <td><a href="?blocked">
1634 <b>$(cat $PKGS_DB/blocked-packages.list | wc -l)</b>
1635 </a></td></tr>
1636 </table>
1637 </section>
1640 <section>
1641 <header>
1642 $(_ 'Latest log entries')
1643 <form action="index.cgi">
1644 <button name="file" value="$LOG" data-icon="view">$(_ 'Show')</button>
1645 </form>
1646 </header>
1647 <pre>$(tail -n 5 $LOG | tac | fgrep "-" | awk '{print $1, $2, $3, $4, $5, "<a href=\"?info=" $6 "\">" $6 "</a>", $7}')</pre>
1648 </section>
1649 EOT
1650 ;;
1651 esac
1653 # xHTML 5 footer
1654 export TEXTDOMAIN='tazpkg'
1655 xhtml_footer
1656 exit 0