tazpkg view tazpkg @ rev 499

tazpkg: small fix to clean-up
author Christophe Lincoln <pankso@slitaz.org>
date Thu Jun 02 02:58:52 2011 +0200 (2011-06-02)
parents 1ff567e9ef8b
children 59604130cb72
line source
1 #!/bin/sh
2 # Tazpkg - Tiny autonomous zone packages manager.
3 #
4 # This is a lightwight packages manager for *.tazpkg files written in
5 # SHell script. It works well with Busybox ash shell and bash. Tazpkg lets you
6 # list, install, remove, download or get information about a package. You can
7 # use 'tazpkg usage' to get a list of commands with short descriptions. Tazpkg
8 # also resolves dependencies and can upgrade packages from a mirror. I18n is
9 # done using gettext and eval_gettext, ex:
10 # gettext "displayed text"; echo
11 # eval_gettext "display \$VARIABLE"; echo
12 # echo -e "BOLD `gettext \"i18n message\"`"
13 #
14 # (C) 2007-2011 SliTaz - GNU General Public License v3.
15 #
16 # Authors : Christophe Lincoln <pankso@slitaz.org>
17 # Pascal Bellard <pascal.bellard@slitaz.org>
18 # Eric Joseph-Alexandre <erjo@slitaz.org>
19 # Paul Issott <paul@slitaz.org>
20 # Rohit Joshi <jozee@slitaz.org>
21 # Antoine Bodin <gokhlayeh@mailoo.org>
22 # Christopher Rogers <slaxemulator@gmail.com>
23 #
24 VERSION=4.6.3
26 ####################
27 # Script variables #
28 ####################
30 source /usr/lib/slitaz/libtaz
31 source_lib commons
32 . /etc/slitaz/tazpkg.conf
34 # Include gettext helper script.
35 . /usr/bin/gettext.sh
37 # Export package name for gettext.
38 TEXTDOMAIN='tazpkg'
39 export TEXTDOMAIN
41 # Initialize some variables to use words rather than numbers for functions
42 # and actions.
43 COMMAND=$1
44 PACKAGE=${2%/}
45 [ -n "$PACKAGE" ] &&
46 PACKAGE_FILE="$(cd $(dirname $PACKAGE) ; pwd)/$(basename $PACKAGE)"
47 if [ -f "$PACKAGE" ]; then
48 # Set pkg basename for install, extract
49 PACKAGE=$(basename ${PACKAGE%.tazpkg} 2>/dev/null)
50 else
51 # Pkg name for remove, search and all other cmds
52 PACKAGE=${PACKAGE%.tazpkg}
53 fi
54 TARGET_DIR=$3
55 TOP_DIR=`pwd`
56 TMP_DIR=$tmp/$RANDOM
57 INSTALL_LIST=""
58 SAVE_CACHE_DIR="$CACHE_DIR"
60 # Path to tazpkg used dir and configuration files
61 INSTALLED=$LOCALSTATE/installed
62 MIRROR=$LOCALSTATE/mirror
63 BLOCKED=$LOCALSTATE/blocked-packages.list
64 UP_LIST=$LOCALSTATE/packages.up
65 DEFAULT_MIRROR="http://mirror.slitaz.org/packages/`cat /etc/slitaz-release`/"
67 # Check if the directories and files used by Tazpkg
68 # exist. If not and user is root we create them.
69 check_base_dir()
70 {
71 if test $(id -u) = 0 ; then
72 check_dir $1$CACHE_DIR
73 check_dir $1$INSTALLED
74 if [ ! -f "$1$LOCALSTATE/mirror" ]; then
75 echo "$DEFAULT_MIRROR" > $1$LOCALSTATE/mirror
76 fi
77 fi
78 }
79 check_base_dir
81 ####################
82 # Script functions #
83 ####################
85 # Print the usage.
86 usage ()
87 {
88 echo -e "`gettext \"SliTaz package manager - Version\"`: $VERSION
89 \033[1m`gettext \"Usage\"`:\033[0m `gettext \"tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]\"`
90 tazpkg shell\n
91 \033[1m`gettext \"Commands\"`: \033[0m
92 usage `gettext \"Print this short usage.\"`
93 bugs `gettext \"Show known bugs in packages.\"`
94 list `gettext \"List installed packages on the system by category or all.\"`
95 xhtml-list `gettext \"Create a xHTML list of installed packages.\"`
96 list-mirror `gettext \"List all available packages on the mirror (--diff for new).\"`
97 info `gettext \"Print information about a package.\"`
98 desc `gettext \"Print description of a package (if it exists).\"`
99 list-files `gettext \"List the files installed with a package.\"`
100 list-config `gettext \"List the configuration files.\"`
101 search `gettext \"Search for a package by pattern or name (options: -i|-l|-m).\"`
102 search-pkgname `gettext \"Search on mirror for package having a particular file.\"`
103 search-file `gettext \"Search for file(s) in all installed packages files.\"`
104 install `gettext \"Install a local (*.tazpkg) package (--forced to force).\"`
105 install-list `gettext \"Install all packages from a list of packages.\"`
106 remove `gettext \"Remove the specified package and all installed files.\"`
107 extract `gettext \"Extract a (*.tazpkg) package into a directory.\"`
108 pack `gettext \"Pack an unpacked or prepared package tree.\"`
109 recharge `gettext \"Recharge your packages.list from the mirror.\"`
110 up|--help-up `gettext \"Check packages md5sum to list and install latest upgrades.\"`
111 repack `gettext \"Create a package archive from an installed package.\"`
112 repack-config `gettext \"Create a package archive with configuration files.\"`
113 recompress `gettext \"Rebuild a package with a better compression ratio.\"`
114 upgrade `gettext \"Upgrade one or all installed package(s) (obsolete).\"`
115 upgradeable `gettext \"Build upgradeable packages list quickly. (buggy)\"`
116 block|unblock `gettext \"Block an installed package version or unblock it for upgrade.\"`
117 get `gettext \"Download a package into the current directory.\"`
118 get-install `gettext \"Download and install a package from the mirror.\"`
119 get-install-list `gettext \"Download and install a list of packages from the mirror.\"`
120 check `gettext \"Verify consistency of installed packages.\"`
121 add-flavor `gettext \"Install the flavor list of packages.\"`
122 install-flavor `gettext \"Install the flavor list of packages and remove other ones.\"`
123 set-release `gettext \"Change release and update packages.\"`
124 clean-cache `gettext \"Clean all packages downloaded in cache directory.\"`
125 depends `gettext \"Display dependencies tree.\"`
126 rdepends `gettext \"Display reverse dependencies tree.\"`
127 convert `gettext \"Convert a deb/rpm/tgz/arch package to a slitaz (.tazpkg).\"`
128 link `gettext \"Link a package from another slitaz installation.\"`
129 setup-mirror `gettext \"Change the mirror url configuration.\"`
130 list-undigest `gettext \"List undigest mirrors.\"`
131 remove-undigest `gettext \"Remove an undigest mirror.\"`
132 add-undigest `gettext \"Add an undigest mirror.\"`
133 setup-undigest `gettext \"Update an undigest mirror.\"`
134 reconfigure `gettext \"Replay post install script from package.\"`"
135 }
137 usage_up() {
138 echo -e "
139 \033[1m`gettext \"Tazpkg usage for command up\"`:\033[0m `gettext \"tazpkg up [--option]`\n
140 * `gettext \"Without options run in interactive mode and ask before install\"`
142 \033[1m`gettext \"Where options are\"`: \033[0m
143 --check |-c `gettext \"Check only for available upgrades\"`
144 --recharge |-r `gettext \"Force recharge of packages list and check\"`
145 --install |-i `gettext \"Check for upgrades and install them all\"`
147 \033[1m`gettext \"Example\"`: \033[0m
148 tazpkg up --recharge --install
149 tazpkg up -c -r
150 "
151 }
153 separator() {
154 echo "================================================================================"
155 }
157 # Check for a package name on cmdline.
158 check_for_package_on_cmdline()
159 {
160 if [ -z "$PACKAGE" ]; then
161 echo ""
162 gettext "Please specify a package name on the command line."; echo
163 echo ""
164 exit 0
165 fi
166 }
168 # Check if the package (*.tazpkg) exists before installing or extracting.
169 check_for_package_file()
170 {
171 if [ ! -f "$PACKAGE_FILE" ]; then
172 echo ""
173 eval_gettext "Unable to find: \$PACKAGE_FILE"; echo
174 echo "" && exit 0
175 fi
176 }
178 # Check for the receipt of an installed package.
179 check_for_receipt()
180 {
181 if [ ! -f "$1$INSTALLED/$PACKAGE/receipt" ]; then
182 FS=$1
183 echo ""
184 eval_gettext "Unable to find the receipt: \$FS\$INSTALLED/\$PACKAGE/receipt"; echo
185 echo "" && exit 0
186 fi
187 }
189 # Get repositories priority using $LOCALSTATE/priority.
190 # In this files, undigest are called by their name and main mirror
191 # by main. Sort order : priority
192 look_for_priority()
193 {
194 [ -s $LOCALSTATE/priority ] && priority=$(cat $LOCALSTATE/priority)
195 for rep in main $(ls $LOCALSTATE/undigest 2>/dev/null); do
196 if [ ! -s $LOCALSTATE/priority ] || \
197 ! grep -q ^$rep$ $LOCALSTATE/priority; then
198 priority=$(echo -e "$priority\n$rep")
199 fi
200 done
201 priority=$(echo "$priority" | sed '/^$/d' | \
202 while read line; do
203 if [ "$line" = main ]; then
204 echo $LOCALSTATE
205 else
206 echo $LOCALSTATE/undigest/$line
207 fi
208 done)
209 }
211 # Get package name in a directory
212 package_fullname_in_dir()
213 {
214 [ -f $1/receipt ] || return
215 EXTRAVERSION=""
216 . $1/receipt
217 echo $PACKAGE-$VERSION$EXTRAVERSION
218 }
220 # Get package name that is already installed.
221 get_installed_package_pathname()
222 {
223 for i in $2$INSTALLED/${1%%-*}*; do
224 [ -d $i ] || continue
225 if [ "$1" = "$(package_fullname_in_dir $i)" ]; then
226 echo $i
227 return
228 fi
229 done
230 }
232 # Check if a package is already installed.
233 check_for_installed_package()
234 {
235 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
236 echo ""
237 eval_gettext "\$PACKAGE package is already installed. You can
238 use the --forced option to force installation or remove it and reinstall."; echo
239 echo "" && exit 0
240 fi
241 }
243 # Check for packages.list to download and install packages.
244 check_for_packages_list()
245 {
246 if [ ! -f "$LOCALSTATE/packages.list" ]; then
247 if test $(id -u) = 0 ; then
248 tazpkg recharge
249 else
250 echo ""
251 eval_gettext "Unable to find the list: \$LOCALSTATE/packages.list"; echo
252 gettext \
253 "You must probably run 'tazpkg recharge' as root to get the latest list of
254 packages available on the mirror."; echo
255 echo "" && exit 0
256 fi
257 fi
258 }
260 get_cache_dir()
261 {
262 echo $rep > $tmp/rep
263 if [ "$rep" = "$LOCALSTATE" ]; then
264 CACHE_DIR="$SAVE_CACHE_DIR/$SLITAZ_VERSION/packages"
265 elif [ "${rep%-incoming}" = "$rep" ]; then
266 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages"
267 else
268 rep="${rep%-incoming}"
269 CACHE_DIR="$SAVE_CACHE_DIR/${rep##*/}/packages-incoming"
270 fi
271 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
272 echo $CACHE_DIR > $tmp/cachedir
273 }
275 # get an already installed package from packages.equiv
276 equivalent_pkg()
277 {
278 for i in $(grep -hs "^$1=" $LOCALSTATE/packages.equiv \
279 $LOCALSTATE/undigest/*/packages.equiv | sed "s/^$1=//"); do
280 if echo $i | fgrep -q : ; then
281 # format 'alternative:newname'
282 # if alternative is installed then substitute newname
283 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
284 # substitute package dependancy
285 echo ${i#*:}
286 return
287 fi
288 else
289 # if alternative is installed then nothing to install
290 if [ -f $2$INSTALLED/$i/receipt ]; then
291 # substitute installed package
292 echo $i
293 return
294 fi
295 fi
296 done
297 # if not found in packages.equiv then no substitution
298 echo $1
299 }
301 # get a virtual package from packages.equiv
302 virtual_pkg()
303 {
304 for i in $(for rep in $priority; do
305 grep -hs "^$1=" $rep/packages.equiv
306 done | sed "s/^$1=//"); do
307 if echo $i | fgrep -q : ; then
308 # format 'alternative:newname'
309 # if alternative is installed then substitute newname
310 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
311 # substitute package dependancy
312 echo ${i#*:}
313 return
314 fi
315 else
316 # unconditional substitution
317 echo $i
318 return
319 fi
320 done
321 }
323 # Get package filename available on the mirror
324 get_package_filename()
325 {
326 local pkg
327 for rep in $priority; do
328 pkg=$(grep -A 1 -sh "^$1$" $rep/packages.txt | tail -1 | \
329 sed 's/^ *//')
330 [ "$pkg" ] && pkg=$(grep -sh "^$1-$pkg" \
331 $rep/packages.list | head -1)
333 # Allow user to call a package with his version number.
334 [ "$pkg" ] || pkg=$(grep -sh "^$1$" $rep/packages.list | head -1)
336 [ "$pkg" ] || pkg=$(grep -sh "^$1-[0-9]" \
337 $rep/packages.list | head -1)
338 [ "$pkg" ] || pkg=$(grep -sh "^$1-.[\.0-9]" \
339 $rep/packages.list | head -1)
340 [ "$pkg" ] && get_cache_dir && break
341 done
342 if [ -z "$pkg" ]; then
343 # Check for vitual package
344 local equiv
345 equiv=$(virtual_pkg $1)
346 if [ "$equiv" != "$1" ]; then
347 PACKAGE=$equiv
348 get_package_filename $PACKAGE
349 return
350 fi
351 fi
352 echo $pkg
353 }
355 # Check for a package in packages.list. Used by get and get-install to grep
356 # package basename.
357 check_for_package_in_list()
358 {
359 local filename
360 local check_only
361 check_only="$1"
362 filename=$(get_package_filename $PACKAGE)
363 if [ "$filename" ]; then
364 PACKAGE=$filename
365 CACHE_DIR=$(cat $tmp/cachedir)
366 rep=$(cat $tmp/rep)
367 rm -f $tmp/rep $tmp/cachedir
368 else
369 echo ""
370 eval_gettext "Unable to find: \$PACKAGE in the mirrored packages list."; echo
371 echo ""
372 [ -n "$check_only" ] && return 1
373 exit 0
374 fi
375 }
377 # Log this activity
378 log()
379 {
380 local extra
381 [ "$1" = "Installed" ] && \
382 extra=" - $(fgrep $PACKAGE-$VERSION $LOCALSTATE/installed.md5 | awk '{ print $1 }')"
383 [ -e $LOG ] || touch $LOG
384 DATE=`date +'%F %T'`
385 [ -w $LOG ] &&
386 echo "$DATE - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
387 }
389 # Download a file from this mirror
390 download_from()
391 {
392 local i
393 local mirrors
394 mirrors="$1"
395 shift
396 for i in $mirrors; do
397 case "$i" in
398 http://*|ftp://*) wget -c $i$@ && break;;
399 *) ln -sf $i/$1 . && break;;
400 esac
401 done
402 }
404 # Download a file trying all mirrors
405 download()
406 {
407 local i
408 case "$1" in
409 *.tazpkg)
410 for i in $priority ; do
411 grep -q "^${1%.tazpkg}$" $i/packages.list 2>/dev/null || continue
412 download_from "$(cat $i/mirror)" "$@" && return
413 done
414 esac
415 for i in $(cat `for rep in $priority; do echo $rep/mirror; done` \
416 2> /dev/null); do
417 download_from "$i" "$@" && break
418 done
419 }
421 # Extract a package with cpio and gzip/lzma.
422 extract_package()
423 {
424 eval_gettext "Extracting \$PACKAGE... "
425 cpio -idm --quiet < ${PACKAGE_FILE##*/} && rm -f ${PACKAGE_FILE##*/}
426 status
427 if [ -f fs.cpio.lzma ]; then
428 gettext "Extracting the pseudo fs... "
429 echo -n "(lzma) "
430 unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
431 status
432 elif [ -f fs.cpio.gz ]; then
433 gettext "Extracting the pseudo fs... "
434 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
435 status
436 fi
437 }
439 remove_with_path()
440 {
441 # Avoid dirname errors by checking for argument.
442 [ "$1" ] || return
444 local dir
445 rm -f $1 2>/dev/null
446 dir="$1"
447 while [ "$dir" != "/" ]; do
448 dir="$(dirname $dir)"
449 rmdir $dir 2> /dev/null || break
450 done
451 }
453 grepesc()
454 {
455 sed 's/\[/\\[/g'
456 }
458 # This function installs a package in the rootfs.
459 install_package()
460 {
461 ROOT=$1
462 if [ -n "$ROOT" ]; then
463 # Get absolute path
464 ROOT=$(cd $ROOT; pwd)
465 fi
466 {
467 # Create package path early to avoid dependencies loop
468 mkdir -p $TMP_DIR
469 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
470 . $TMP_DIR/receipt
471 if grep -q ^pre_depends $TMP_DIR/receipt; then
472 pre_depends $ROOT
473 fi
474 # Keep modifers and file list on upgrade
475 cp $ROOT$INSTALLED/$PACKAGE/modifiers \
476 $ROOT$INSTALLED/$PACKAGE/files.list $TMP_DIR 2> /dev/null
477 rm -rf $ROOT$INSTALLED/$PACKAGE 2> /dev/null
478 # Make the installed package data dir to store
479 # the receipt and the files list.
480 mkdir -p $ROOT$INSTALLED/$PACKAGE
481 cp $TMP_DIR/modifiers $ROOT$INSTALLED/$PACKAGE 2> /dev/null
482 cp $TMP_DIR/files.list $ROOT$INSTALLED/$PACKAGE 2> /dev/null
483 rm -rf $TMP_DIR 2> /dev/null
484 sed -i "/ $(basename $PACKAGE_FILE)$/d" \
485 $ROOT$LOCALSTATE/installed.md5 2> /dev/null
486 cd $(dirname $PACKAGE_FILE)
487 md5sum $(basename $PACKAGE_FILE) >> $ROOT$LOCALSTATE/installed.md5
488 }
489 # Resolve package deps.
490 check_for_deps $ROOT
491 if [ ! "$MISSING_PACKAGE" = "" ]; then
492 install_deps $ROOT
493 fi
494 mkdir -p $TMP_DIR
495 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $INSTALL_LIST-processed
496 echo ""
497 echo -e "\033[1m`gettext \"Installation of :\"`\033[0m $PACKAGE"
498 separator
499 eval_gettext "Copying \$PACKAGE... "
500 cp $PACKAGE_FILE $TMP_DIR
501 status
502 cd $TMP_DIR
503 extract_package
504 SELF_INSTALL=0
505 EXTRAVERSION=""
506 CONFIG_FILES=""
507 # Include temporary receipt to get the right variables.
508 . $PWD/receipt
509 cd $ROOT$INSTALLED
510 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
511 gettext "Checking post install dependencies... "
512 [ -f $INSTALLED/$PACKAGE/receipt ]
513 if ! status; then
514 eval_gettext "Please run 'tazpkg install \$PACKAGE_FILE' in / and retry."; echo
515 rm -rf $TMP_DIR
516 exit 1
517 fi
518 fi
519 # Get files to remove if upgrading
520 if [ -f $PACKAGE/files.list ]; then
521 while read file; do
522 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
523 for i in $(cat $PACKAGE/modifiers 2> /dev/null ;
524 fgrep -sl $PACKAGE */modifiers | cut -d/ -f1 ); do
525 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
526 done
527 echo $file
528 done < $PACKAGE/files.list > $TMP_DIR/files2remove.list
529 fi
530 # Remember modified packages
531 { check=false
532 for i in $(fgrep -v [ $TMP_DIR/files.list); do
533 [ -e "$ROOT$i" ] || continue
534 [ -d "$ROOT$i" ] && continue
535 echo "- $i"
536 check=true
537 done ;
538 $check && for i in *; do
539 [ "$i" == "$PACKAGE" ] && continue
540 [ -s $i/files.list ] || continue
541 awk "{ printf \"$i %s\\n\",\$1 }" < $i/files.list
542 done; } | awk '
543 {
544 if ($1 == "-" || file[$2] != "") {
545 file[$2] = file[$2] " " $1
546 if ($1 != "-") {
547 if (pkg[$1] == "") all = all " " $1
548 pkg[$1] = pkg[$1] " " $2
549 }
550 }
551 }
552 END {
553 for (i = split(all, p, " "); i > 0; i--)
554 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
555 printf "%s %s\n",p[i],f[j];
556 }
557 ' | while read dir file; do
558 if grep -qs ^$dir$ $PACKAGE/modifiers; then
559 # Do not overload an overloaded file !
560 rm $TMP_DIR$file 2> /dev/null
561 continue
562 fi
563 grep -qs ^$PACKAGE$ $dir/modifiers && continue
564 if [ -s "$dir/volatile.cpio.gz" ]; then
565 # We can modify backed up files without notice
566 zcat $dir/volatile.cpio.gz | cpio -t --quiet | \
567 grep -q "^${file#/}$" && continue
568 fi
569 echo "$PACKAGE" >> $dir/modifiers
570 done
572 cd $TMP_DIR
573 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
574 # Copy the description if found.
575 if [ -f "description.txt" ]; then
576 cp description.txt $ROOT$INSTALLED/$PACKAGE
577 fi
578 # Copy the md5sum if found.
579 if [ -f "md5sum" ]; then
580 cp md5sum $ROOT$INSTALLED/$PACKAGE
581 fi
582 # Pre install commands.
583 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
584 pre_install $ROOT
585 fi
586 if [ -n "$CONFIG_FILES" ]; then
587 # save 'official' configuration files
588 eval_gettext "Saving configuration files for \$PACKAGE... "
589 for i in $CONFIG_FILES; do
590 { cd fs ; find ${i#/} -type f; cd ..; }
591 done | { cd fs ; cpio -o -H newc --quiet | gzip -9; cd ..; } > \
592 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
593 # keep user configuration files
594 for i in $CONFIG_FILES; do
595 { cd fs ; find ${i#/} -type f; cd ..; }
596 done | while read i; do
597 [ -e $ROOT/$i ] || continue
598 cp -a $ROOT/$i fs/$i
599 done
600 status
601 fi
602 eval_gettext "Installing \$PACKAGE... "
603 cp -a fs/* $ROOT/
604 status
605 if [ -s files2remove.list ]; then
606 eval_gettext "Removing old \$PACKAGE... "
607 while read file; do
608 remove_with_path $ROOT$file
609 done < files2remove.list
610 true
611 status
612 fi
613 # Remove the temporary random directory.
614 gettext "Removing all tmp files... "
615 cd .. && rm -rf $TMP_DIR
616 status
617 # Post install commands.
618 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
619 post_install $ROOT
620 fi
621 # Update-desktop-database if needed.
622 if [ "$(fgrep .desktop $ROOT$INSTALLED/$PACKAGE/files.list | fgrep /usr/share/applications/)" ]; then
623 updatedesktopdb=yes
624 fi
625 # Update-mime-database if needed.
626 if [ "$(fgrep /usr/share/mime $ROOT$INSTALLED/$PACKAGE/files.list)" ]; then
627 updatemimedb=yes
628 fi
629 cd $TOP_DIR
630 separator
631 eval_gettext "\$PACKAGE (\$VERSION\$EXTRAVERSION) is installed."; echo
632 echo ""
633 # Log this activity
634 [ -n "$ROOT" ] || log Installed
635 }
637 # Check for loop in deps tree.
638 check_for_deps_loop()
639 {
640 local list
641 local pkg
642 local deps
643 pkg=$1
644 shift
645 [ -n "$1" ] || return
646 list=""
647 # Filter out already processed deps
648 for i in $@; do
649 case " $ALL_DEPS" in
650 *\ $i\ *);;
651 *) list="$list $i";;
652 esac
653 done
654 ALL_DEPS="$ALL_DEPS$list "
655 for i in $list; do
656 [ -f $i/receipt ] || continue
657 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
658 case " $deps " in
659 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
660 *) check_for_deps_loop $pkg $deps;;
661 esac
662 done
663 }
665 # Check for missing deps listed in a receipt packages.
666 check_for_deps()
667 {
668 local saved;
669 saved=$PACKAGE
670 mkdir -p $TMP_DIR
671 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $PACKAGE_FILE
672 . $TMP_DIR/receipt
673 PACKAGE=$saved
674 rm -rf $TMP_DIR
675 for pkgorg in $DEPENDS
676 do
677 i=$(equivalent_pkg $pkgorg $1)
678 if [ ! -d "$1$INSTALLED/$i" ]; then
679 MISSING_PACKAGE=$i
680 deps=$(($deps+1))
681 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
682 eval_gettext "WARNING Dependency loop between \$PACKAGE and \$i."; echo
683 fi
684 done
685 if [ ! "$MISSING_PACKAGE" = "" ]; then
686 echo -e "\033[1m`gettext \"Tracking dependencies for :\"`\033[0m $PACKAGE"
687 separator
688 for pkgorg in $DEPENDS
689 do
690 i=$(equivalent_pkg $pkgorg $1)
691 if [ ! -d "$1$INSTALLED/$i" ]; then
692 MISSING_PACKAGE=$i
693 eval_gettext "Missing: \$MISSING_PACKAGE"; echo
694 fi
695 done
696 separator
697 eval_gettext "\$deps missing package(s) to install."; echo
698 fi
699 }
701 # Install all missing deps. Auto install or ask user then install all missing
702 # deps from local dir, cdrom, media or from the mirror. In case we want to
703 # install packages from local, we need a packages.list to find the version.
704 install_deps()
705 {
706 local root
707 root=""
708 [ -n "$1" ] && root="--root=$1"
709 if [ "$AUTO_INSTALL_DEPS" == "yes" ]; then
710 answer=`translate_querry y`
711 else
712 echo ""
713 gettext "Install all missing dependencies"
714 echo -n " (`translate_querry y`/`translate_querry N`) ? "
715 read answer
716 echo ""
717 fi
718 if [ "$answer" == "$(translate_querry y)" ]; then
719 for pkgorg in $DEPENDS
720 do
721 pkg=$(equivalent_pkg $pkgorg $1)
722 if [ ! -d "$1$INSTALLED/$pkg" ]; then
723 local list
724 list="$INSTALL_LIST"
725 [ -n "$list" ] || list="$TOP_DIR/packages.list"
726 # We can install packages from a local dir by greping
727 # the TAZPKG_BASENAME in the local packages.list.
728 found=0
729 if [ -f "$list" ]; then
730 eval_gettext "Checking if \$pkg exists in local list... "; echo
731 mkdir $TMP_DIR
732 for i in $pkg-*.tazpkg; do
733 [ -f $i ] || continue
734 { cd $TMP_DIR ; cpio --quiet -i receipt > /dev/null 2>&1; } < $i
735 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
736 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
737 then
738 found=1
739 tazpkg install $i $root --list=$list
740 break
741 fi
742 done
743 rm -rf $TMP_DIR
744 fi
745 # Install deps from the mirror.
746 if [ $found -eq 0 ]; then
747 if [ ! -f "$LOCALSTATE/packages.list" ]; then
748 tazpkg recharge
749 fi
750 tazpkg get-install $pkg $root
751 fi
752 fi
753 done
754 else
755 echo ""
756 eval_gettext \
757 "Leaving dependencies for \$PACKAGE unresolved. The package is installed but
758 will probably not work."; echo
759 echo ""
760 fi
761 }
763 # xHTML packages list header.
764 xhtml_header()
765 {
766 cat > $XHTML_LIST << _EOT_
767 <!DOCTYPE html>
768 <html xmlns="http://www.w3.org/1999/xhtml">
769 <head>
770 <title>Install packages on: `hostname`</title>
771 <meta charset="utf-8" />
772 <style type="text/css">
773 body { font: 88% sans-serif, vernada, arial; margin: 0; }
774 #header { background: #351a0a; height: 40px; border-bottom: 8px solid #d66018; }
775 #content { margin: 40px 80px; text-align: justify; }
776 #footer { text-align: center; padding: 20px; border-top: 1px solid #ddd; }
777 h1 { margin: 0; padding: 8px; color: #fff; font-size: 20px; }
778 h2 { color: #444; } h3 { color: #666; font-size: 140%; }
779 pre { background-color: #f8f8f8; border: 1px solid #ddd; padding: 10px;
780 -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;}
781 </style>
782 </head>
783 <body>
785 <body>
786 <div id="header">
787 <h1>Installed packages list</h1>
788 </div>
790 <!-- Start content -->
791 <div id="content">
793 <p>
794 _packages_ packages installed - List generated on : $DATE
795 <p>
797 _EOT_
798 }
800 # xHTML content with packages info.
801 xhtml_pkg_info()
802 {
803 cat >> $XHTML_LIST << _EOT_
804 <h3>$PACKAGE</h3>
805 <pre>
806 Version : $VERSION$EXTRAVERSION
807 Short desc : $SHORT_DESC
808 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
809 </pre>
811 _EOT_
812 }
814 # xHTML packages list footer.
815 xhtml_footer()
816 {
817 cat >> $XHTML_LIST << _EOT_
818 <hr />
819 <p id="footer">
820 $packages packages installed - List generated on : $DATE
821 </p>
823 <!-- End content -->
824 </div>
825 </body>
826 </html>
827 _EOT_
828 }
830 # Search pattern in installed packages.
831 search_in_installed_packages()
832 {
833 gettext "Installed packages"; echo
834 separator
835 list=`ls -1 $INSTALLED | grep -i "$PATTERN"`
836 for pkg in $list
837 do
838 EXTRAVERSION=""
839 [ -f $INSTALLED/$pkg/receipt ] || continue
840 . $INSTALLED/$pkg/receipt
841 echo -n "$PACKAGE "
842 echo -en "\033[24G $VERSION$EXTRAVERSION"
843 echo -e "\033[42G `translate_category $CATEGORY`."
844 packages=$(($packages+1))
845 done
846 # Set correct ending messages.
847 if [ "$packages" = "" ]; then
848 eval_gettext "0 installed packages found for : \$PATTERN"; echo
849 echo ""
850 else
851 separator
852 eval_gettext "\$packages installed package(s) found for : \$PATTERN"; echo
853 echo ""
854 fi
855 }
857 # Search in packages.list for available pkgs.
858 search_in_packages_list()
859 {
860 gettext "Available packages name-version"; echo
861 separator
862 packages=0
863 for i in $LOCALSTATE/packages.list $LOCALSTATE/undigest/*/packages.list; do
864 grep -is "$PATTERN" $i
865 packages=$(($packages + `grep -is "$PATTERN" $i | wc -l`))
866 done
867 if [ ! -f "$LOCALSTATE/packages.list" ]; then
868 echo ""
869 gettext \
870 "No 'packages.list' found to check for mirrored packages. For more results,
871 please run 'tazpkg recharge' once as root before searching."; echo
872 echo ""
873 fi
874 if [ "$packages" = "0" ]; then
875 eval_gettext "0 available packages found for : \$PATTERN"; echo
876 echo ""
877 else
878 separator
879 eval_gettext "\$packages available package(s) found for : \$PATTERN"; echo
880 echo ""
881 fi
882 }
884 # search --mirror: Search in packages.txt for available pkgs and give more
885 # info than --list or default.
886 search_in_packages_txt()
887 {
888 gettext "Matching packages name with version and desc"; echo
889 separator
890 packages=0
891 for i in $LOCALSTATE/packages.txt $LOCALSTATE/undigest/*/packages.txt; do
892 grep -is -A 2 "^$PATTERN" $i
893 packages=$(($packages + `grep -is "^$PATTERN" $i | wc -l`))
894 done
895 if [ ! -f "$LOCALSTATE/packages.txt" ]; then
896 echo ""
897 gettext \
898 "No 'packages.txt' found to check for mirrored packages. For more results,
899 please run 'tazpkg recharge' once as root before searching."; echo
900 echo ""
901 fi
902 if [ "$packages" = "0" ]; then
903 eval_gettext "0 available packages found for : \$PATTERN"; echo
904 echo ""
905 else
906 separator
907 eval_gettext "\$packages available package(s) found for : \$PATTERN"; echo
908 echo ""
909 fi
910 }
912 # Install package-list from a flavor
913 install_flavor()
914 {
915 check_root
917 # Get repositories priority list.
918 look_for_priority
920 FLAVOR=$1
921 ARG=$2
922 mkdir -p $TMP_DIR
923 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
924 cd $TMP_DIR
925 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
926 zcat $FLAVOR.flavor | cpio --quiet -i >/dev/null
927 while read file; do
928 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
929 [ -f $pkg/receipt ] || continue
930 EXTRAVERSION=""
931 . $pkg/receipt
932 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
933 done
934 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
935 cd $CACHE_DIR
936 download $file.tazpkg
937 cd $TMP_DIR
938 tazpkg install $CACHE_DIR/$file.tazpkg --forced
939 done < $FLAVOR.pkglist
940 [ -f $FLAVOR.nonfree ] && while read pkg; do
941 [ -d $INSTALLED/$pkg ] || continue
942 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
943 get-$pkg
944 done < $FLAVOR.nonfree
945 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
946 [ -f $INSTALLED/$pkg/receipt ] || continue
947 EXTRAVERSION=""
948 . $INSTALLED/$pkg/receipt
949 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
950 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
951 tazpkg remove $PACKAGE
952 done
953 else
954 eval_gettext "Can't find flavor \$FLAVOR. Abort."; echo
955 fi
956 cd $TOP_DIR
957 rm -rf $TMP_DIR
958 }
960 # Update mirror urls
961 setup_mirror()
962 {
963 # Backup old list.
964 if [ -f "$1/mirror" ]; then
965 cp -f $1/mirror $1/mirror.bak
966 fi
967 echo ""
968 echo -e "\033[1m`gettext \"Current mirror(s)\"`\033[0m"
969 separator
970 echo " `cat $1/mirror 2> /dev/null`"
971 gettext \
972 "Please enter URL of the new mirror (http, ftp or local path). You must specify
973 the complete address to the directory of the packages and packages.list file."; echo
974 echo ""
975 gettext "New mirror(s) URL : "
976 NEW_MIRROR_URL=$2
977 if [ -n "$NEW_MIRROR_URL" ]; then
978 echo $NEW_MIRROR_URL
979 else
980 read NEW_MIRROR_URL
981 fi
982 if [ "$NEW_MIRROR_URL" = "" ]; then
983 gettext "Nothing has been changed."; echo
984 else
985 eval_gettext "Setting mirror(s) to : $NEW_MIRROR_URL"; echo
986 rm -f $1/mirror
987 for i in $NEW_MIRROR_URL; do
988 echo "$i" >> $1/mirror
989 done
990 fi
991 echo ""
992 }
994 # recursive dependencies scan
995 dep_scan()
996 {
997 for i in $1; do
998 case " $ALL_DEPS " in
999 *\ $i\ *) continue;;
1000 esac
1001 ALL_DEPS="$ALL_DEPS $i"
1002 [ -n "$2" ] && echo "$2$i ($(fgrep -A 3 $i $LOCALSTATE/packages.txt \
1003 | tail -1 | sed 's/.*(\([^ ]*\).*/\1/'))"
1004 [ -f $i/receipt ] || continue
1005 DEPENDS=""
1006 . $i/receipt
1007 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
1008 done
1011 # recursive reverse dependencies scan
1012 rdep_scan()
1014 SEARCH=$1
1016 for i in * ; do
1017 DEPENDS=""
1018 . $i/receipt
1019 echo "$i $(echo $DEPENDS)"
1020 done | awk -v search=$SEARCH '
1021 function show_deps(deps, all_deps, pkg, space)
1023 if (all_deps[pkg] == 1) return
1024 all_deps[pkg] = 1
1025 if (space != "") printf "%s %s\n",space,pkg
1026 for (i = 1, n = split(deps[pkg], mydeps, " "); i <= n; i++) {
1027 show_deps(deps, all_deps, mydeps[i],"==" space)
1032 all_deps[$1] = 0
1033 for (i = 2; i <= NF; i++)
1034 deps[$i] = deps[$i] " " $1
1037 END {
1038 show_deps(deps, all_deps, search, "")
1040 ' | while read spc pkg; do
1041 echo -n $spc | sed 's/=/ /g'
1042 echo -n $pkg
1043 echo -n ' ('
1044 fgrep -A 3 $pkg $LOCALSTATE/packages.txt | tail -1 | \
1045 sed 's/.*(\([^ ]*\).*/\1)/'
1046 done
1049 # Check for ELF file
1050 is_elf()
1052 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
1055 # Print shared library dependencies
1056 ldd()
1058 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
1061 # search dependencies for files in $TMP_DIR/$file/fs
1062 find_depends()
1064 DEFAULT_DEPENDS="glibc-base gcc-lib-base"
1066 [ -f $LOCALSTATE/files.list.lzma ] || tazpkg recharge > /dev/null
1067 for i in $LOCALSTATE/files.list.lzma \
1068 $LOCALSTATE/undigest/*/files.list.lzma ; do
1069 [ -f $i ] && lzma d $i -so >> $TMP_DIR/files.list
1070 done
1071 find $TMP_DIR/$file/fs -type f | while read chkfile ; do
1072 is_elf $chkfile || continue
1073 case "$chkfile" in
1074 *.o|*.ko|*.ko.gz) continue;;
1075 esac
1076 ldd $chkfile | while read lib rem; do
1077 case "$lib" in
1078 statically|linux-gate.so*|ld-*.so|*/ld-*.so)
1079 continue;;
1080 esac
1081 find $TMP_DIR/$file/fs | grep -q /$lib$ && continue
1082 for dep in $(fgrep $lib files.list | cut -d: -f1); do
1083 case " $DEFAULT_DEPENDS " in
1084 *\ $dep\ *) continue 2;;
1085 esac
1086 grep -qs "^$dep$" $TMP_DIR/depends && continue 2
1087 done
1088 if [ -n "$dep" ]; then
1089 echo "$dep" >> $TMP_DIR/depends
1090 else
1091 grep -qs ^$lib$ $TMP_DIR/unresolved ||
1092 echo "$lib" >> $TMP_DIR/unresolved
1093 fi
1094 done
1095 done
1096 spc=""
1097 cat $TMP_DIR/depends 2> /dev/null | sort | uniq | while read file; do
1098 echo -n "$spc$file"
1099 spc=" "
1100 done
1103 show_unresolved_lib()
1105 if [ -s $TMP_DIR/unresolved ]; then
1106 echo -e "BUGS=\"`gettext \"No dependency for\"`" >> $1
1107 cat $TMP_DIR/unresolved | sort | uniq | while read file; do
1108 eval_gettext "WARNING: unknown dependency for \$lib"; echo
1109 echo -n " $file" >> $1
1110 done
1111 echo "\"" >> $1
1112 fi
1115 # convert a .ipk package to .tazpkg
1116 convert_ipk()
1118 mkdir -p $TMP_DIR
1119 tar xOzf $PACKAGE_FILE ./control.tar.gz | tar xzf - -C $TMP_DIR
1120 package="$(grep ^Package $TMP_DIR/control | sed 's/.*: //')"
1121 version="$(grep ^Version $TMP_DIR/control | sed 's/.*: //')"
1122 maintainer="$(grep ^Maintainer $TMP_DIR/control | sed 's/.*: //')"
1123 target="$(grep ^Architecture $TMP_DIR/control | sed 's/.*: //')"
1124 descrip="$(grep ^Description $TMP_DIR/control | sed 's/.*: //')"
1125 url="http://openwrt.org/"
1126 case "$target" in
1127 i386|all)
1128 file=$package-$version
1129 mkdir -p $TMP_DIR/$file/fs
1130 tar xOzf $PACKAGE_FILE ./data.tar.gz | \
1131 tar xzf - -C $TMP_DIR/$file/fs
1132 cd $TMP_DIR
1133 cat > $file/receipt <<EOT
1134 # SliTaz package receipt.
1135 # generated by tazpkg from package $(basename $PACKAGE_FILE)
1136 PACKAGE="$package"
1137 VERSION="$version"
1138 CATEGORY="misc"
1139 SHORT_DESC="$descrip"
1140 WEB_SITE="$url"
1141 MAINTAINER="$maintainer"
1142 DEPENDS="$(find_depends)"
1143 EOT
1144 [ -s conffiles ] && cat >> $file/receipt <<EOT
1145 CONFIG_FILES="$(cat conffiles)"
1146 EOT
1147 show_unresolved_lib $file/receipt
1148 while read script func; do
1149 [ -s $script ] && cat >> $file/receipt <<EOT
1151 $func()
1153 $(cat $script)
1155 EOT
1156 done <<EOT
1157 preinst pre_install
1158 postinst post_install
1159 prerm pre_remove
1160 postrm post_remove
1161 EOT
1162 awk '
1164 if (/^ / && show) print substr($0,2);
1165 else show=0;
1166 if (/^Description/) show=1;
1167 }' < $TMP_DIR/control > $file/description.txt
1168 sed -i 's/^\.$//' $file/description.txt
1169 [ -s $file/description.txt ] || rm -f $file/description.txt
1170 tazpkg pack $file
1171 cd $TOP_DIR
1172 mv $TMP_DIR/$file.tazpkg .
1173 ;;
1174 *)
1175 gettext "Invalid target: $target (expected i386)"; echo
1176 ;;
1177 esac
1178 rm -rf $TMP_DIR
1181 # convert a .pkg.tar.gz/.apk package to .tazpkg
1182 convert_arch()
1184 mkdir -p $TMP_DIR/fs
1185 tar xzf $PACKAGE_FILE -C $TMP_DIR/fs
1186 if [ -f $TMP_DIR/fs/.PKGINFO ]; then
1187 cd $TMP_DIR
1188 package="$(grep ^pkgname fs/.PKGINFO | sed 's/.*= //')"
1189 version="$(grep ^pkgver fs/.PKGINFO | sed 's/.*= //')"
1190 descrip="$(grep ^pkgdesc fs/.PKGINFO | sed 's/.*= //')"
1191 url="$(grep ^url fs/.PKGINFO | sed 's/.*= //')"
1192 maintainer="$(grep ^packager fs/.PKGINFO | sed 's/.*= //')"
1193 file=$package-$version
1194 mkdir $file
1195 mv fs $file
1196 cat > $file/receipt <<EOT
1197 # SliTaz package receipt.
1198 # generated by tazpkg from Archlinux package $(basename $PACKAGE_FILE)
1199 PACKAGE="$package"
1200 VERSION="$version"
1201 CATEGORY="misc"
1202 SHORT_DESC="$descrip"
1203 WEB_SITE="$url"
1204 MAINTAINER="$maintainer"
1205 DEPENDS="$(find_depends)"
1206 EOT
1207 show_unresolved_lib $file/receipt
1208 rm -f $file/fs/.[A-Z]*
1209 tazpkg pack $file
1210 mv $file.tazpkg $TOP_DIR
1211 else
1212 eval_gettext "\$PACKAGE_FILE does not look like an Archlinux/Alpine package !"; echo
1213 fi
1214 cd $TOP_DIR
1215 rm -rf $TMP_DIR
1218 # convert a .tgz package to .tazpkg
1219 convert_tgz()
1221 package=$(basename $PACKAGE_FILE)
1222 IFS='-'
1223 set -- $package
1224 unset IFS
1225 package=$1
1226 version=$2
1227 file="$package-$version"
1228 mkdir -p $TMP_DIR/$file/fs
1229 tar xzf $PACKAGE_FILE -C $TMP_DIR/$file/fs
1230 cd $TMP_DIR
1231 if [ -d $file/fs/install ]; then
1232 descrip=$(grep ^$package $file/fs/install/slack-desc | \
1233 head -1 | sed 's/.*(\(.*\)).*/\1/')
1234 cat > $file/receipt <<EOT
1235 # SliTaz package receipt.
1236 # generated by tazpkg from slackware package $(basename $PACKAGE_FILE)
1237 PACKAGE="$package"
1238 VERSION="$version"
1239 CATEGORY="misc"
1240 SHORT_DESC="$descrip"
1241 WEB_SITE="http://www.slackware.com/packages/"
1242 MAINTAINER="nobody@slitaz.org"
1243 DEPENDS="$(find_depends)"
1244 EOT
1245 show_unresolved_lib $file/receipt
1246 [ -f $file/fs/install/doinst.sh ] && cat >> $file/receipt <<EOM
1248 post_install()
1250 chroot \$1/ sh - << EOT
1251 cd /
1252 $(cat $file/fs/install/doinst.sh | sed -e 's/\\/\\\\/g' | sed -e 's/\$/\\$/g')
1253 EOT
1255 EOM
1256 grep ^$package $file/fs/install/slack-desc | \
1257 sed "s/^$package://" > $file/description.txt
1258 [ -s $file/description.txt ] || rm -f $file/description.txt
1259 rm -rf $file/fs/install
1260 tazpkg pack $file
1261 mv $file.tazpkg $TOP_DIR
1262 else
1263 eval_gettext "\$PACKAGE_FILE does not look like a Slackware package !"; echo
1264 fi
1265 cd $TOP_DIR
1266 rm -rf $TMP_DIR
1269 # convert a .deb package to .tazpkg
1270 convert_deb()
1272 mkdir -p $TMP_DIR
1273 dpkg-deb -e $PACKAGE_FILE $TMP_DIR
1274 package=$(grep '^ *Package:' $TMP_DIR/control)
1275 package=$(echo ${package##*:})
1276 version=$(grep '^ *Version:' $TMP_DIR/control)
1277 version=$(echo ${version##*:})
1278 descrip=$(grep '^ *Description:' $TMP_DIR/control)
1279 descrip=$(echo ${descrip##*:})
1280 target="$(grep ^Architecture $TMP_DIR/control | sed 's/.*: //')"
1281 case "$target" in
1282 i386|all)
1283 file="$package-$version"
1284 mkdir -p $TMP_DIR/$file/fs/
1285 dpkg-deb -x $PACKAGE_FILE $TMP_DIR/$file/fs
1286 cd $TMP_DIR
1287 cat > $file/receipt <<EOT
1288 # SliTaz package receipt.
1289 # generated by tazpkg from debian package $(basename $PACKAGE_FILE)
1290 PACKAGE="$package"
1291 VERSION="$version"
1292 CATEGORY="misc"
1293 SHORT_DESC="$descrip"
1294 WEB_SITE="http://packages.debian.org/search?keywords=$package"
1295 MAINTAINER="nobody@slitaz.org"
1296 DEPENDS="$(find_depends)"
1297 EOT
1298 [ -s conffiles ] && cat >> $file/receipt <<EOT
1299 CONFIG_FILES="$(cat conffiles)"
1300 EOT
1301 show_unresolved_lib $file/receipt
1302 awk '
1304 if (/^ / && show) print substr($0,2);
1305 else show=0;
1306 if (/^Description/) show=1;
1307 }' < $TMP_DIR/control > $file/description.txt
1308 sed -i 's/^\.$//' $file/description.txt
1309 [ -s $file/description.txt ] || rm -f $file/description.txt
1310 tazpkg pack $file
1311 mv $file.tazpkg $TOP_DIR
1312 ;;
1313 *)
1314 gettext "Invalid target: $target (expected i386)"; echo
1315 ;;
1316 esac
1317 cd $TOP_DIR
1318 rm -rf $TMP_DIR
1321 # convert a .rpm package to .tazpkg
1322 convert_rpm()
1324 mkdir -p $TMP_DIR
1325 cp $PACKAGE_FILE $TMP_DIR
1326 PACKAGE_FILE=$TMP_DIR/$(basename $PACKAGE_FILE)
1327 rpm -qip $PACKAGE_FILE | awk -v pkg=$(basename $PACKAGE_FILE) '
1328 BEGIN {
1329 goturl=0;
1330 printf "# Taz package receipt.\n";
1331 printf "# Generated by tazpkg from rpm package %s\n",pkg;
1334 if (/^Name/) { name=$3; printf "PACKAGE=\"%s\"\n",$3; }
1335 if (/^Version/) printf "VERSION=\"%s-",$3;
1336 if (/^Release/) printf "%s\"\n",$3;
1337 if (/^Summary/) printf "SHORT_DESC=\"%s\"\n",substr($0,15);
1338 if (/^URL/) { goturl=1; printf "WEB_SITE=\"%s\"\n",$3; }
1340 END {
1341 if (goturl == 0)
1342 printf "WEB_SITE=\"http://rpmfind.net/linux/rpm2html/search.php?query=%s\"\n",name;
1343 printf "CATEGORY=\"misc\"\n";
1344 printf "MAINTAINER=\"nobody@slitaz.org\"\n";
1346 ' > $TMP_DIR/receipt
1347 . $TMP_DIR/receipt
1348 file=$PACKAGE-$VERSION
1349 mkdir -p $TMP_DIR/$file/fs/
1350 mv $TMP_DIR/receipt $TMP_DIR/$file
1351 rpm -qip $PACKAGE_FILE | awk '
1352 DEGIN { show=0 }
1354 if (show) print;
1355 if (/^Description/) show=1;
1357 ' > $TMP_DIR/$file/description.txt
1358 cd $TMP_DIR/$file/fs/
1359 rpm2cpio $PACKAGE_FILE | cpio -idm --quiet
1360 cd ../..
1361 echo "DEPENDS=\"$(find_depends)\"" >> $TMP_DIR/$file/receipt
1362 show_unresolved_lib $TMP_DIR/$file/receipt
1363 tazpkg pack $file
1364 mv $file.tazpkg $TOP_DIR
1365 cd $TOP_DIR
1366 rm -rf $TMP_DIR
1369 update_desktop_database()
1371 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1372 $1/usr/bin/update-desktop-database $1/usr/share/applications 2>/dev/null
1373 fi
1376 update_mime_database()
1378 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1379 $1/usr/bin/update-mime-database $1/usr/share/mime
1380 fi
1383 translate_category()
1385 case $1 in
1386 base-system) gettext "base-system" ;;
1387 x-window) gettext "x-window" ;;
1388 utilities) gettext "utilities" ;;
1389 network) gettext "network" ;;
1390 graphics) gettext "graphics" ;;
1391 multimedia) gettext "multimedia" ;;
1392 office) gettext "office" ;;
1393 development) gettext "development" ;;
1394 system-tools) gettext "system-tools" ;;
1395 security) gettext "security" ;;
1396 games) gettext "games" ;;
1397 misc) gettext "misc" ;;
1398 meta) gettext "meta" ;;
1399 non-free) gettext "non-free" ;;
1401 # Support custom categories by keeping them untranslated.
1402 *) echo "$1" ;;
1404 esac
1407 reverse_translate_category()
1409 case $1 in
1410 `gettext "base-system"`) echo "base-system" ;;
1411 `gettext "x-window"`) echo "x-window" ;;
1412 `gettext "utilities"`) echo "utilities" ;;
1413 `gettext "network"`) echo "network" ;;
1414 `gettext "graphics"`) echo "graphics" ;;
1415 `gettext "multimedia"`) echo "multimedia" ;;
1416 `gettext "office"`) echo "office" ;;
1417 `gettext "development"`) echo "development" ;;
1418 `gettext "system-tools"`) echo "system-tools" ;;
1419 `gettext "security"`) echo "security" ;;
1420 `gettext "games"`) echo "games" ;;
1421 `gettext "misc"`) echo "misc" ;;
1422 `gettext "meta"`) echo "meta" ;;
1423 `gettext "non-free"`) echo "non-free" ;;
1425 # If category is not one of those translated in native language,
1426 # keep it untranslated. This allows both native and english
1427 # language support. This also supports custom categories.
1428 *) echo "$1" ;;
1430 esac
1433 translate_querry()
1435 case $1 in
1436 y) gettext "y" ;;
1437 Y) gettext "Y" ;;
1438 n) gettext "n" ;;
1439 N) gettext "N" ;;
1441 # Support other cases but keep them untranslated.
1442 *) echo "$1" ;;
1444 esac
1448 ###################
1449 # Tazpkg commands #
1450 ###################
1452 case "$COMMAND" in
1453 list)
1454 # List all installed packages or a specific category.
1456 if [ "$2" = "blocked" ]; then
1457 echo ""
1458 echo -e "\033[1m`gettext \"Blocked packages\"`\033[0m"
1459 separator
1460 if [ -s "$BLOCKED" ];then
1461 cat $BLOCKED
1462 else
1463 gettext "No blocked packages found."; echo
1464 fi
1465 echo "" && exit 0
1466 fi
1467 # Display the list of categories.
1468 if [ "$2" = "cat" -o "$2" = "categories" ]; then
1469 echo ""
1470 echo -e "\033[1m`gettext \"Packages categories\"`\033[0m"
1471 separator
1472 for i in $CATEGORIES
1473 do
1474 translate_category $i; echo
1475 categories=$(($categories+1))
1476 done
1477 separator
1478 eval_gettext "\$categories categories"; echo
1479 echo ""
1480 exit 0
1481 fi
1482 # Check for an asked category.
1483 if [ -n "$2" ]; then
1484 ASKED_CATEGORY_I18N=$2
1485 ASKED_CATEGORY=$(reverse_translate_category $2)
1486 echo ""
1487 echo -e "\033[1m`gettext \"Installed packages of category:\"`\033[0m $ASKED_CATEGORY_I18N"
1488 separator
1489 for pkg in $INSTALLED/*
1490 do
1491 [ -f $pkg/receipt ] || continue
1492 EXTRAVERSION=""
1493 . $pkg/receipt
1494 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
1495 echo -n "$PACKAGE"
1496 echo -e "\033[24G $VERSION$EXTRAVERSION"
1497 packages=$(($packages+1))
1498 fi
1499 done
1500 separator
1501 eval_gettext "\$packages packages installed of category \$ASKED_CATEGORY_I18N."; echo
1502 echo ""
1503 else
1504 # By default list all packages and versions.
1505 echo ""
1506 echo -e "\033[1m`gettext \"List of all installed packages\"`\033[0m"
1507 separator
1508 for pkg in $INSTALLED/*
1509 do
1510 [ -f $pkg/receipt ] || continue
1511 EXTRAVERSION=""
1512 . $pkg/receipt
1513 echo -n "$PACKAGE"
1514 echo -en "\033[24G $VERSION$EXTRAVERSION"
1515 echo -e "\033[42G `translate_category $CATEGORY`"
1516 packages=$(($packages+1))
1517 done
1518 separator
1519 eval_gettext "\$packages packages installed."; echo
1520 echo ""
1521 fi ;;
1522 xhtml-list)
1523 # Get info in receipts and build list.
1524 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
1525 if [ -n "$2" ]; then
1526 XHTML_LIST=$2
1527 else
1528 XHTML_LIST=installed-packages.html
1529 fi
1530 echo ""
1531 echo -e "\033[1m`gettext \"Creating xHTML list of installed packages\"`\033[0m"
1532 separator
1533 gettext "Generating xHTML header..."
1534 xhtml_header
1535 status
1536 # Packages
1537 gettext "Creating packages information..."
1538 for pkg in $INSTALLED/*
1539 do
1540 [ -f $pkg/receipt ] || continue
1541 EXTRAVERSION=""
1542 . $pkg/receipt
1543 xhtml_pkg_info
1544 packages=$(($packages+1))
1545 done
1546 status
1547 gettext "Generating xHTML footer..."
1548 xhtml_footer
1549 status
1550 # sed pkgs nb in header.
1551 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
1552 separator
1553 eval_gettext "\$XHTML_LIST created - $packages packages."; echo
1554 echo "" ;;
1555 list-mirror)
1556 # List all available packages on the mirror. Option --diff displays
1557 # last mirrored packages diff (see recharge).
1558 check_for_packages_list
1559 case $2 in
1560 --diff)
1561 if [ -f "$LOCALSTATE/packages.diff" ]; then
1562 echo ""
1563 echo -e "\033[1m`gettext \"Mirrored packages diff\"`\033[0m"
1564 separator
1565 cat $LOCALSTATE/packages.diff
1566 separator
1567 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
1568 eval_gettext "\$pkgs new packages listed on the mirror."; echo
1569 echo ""
1570 else
1571 echo ""
1572 gettext "Unable to list anything, no packages.diff found."; echo
1573 gettext "Recharge your current list to create a first diff."; echo
1574 echo ""
1575 fi && exit 0 ;;
1576 --text|--txt)
1577 echo ""
1578 echo -e "\033[1m`gettext \"List of available packages on the mirror\"`\033[0m"
1579 separator
1580 cat $LOCALSTATE/packages.txt ;;
1581 --raw|*)
1582 echo ""
1583 echo -e "\033[1m`gettext \"List of available packages on the mirror\"`\033[0m"
1584 separator
1585 cat $LOCALSTATE/packages.list ;;
1586 esac
1587 separator
1588 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
1589 eval_gettext "\$pkgs packages in the last recharged list."; echo
1590 echo "" ;;
1591 list-files)
1592 # List files installed with the package.
1594 check_for_package_on_cmdline
1595 check_for_receipt
1596 echo ""
1597 echo -e "\033[1m`gettext \"Installed files with:\"`\033[0m $PACKAGE"
1598 separator
1599 cat $INSTALLED/$PACKAGE/files.list | sort
1600 separator
1601 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
1602 eval_gettext "\$files files installed with \$PACKAGE."; echo
1603 echo "" ;;
1604 info)
1605 # Information about package.
1607 check_for_package_on_cmdline
1608 check_for_receipt
1609 EXTRAVERSION=""
1610 . $INSTALLED/$PACKAGE/receipt
1611 echo ""
1612 echo -e "\033[1m`gettext \"Tazpkg information\"`\033[0m
1613 ================================================================================
1614 `gettext \"Package :\"` $PACKAGE
1615 `gettext \"Version :\"` $VERSION$EXTRAVERSION
1616 `gettext \"Category :\"` `translate_category $CATEGORY`
1617 `gettext \"Short desc :\"` $SHORT_DESC
1618 `gettext \"Maintainer :\"` $MAINTAINER"
1619 if [ "$DEPENDS" ]; then
1620 echo -e "`gettext \"Depends :\"` $DEPENDS"
1621 fi
1622 if [ "$SUGGESTED" ]; then
1623 echo -e "`gettext \"Suggested :\"` $SUGGESTED"
1624 fi
1625 if [ "$BUILD_DEPENDS" ]; then
1626 echo -e "`gettext \"Build deps :\"` $BUILD_DEPENDS"
1627 fi
1628 if [ "$WANTED" ]; then
1629 echo -e "`gettext \"Wanted src :\"` $WANTED"
1630 fi
1631 if [ "$WEB_SITE" ]; then
1632 echo -e "`gettext \"Web site :\"` $WEB_SITE"
1633 fi
1634 separator
1635 echo "" ;;
1636 desc)
1637 # Display package description.txt if available.
1638 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1639 echo ""
1640 echo -e "\033[1m`gettext \"Description of:\"`\033[0m $PACKAGE"
1641 separator
1642 cat $INSTALLED/$PACKAGE/description.txt
1643 separator
1644 echo ""
1645 else
1646 echo ""
1647 gettext "Sorry, no description available for this package."; echo
1648 echo ""
1649 fi ;;
1650 search)
1651 # Search for a package by pattern or name.
1653 PATTERN="$2"
1654 if [ -z "$PATTERN" ]; then
1655 echo ""
1656 gettext "Please specify a pattern or package name to search for."; echo
1657 gettext "Example : 'tazpkg search paint'"; echo
1658 echo ""
1659 exit 0
1660 fi
1661 echo ""
1662 echo -e "\033[1m`gettext \"Search result for:\"`\033[0m $PATTERN"
1663 echo ""
1664 # Default is to search in installed pkgs and the raw list.
1665 case $3 in
1666 -i|--installed)
1667 search_in_installed_packages ;;
1668 -l|--list)
1669 search_in_packages_list ;;
1670 -m|--mirror)
1671 search_in_packages_txt ;;
1672 *)
1673 search_in_installed_packages
1674 search_in_packages_list ;;
1675 esac ;;
1676 search-file)
1677 # Search for a file by pattern or name in all files.list.
1679 if [ -z "$2" ]; then
1680 echo ""
1681 gettext "Please specify a pattern or file name to search for."; echo
1682 gettext "Example : 'tazpkg search-file libnss'"; echo
1683 echo ""
1684 exit 0
1685 fi
1686 echo ""
1687 echo -e "\033[1m`gettext \"Search result for file\"`\033[0m $2"
1688 separator
1690 if [ "$3" == "--mirror" ]; then
1692 match=0
1693 for i in $LOCALSTATE/files.list.lzma \
1694 $LOCALSTATE/undigest/*/files.list.lzma; do
1695 [ -f $i ] || continue
1696 unlzma -c $i | grep -- ".*:.*$2" | awk '
1697 BEGIN { last="" }
1699 pkg=substr($0,0,index($0,":")-1);
1700 file=substr($0,index($0,":")+2);
1701 if (last != pkg) {
1702 last = pkg;
1703 printf("\n%c[1mPackage %s :%c[0m\n",27,pkg,27);
1705 printf("%s\n",file);
1706 }'
1707 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | wc -l`))
1708 done
1710 else
1712 # Check all pkg files.list in search match which specify the package
1713 # name and the full path to the file(s).
1714 for pkg in $INSTALLED/*
1715 do
1716 if grep -qs "$2" $pkg/files.list; then
1717 . $pkg/receipt
1718 echo ""
1719 echo -e "\033[1m`gettext \"Package\"` $PACKAGE:\033[0m"
1720 grep "$2" $pkg/files.list
1721 files=`grep $2 $pkg/files.list | wc -l`
1722 match=$(($match+$files))
1723 fi
1724 done
1726 fi
1727 pkg=$2
1728 if [ "$match" = "" ]; then
1729 eval_gettext "0 file found for: \$pkg"; echo
1730 echo ""
1731 else
1732 echo ""
1733 separator
1734 eval_gettext "\$match file(s) found for: \$pkg"; echo
1735 echo ""
1736 fi ;;
1737 search-pkgname)
1738 # Search for a package name
1739 if [ -z "$2" ]; then
1740 echo ""
1741 gettext "Please specify a pattern or file name to search for."; echo
1742 gettext "Example : 'tazpkg search-pkgname libnss'"; echo
1743 echo ""
1744 exit 0
1745 fi
1746 echo ""
1747 echo -e "\033[1m`gettext \"Search result for file\"`\033[0m $2"
1748 separator
1750 # Search for a file on mirror and output only the package name
1751 match=0
1752 for i in $LOCALSTATE/files.list.lzma \
1753 $LOCALSTATE/undigest/*/files.list.lzma; do
1754 [ -f $i ] || continue
1755 unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | awk '{ print $1 }'
1756 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | wc -l`))
1757 done
1758 file=$2
1759 if [ "$match" = "" ]; then
1760 eval_gettext "0 file found for : \$file"; echo
1761 echo ""
1762 else
1763 echo ""
1764 separator
1765 eval_gettext "$match pkg(s) found with file: \$file"; echo
1766 echo ""
1767 fi
1768 ;;
1769 install)
1770 # Install .tazpkg packages.
1772 check_root
1773 check_for_package_on_cmdline
1774 check_for_package_file
1776 get_options_list="root forced list rootconfig"
1777 get_options
1779 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
1780 [ "$list" ] && INSTALL_LIST="$list"
1781 if [ "$rootconfig" ]; then
1782 if [ "$root" ]; then
1783 CACHE_DIR=$root/$CACHE_DIR
1784 SAVE_CACHE_DIR=$CACHE_DIR
1785 LOCALSTATE=$root/$LOCALSTATE
1786 else
1787 echo "rootconfig needs --root= option used." >&2
1788 exit 1
1789 fi
1790 fi
1792 # Get repositories priority list.
1793 look_for_priority
1795 # Check if forced install.
1796 if ! [ "$forced" ]; then
1797 check_for_installed_package $ROOT
1798 fi
1799 install_package $ROOT
1800 update_desktop_database $ROOT
1801 update_mime_database $ROOT ;;
1802 install-list|get-install-list)
1803 # Install a set of packages from a list.
1805 check_root
1806 if [ -z "$2" ]; then
1807 echo ""
1808 gettext \
1809 "Please change directory (cd) to the packages repository and specify the
1810 list of packages to install. Example : tazpkg install-list packages.list"
1811 echo "" && exit 0
1812 fi
1813 # Check if the packages list exist.
1814 list_file=$2
1815 if [ ! -f "$list_file" ]; then
1816 gettext "Unable to find : $list_file"; echo
1817 exit 0
1818 else
1819 LIST=`cat $2`
1820 fi
1822 # Remember processed list
1823 export INSTALL_LIST="$2"
1825 # Set $COMMAND and install all packages.
1826 if [ "$1" = "get-install-list" ]; then
1827 COMMAND=get-install
1828 else
1829 COMMAND=install
1830 fi
1831 touch $2-processed
1833 # Upgrade tazpkg first. It may handle new features/formats...
1834 # then upgrade essential packages early
1835 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1836 slitaz-base-files tazpkg ; do
1837 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1838 [ -n "$pkg" ] || continue
1839 eval_gettext "Adding implicit depends \$pkg ..."; echo
1840 LIST="$pkg
1841 $LIST"
1842 done
1844 for pkg in $LIST
1845 do
1846 grep -qs ^$pkg$ $2-processed && continue
1847 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1848 done
1849 rm -f $2-processed ;;
1850 add-flavor)
1851 # Install a set of packages from a flavor.
1853 install_flavor $2 ;;
1854 install-flavor)
1855 # Install a set of packages from a flavor and purge other ones.
1857 install_flavor $2 --purge ;;
1858 set-release)
1859 # Change curent release and upgrade packages.
1861 RELEASE=$2
1862 if [ -z "$RELEASE" ]; then
1863 echo ""
1864 gettext "Please specify the release you want on the command line."; echo
1865 gettext "Example: tazpkg set-release cooking"; echo
1866 echo ""
1867 exit 0
1868 fi
1869 rm $LOCALSTATE/mirror
1870 echo "$RELEASE" > /etc/slitaz-release
1871 tazpkg recharge && tazpkg upgrade
1873 # Install missing depends
1874 cd $INSTALLED
1875 for i in * ; do
1876 DEPENDS=""
1877 . $i/receipt
1878 for j in $DEPENDS ; do
1879 [ -d $j ] || tazpkg get-install $j
1880 done
1881 done ;;
1882 remove)
1883 # Remove packages.
1885 check_root
1886 check_for_package_on_cmdline
1887 get_options_list="root auto"
1888 get_options
1889 [ "$root" ] && ROOT="$root"
1890 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1891 echo ""
1892 eval_gettext "\$PACKAGE is not installed."; echo
1893 exit 0
1894 else
1895 ALTERED=""
1896 THE_PACKAGE=$PACKAGE # altered by receipt
1897 for i in $(cd $ROOT$INSTALLED ; ls); do
1898 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1899 DEPENDS=""
1900 . $ROOT$INSTALLED/$i/receipt
1901 case " $(echo $DEPENDS) " in
1902 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1903 esac
1904 done
1905 EXTRAVERSION=""
1906 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1907 fi
1908 echo ""
1909 if [ -n "$ALTERED" ]; then
1910 eval_gettext "The following packages depend on \$PACKAGE:"; echo
1911 for i in $ALTERED; do
1912 echo " $i"
1913 done
1914 fi
1915 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1916 if [ -n "$REFRESH" ]; then
1917 eval_gettext "The following packages have been modified by \$PACKAGE:"; echo
1918 for i in $REFRESH; do
1919 echo " ${i%/modifiers}"
1920 done
1921 fi
1922 if [ "$auto" ]; then
1923 answer=`translate_querry y`
1924 else
1925 eval_gettext "Remove \$PACKAGE (\$VERSION\$EXTRAVERSION) ?"; echo
1926 gettext "Please confirm uninstallation"
1927 echo -n " (`translate_querry y`/`translate_querry N`) : "; read answer
1928 fi
1929 if [ "$answer" = "$(translate_querry y)" ]; then
1930 echo ""
1931 echo -e "\033[1m`gettext \"Removing:\"`\033[0m $PACKAGE"
1932 separator
1933 # Pre remove commands.
1934 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1935 pre_remove
1936 fi
1937 gettext "Removing all files installed..."
1938 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1939 for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
1940 do
1941 for mod in `cat $ROOT$INSTALLED/$PACKAGE/modifiers`
1942 do
1943 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1944 done
1945 remove_with_path $ROOT$file
1946 done
1947 else
1948 for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
1949 do
1950 remove_with_path $ROOT$file
1951 done
1952 fi
1953 status
1954 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1955 post_remove
1956 fi
1957 # Remove package receipt.
1958 gettext "Removing package receipt..."
1959 rm -rf $ROOT$INSTALLED/$PACKAGE
1960 status
1961 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1962 $LOCALSTATE/installed.md5 2> /dev/null
1963 # Log this activity
1964 log Removed
1965 if [ "$ALTERED" ]; then
1966 if [ "$auto" ]; then
1967 answer=`translate_querry y`
1968 else
1969 eval_gettext "Remove packages depending on \$PACKAGE"
1970 echo -n " (`translate_querry y`/`translate_querry N`) ? "
1971 read answer
1972 fi
1973 if [ "$answer" = "$(translate_querry y)" ]; then
1974 for i in $ALTERED; do
1975 if [ -d "$ROOT$INSTALLED/$i" ]; then
1976 tazpkg remove $i $ROOTOPTS
1977 fi
1978 done
1979 fi
1980 fi
1981 if [ "$REFRESH" ]; then
1982 if [ "$auto" ]; then
1983 answer=`translate_querry y`
1984 else
1985 eval_gettext "Reinstall packages modified by \$PACKAGE"
1986 echo -n " (`translate_querry y`/`translate_querry N`) ? "
1987 read answer
1988 fi
1989 if [ "$answer" = "$(translate_querry y)" ]; then
1990 for i in $REFRESH; do
1991 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1992 eval_gettext "Check \$INSTALLED/\$i for reinstallation"; echo
1993 continue
1994 fi
1995 rm -r $ROOT$INSTALLED/$i
1996 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1997 done
1998 fi
1999 fi
2000 else
2001 echo ""
2002 eval_gettext "Uninstallation of \$PACKAGE cancelled."; echo
2003 fi
2004 echo "" ;;
2005 extract)
2006 # Extract .tazpkg cpio archive into a directory.
2008 check_for_package_on_cmdline
2009 check_for_package_file
2010 echo ""
2011 echo -e "\033[1m`gettext \"Extracting:\"`\033[0m $PACKAGE"
2012 separator
2013 # If no directory destination is found on the cmdline
2014 # we create one in the current dir using the package name.
2015 if [ -n "$TARGET_DIR" ]; then
2016 DESTDIR=$TARGET_DIR/$PACKAGE
2017 else
2018 DESTDIR=$PACKAGE
2019 fi
2020 mkdir -p $DESTDIR
2021 gettext "Copying original package..."
2022 cp $PACKAGE_FILE $DESTDIR
2023 status
2024 cd $DESTDIR
2025 extract_package
2026 separator
2027 eval_gettext "\$PACKAGE is extracted to: \$DESTDIR"; echo
2028 echo "" ;;
2029 recompress)
2030 # Recompress .tazpkg cpio archive with lzma.
2032 check_for_package_on_cmdline
2033 check_for_package_file
2034 echo ""
2035 echo -e "\033[1m`gettext \"Recompressing:\"`\033[0m $PACKAGE"
2036 separator
2037 mkdir -p $TMP_DIR
2038 gettext "Copying original package..."
2039 cp $PACKAGE_FILE $TMP_DIR
2040 status
2041 cd $TMP_DIR
2042 extract_package
2043 gettext "Recompressing the fs... "
2044 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2045 rm -rf fs
2046 status
2047 gettext "Creating new package... "
2048 find . -print | cpio -o -H newc --quiet > \
2049 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
2050 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
2051 $TOP_DIR/$(basename $PACKAGE_FILE)
2052 status
2053 cd $TOP_DIR
2054 rm -rf $TMP_DIR ;;
2055 list-config)
2056 # List configuration files installed.
2058 if [ "$2" = "--box" ]; then
2059 mkdir -p $TMP_DIR && cd $TMP_DIR
2060 FILES="$INSTALLED/*/volatile.cpio.gz"
2061 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
2062 for i in $FILES; do
2063 zcat $i | cpio -idm --quiet > /dev/null
2064 find * -type f 2>/dev/null | while read file; do
2065 if [ ! -e /$file ]; then
2066 echo -en "|--|--|--|`gettext \"File lost\"`"
2067 else
2068 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
2069 cmp $file /$file > /dev/null 2>&1 || \
2070 echo -n "$(stat -c "%.16y" /$file)"
2071 fi
2072 echo "|/$file"
2073 done
2074 rm -rf *
2075 done
2076 cd $TOP_DIR
2077 rm -rf $TMP_DIR
2078 else
2079 echo ""
2080 echo -e "\033[1m`gettext \"Configuration files\"`\033[0m"
2081 separator
2082 for i in $INSTALLED/*/volatile.cpio.gz; do
2083 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
2084 [ -f "$i" ] || continue
2085 zcat $i | cpio -t --quiet
2086 done | sed 's|^|/|' | sort
2087 separator
2088 echo ""
2089 fi ;;
2090 repack-config)
2091 # Create SliTaz package archive from configuration files.
2093 mkdir -p $TMP_DIR && cd $TMP_DIR
2094 CONFIG_VERSION=1.0
2095 mkdir config-$CONFIG_VERSION
2096 cd config-$CONFIG_VERSION
2097 for i in $INSTALLED/*/volatile.cpio.gz; do
2098 zcat $i | cpio -t --quiet
2099 done > files.list
2100 mkdir fs
2101 cd fs
2102 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2103 mkdir -p etc/tazlito
2104 for i in $INSTALLED/*/receipt; do
2105 EXTRAVERSION=""
2106 . $i
2107 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2108 done > etc/tazlito/config-packages.list
2109 cd ..
2110 echo "etc/tazlito/config-packages.list" >> files.list
2111 cat > receipt <<EOT
2112 # SliTaz package receipt.
2114 PACKAGE="config"
2115 VERSION="$CONFIG_VERSION"
2116 CATEGORY="base-system"
2117 SHORT_DESC="$(gettext "User configuration backup on ")$(date)"
2118 DEPENDS="$(ls $INSTALLED)"
2119 EOT
2120 cd ..
2121 tazpkg pack config-$CONFIG_VERSION
2122 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2123 cd $TOP_DIR
2124 rm -rf $TMP_DIR
2125 ;;
2126 repack)
2127 # Create SliTaz package archive from an installed package.
2129 check_for_package_on_cmdline
2130 check_for_receipt
2131 EXTRAVERSION=""
2132 . $INSTALLED/$PACKAGE/receipt
2133 echo ""
2134 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
2135 separator
2136 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2137 eval_gettext "Can't repack \$PACKAGE"; echo
2138 exit 1
2139 fi
2140 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2141 eval_gettext "Can't repack, \$PACKAGE files have been modified by:"; echo
2142 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2143 echo " $i"
2144 done
2145 exit 1
2146 fi
2147 MISSING=""
2148 while read i; do
2149 [ -e "$i" ] && continue
2150 [ -L "$i" ] || MISSING="$MISSING\n $i"
2151 done < $INSTALLED/$PACKAGE/files.list
2152 if [ -n "$MISSING" ]; then
2153 gettext "Can't repack, the following files are lost:"
2154 echo -e "$MISSING"
2155 exit 1
2156 fi
2157 mkdir -p $TMP_DIR && cd $TMP_DIR
2158 FILES="fs.cpio.lzma\n"
2159 for i in $(ls $INSTALLED/$PACKAGE) ; do
2160 [ "$i" = "volatile.cpio.gz" ] && continue
2161 [ "$i" = "modifiers" ] && continue
2162 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
2163 done
2164 ln -s / rootfs
2165 mkdir tmp
2166 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet |\
2167 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2168 mv tmp/rootfs fs
2169 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2170 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2171 { cd fs; cpio -idm --quiet; cd ..; }
2172 fi
2173 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2174 . $INSTALLED/$PACKAGE/receipt
2175 repack_cleanup fs
2176 fi
2177 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
2178 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
2179 md5sum -s -c || {
2180 gettext "Can't repack, md5sum error."; echo
2181 cd $TOP_DIR
2182 rm -rf $TMP_DIR
2183 exit 1
2185 fi
2186 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2187 echo -e "$FILES" | cpio -o -H newc --quiet > \
2188 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2189 cd $TOP_DIR
2190 \rm -R $TMP_DIR
2191 eval_gettext "Package \$PACKAGE repacked successfully."; echo
2192 echo -e "`gettext \"Size\"` : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
2193 echo "" ;;
2194 pack)
2195 # Create SliTaz package archive using cpio and gzip.
2197 check_for_package_on_cmdline
2198 cd $PACKAGE
2199 if [ ! -f "receipt" ]; then
2200 gettext "Receipt is missing. Please read the documentation."; echo
2201 exit 0
2202 else
2203 echo ""
2204 echo -e "\033[1mPacking :\033[0m $PACKAGE"
2205 separator
2206 # Create files.list with redirecting find outpout.
2207 gettext "Creating the list of files..." && cd fs
2208 find . -type f -print > ../files.list
2209 find . -type l -print >> ../files.list
2210 cd .. && sed -i s/'^.'/''/ files.list
2211 status
2212 gettext "Creating md5sum of files..."
2213 while read file; do
2214 [ -L "fs$file" ] && continue
2215 [ -f "fs$file" ] || continue
2216 case "$file" in
2217 /lib/modules/*/modules.*|*.pyc) continue;;
2218 esac
2219 md5sum "fs$file" | sed 's/ fs/ /'
2220 done < files.list > md5sum
2221 status
2222 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
2223 description.txt 2> /dev/null | awk \
2224 '{ sz=$1 } END { print sz }')
2225 # Build cpio archives.
2226 gettext "Compressing the fs... "
2227 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2228 rm -rf fs
2229 status
2230 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2231 md5sum description.txt 2> /dev/null | awk \
2232 '{ sz=$1 } END { print sz }')
2233 gettext "Updating receipt sizes..."
2234 sed -i s/^PACKED_SIZE.*$// receipt
2235 sed -i s/^UNPACKED_SIZE.*$// receipt
2236 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2237 status
2238 gettext "Creating full cpio archive... "
2239 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2240 status
2241 gettext "Restoring original package tree... "
2242 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2243 status
2244 rm fs.cpio.lzma && cd ..
2245 separator
2246 eval_gettext "Package \$PACKAGE compressed successfully."; echo
2247 echo "`gettext \"Size\"` : `du -sh $PACKAGE.tazpkg`"
2248 echo ""
2249 fi ;;
2250 recharge)
2251 # Recharge packages.list from a mirror.
2253 check_root
2254 get_options_list="root forced list rootconfig"
2255 get_options
2256 ARG=$2
2257 if [ "$root" ]; then
2258 LOCALSTATE=$root$LOCALSTATE
2259 [ "${2#--}" != "$2" ] && ARG=$3
2260 fi
2261 if [ "$ARG" = main ]; then
2262 repository_to_recharge=$LOCALSTATE
2263 elif [ "$ARG" ]; then
2264 if [ -d "$LOCALSTATE/undigest/$ARG" ]; then
2265 repository_to_recharge=$LOCALSTATE/undigest/$ARG
2266 else
2267 echo "\$LOCALSTATE/undigest/$ARG `gettext \"doesn't exist.\"`" >&2
2268 exit 1
2269 fi
2270 else
2271 repository_to_recharge="$LOCALSTATE $LOCALSTATE/undigest/*"
2272 fi
2273 for path in $repository_to_recharge; do
2274 [ -f $path/mirror ] || continue
2275 cd $path
2277 # Quietly check if recharging is needed.
2278 [ -f ID ] && mv ID ID.bak
2279 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2280 if [ -f ID ] && fgrep -q `cat ID.bak 2>/dev/null || echo "null"` ID; then
2281 if [ "$path" = "$LOCALSTATE" ]; then
2282 repository_name=Main
2283 else
2284 repository_name="`gettext \"Undigest\"` $(basename $path)"
2285 fi
2286 echo "$repository_name `gettext \"is up to date.\"`"
2287 rm ID.bak
2288 continue
2289 fi
2291 # Don't let ID be a symlink when using local repository.
2292 if [ -f ID ]; then
2293 mv -f ID ID.bak
2294 cat ID.bak > ID
2295 rm ID.bak
2296 fi
2298 echo ""
2299 if [ "$path" != "$LOCALSTATE" ]; then
2300 echo -e "`gettext \"Recharging undigest\"` $(basename $path):"
2301 fi
2303 if [ -f "packages.list" ]; then
2304 gettext "Creating backup of the last packages list..."
2305 for i in wanted.txt depends.txt libraries.txt \
2306 packages.desc packages.md5 packages.txt \
2307 packages.list packages.equiv files.list.lzma \
2308 mirrors; do
2309 mv -f $i $i.bak 2>/dev/null
2310 done
2311 status
2312 fi
2313 for i in desc md5 txt list equiv; do
2314 download_from "$(cat mirror)" packages.$i
2315 done
2317 download_from "$(cat mirror)" files.list.lzma
2319 # ID file & wanted/depends/libraries files were implemented
2320 # at the same time. Not all repositories have them.
2321 if [ -f ID ]; then
2322 for i in wanted depends library; do
2323 download_from "$(cat mirror)" $i.txt
2324 done
2325 fi
2327 download_from "$(sed 's|packages/.*||' < mirror)" mirrors
2328 [ -f mirrors ] || mv mirrors.bak mirrors 2> /dev/null
2329 suffix=$(head -1 mirror)
2330 suffix=packages${suffix#*/packages}
2331 for i in $(cat mirrors 2> /dev/null); do
2332 fgrep -qs $i mirror || echo $i$suffix >> mirror
2333 done
2334 if [ -f "packages.list.bak" ]; then
2335 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2336 sed -i s/+// packages.diff
2337 echo ""
2338 echo -e "\033[1m`gettext \"Mirrored packages diff\"`\033[0m"
2339 separator
2340 cat packages.diff
2341 new_pkgs=`cat packages.diff | wc -l`
2342 if [ "$new_pkgs" != 0 ]; then
2343 separator
2344 eval_gettext "\$new_pkgs new packages on the mirror."; echo
2345 echo ""
2346 else
2347 gettext "No new packages on the mirror."; echo
2348 echo ""
2349 fi
2350 else
2351 echo -e "
2352 ================================================================================"
2353 gettext \
2354 "Last packages.list is ready to use. Note that next time you recharge the
2355 list, a list of differences will be displayed to show new and upgradeable
2356 packages."
2357 echo ""
2358 fi
2359 done ;;
2360 up)
2362 # This is the new way to upgrade packages making 'upgrade' and
2363 # upgradeable out-of-date. This new way is much, much more faster!
2364 # Look into installed packages and get data from receipt, it is fast
2365 # and easy to handle vars after using only md5sum to compare packages
2367 # Options available for the command: up
2368 for opt in $@
2369 do
2370 case "$opt" in
2371 --recharge|-r)
2372 tazpkg recharge ;;
2373 --install|-i)
2374 install="y" ;;
2375 --check|-c)
2376 install="n" ;;
2377 esac
2378 done
2379 mtime=`find /var/lib/tazpkg/packages.list -mtime +7`
2380 if [ "$mtime" ]; then
2381 gettext "Your packages list is older than one week... recharging"
2382 tazpkg recharge
2383 fi
2384 echo -en "\n\033[1m"
2385 gettext "Package"
2386 echo -en "\033[26G " && gettext "Update type"
2387 echo -e "\033[0m"
2388 separator
2389 cd $LOCALSTATE/installed
2390 echo "" > $UP_LIST
2391 blocked_count=0
2392 for pkg in *
2393 do
2394 unset VERSION EXTRAVERSION
2395 . $pkg/receipt
2396 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2397 ../installed.md5 | awk '{print $1}')
2398 if ! fgrep -q "$md5 $PACKAGE-" ../packages.md5; then
2399 # Skip when not found on mirror (local package)
2400 grep -q ^$PACKAGE- ../packages.list || continue
2401 new=$(grep "^$PACKAGE |" ../packages.desc | awk '{print $3}')
2402 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2403 # Skip pkgs listed in $LOCALSTATE/blocked-packages.list
2404 blocked_count=$(($blocked_count+1))
2405 else
2406 if [ "$VERSION" == "$new" ]; then
2407 echo -n "$PACKAGE"
2408 echo -e "\\033[26G `gettext \"New build :\"` $md5"
2409 else
2410 echo -n "$PACKAGE"
2411 echo -e "\\033[26G `gettext \"New version :\"` $new"
2412 fi
2413 echo "$PACKAGE" >> $UP_LIST
2414 fi
2415 fi
2416 done
2417 sed -i /^$/d $UP_LIST
2418 upnb=$(cat $UP_LIST | wc -l)
2419 pkgs=$(ls | wc -l)
2420 if [ "$upnb" = 0 ]; then
2421 install="n"
2422 gettext -e "System is up-to-date...\n\n"
2423 else
2424 separator
2425 echo -en "\033[1m"
2426 if [ "$blocked_count" -gt 0 ]; then
2427 blocks=`eval_gettext " (\$blocked_count blocked)"`
2428 fi
2429 eval_gettext "You have \$upnb available upgrades\$blocks on \$pkgs installed packages"
2430 echo -e "\033[0m\n"
2431 fi
2432 # Pkgs to upgrade ? Skip, let install them all or ask user
2433 [ "$install" == "n" ] && exit 0
2434 if [ "$upnb" -gt 0 ]; then
2435 if [ "$install" == "y" ]; then
2436 continue
2437 else
2438 gettext "Do you wish to install them now: y/n ? "
2439 read install
2440 fi
2441 case "$install" in
2442 y|Y|yes|YES|Yes)
2443 for pkg in `cat $UP_LIST`
2444 do
2445 echo 'y' | tazpkg get-install $pkg --forced
2446 done ;;
2447 *)
2448 gettext -e "Leaving without any upgrades installed.\n\n"
2449 exit 0 ;;
2450 esac
2451 fi
2452 echo "" ;;
2453 upgradeable)
2454 # Build upgradeable-packages.list quickly.
2456 check_root
2457 cd $LOCALSTATE
2458 while read md5 file ; do
2459 fgrep -qs "$md5 $file" packages.md5 && continue
2460 for i in 1 2 3 4 5; do
2461 file=${file%-*}
2462 [ -d installed/$file ] || continue
2463 echo $file
2464 break
2465 done
2466 done < installed.md5 > upgradeable-packages.list.tmp
2467 uniq upgradeable-packages.list.tmp upgradeable-packages.list ;;
2468 upgrade)
2469 # Upgrade all installed packages with the new version from the mirror.
2471 check_root
2472 check_for_packages_list
2474 # Get repositories priority list.
2475 look_for_priority
2477 cd $LOCALSTATE
2478 # Touch the blocked pkgs list to avoid errors and remove any old
2479 # upgrade list.
2480 touch blocked-packages.list
2481 rm -f upgradeable-packages.list
2482 echo ""
2483 echo -e "\033[1m`gettext \"Available upgrades\"`\033[0m"
2484 separator
2485 echo ""
2486 # Some packages must be installed first
2487 FIRST_CLASS_PACKAGE=" glibc-base slitaz-base-files slitaz-boot-scripts "
2488 if [ -n "$PACKAGE_FILE" -a -d "$INSTALLED/$PACKAGE_FILE" ]; then
2489 ALL=$INSTALLED/$PACKAGE_FILE
2490 else
2491 ALL="$(ls -d $INSTALLED/*)"
2492 fi
2493 for pkg in $ALL
2494 do
2495 [ -f $pkg/receipt ] || continue
2496 EXTRAVERSION=""
2497 . $pkg/receipt
2498 # Display package name to show that Tazpkg is working...
2499 echo -en "\\033[0G "
2500 echo -en "\\033[0G$PACKAGE"
2501 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
2502 if grep -qs "^$PACKAGE" $BLOCKED; then
2503 blocked=$(($blocked+1))
2504 else
2505 # Check if the installed package is in the current list (other
2506 # mirror or local).
2507 NEW_PACKAGE=$(get_package_filename $PACKAGE)
2509 if [ -n "$NEW_PACKAGE" ]; then
2510 # Set new pkg and version for future comparison
2511 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
2512 # Change '-' and 'pre' to points.
2513 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
2514 VERSION=`echo $VERSION | sed s/'-'/'.'/`$EXTRAVERSION
2515 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
2516 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
2517 NEW_VERSION=`echo $NEW_VERSION | sed 's/[A-Z]\.//'`
2518 VERSION=`echo $VERSION | sed 's/[A-Z]\.//'`
2519 # Compare version. Upgrades are only available for official
2520 # packages, so we control the mirror and it should be ok if
2521 # we just check for equality.
2522 RELEASE=""
2523 if [ -f installed.md5 -a -f packages.md5 ]; then
2524 current_md5=$(fgrep -s " $PACKAGE-$VERSION" installed.md5 | awk '{ print $1 }')
2525 new_md5=$(fgrep -hs " $PACKAGE-$VERSION" packages.md5 undigest/*/packages.md5 | head -1 | awk '{ print $1 }')
2526 [ -n "$current_md5" ] && [ -n "$new_md5" ] &&
2527 [ "$current_md5" != "$new_md5" ] && RELEASE=$(gettext "build")
2528 fi
2529 if [ "$VERSION" != "$NEW_VERSION" -o -n "$RELEASE" ]; then
2530 # Version seems different. Check for major, minor or
2531 # revision
2532 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
2533 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
2534 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
2535 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
2536 # Minor
2537 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ] 2> /dev/null; then
2538 RELEASE=$(gettext "minor")
2539 fi
2540 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ] 2> /dev/null; then
2541 RELEASE=$(gettext "WARNING")
2542 FIXE=yes
2543 fi
2544 # Major
2545 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ] 2> /dev/null; then
2546 RELEASE=$(gettext "major")
2547 FIXE=""
2548 fi
2549 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ] 2> /dev/null; then
2550 RELEASE=$(gettext "WARNING")
2551 FIXE=yes
2552 fi
2553 # Default to revision.
2554 if [ -z $RELEASE ]; then
2555 RELEASE=$(gettext "revision")
2556 fi
2557 # Pkg name is already displayed by the check process.
2558 echo -en "\033[24G $VERSION"
2559 echo -en "\033[38G --->"
2560 echo -en "\033[43G $NEW_VERSION"
2561 echo -en "\033[58G `translate_category $CATEGORY`"
2562 echo -e "\033[72G $RELEASE"
2563 up=$(($up+1))
2564 echo "$PACKAGE" >> upgradeable-packages.list
2565 case "$FIRST_CLASS_PACKAGE" in
2566 *\ $PACKAGE\ *) echo "$PACKAGE" >> upgradeable-packages.list$$;;
2567 esac
2568 unset RELEASE
2569 fi
2570 packages=$(($packages+1))
2571 fi
2572 fi
2573 done
2574 if [ -z $blocked ]; then
2575 blocked=0
2576 fi
2577 # Clean last checked package and display summary.
2578 if [ ! "$up" = "" ]; then
2579 echo -e "\\033[0G "
2580 separator
2581 eval_gettext "\$packages installed and listed packages to consider, \$up to upgrade, \$blocked blocked."; echo
2582 echo ""
2583 else
2584 echo -e "\\033[0G`gettext \"System is up-to-date.\"` "
2585 echo ""
2586 separator
2587 eval_gettext "\$packages installed and listed packages to consider, 0 to upgrade, \$blocked blocked."; echo
2588 echo ""
2589 exit 0
2590 fi
2591 # What to do if major or minor version is smaller.
2592 if [ "$FIXE" == "yes" ]; then
2593 gettext \
2594 "WARNING ---> Installed package seems more recent than the mirrored
2595 one. You can block packages using the command : 'tazpkg block package'.
2596 Or upgrade packages at your own risk."
2597 echo ""
2598 fi
2599 # Ask for upgrade, it can be done another time.
2600 gettext "Upgrade now"
2601 echo -n " (`translate_querry y`/`translate_querry N`) ? "
2602 read answer
2603 if [ ! "$answer" = "$(translate_querry y)" ]; then
2604 echo ""
2605 gettext "Exiting. No package upgraded."; echo
2606 echo ""
2607 exit 0
2608 fi
2609 # If answer is yes (y). Install all new versions.
2610 cat upgradeable-packages.list >> upgradeable-packages.list$$
2611 mv -f upgradeable-packages.list$$ upgradeable-packages.list
2612 yes y | tazpkg get-install-list upgradeable-packages.list --forced
2613 rm -f upgradeable-packages.list ;;
2614 bugs)
2615 # Show known bugs in package(s)
2617 cd $INSTALLED
2618 shift
2619 LIST=$@
2620 [ -n "$LIST" ] || LIST=`ls`
2621 MSG=$(gettext "No known bugs.")
2622 for PACKAGE in $LIST; do
2623 BUGS=""
2624 EXTRAVERSION=""
2625 . $PACKAGE/receipt
2626 if [ -n "$BUGS" ]; then
2627 MSG=$(gettext "Bug list completed")
2628 echo ""
2629 eval_gettext "Bugs in package \$PACKAGE version \$VERSION\$EXTRAVERSION:"; echo
2630 cat <<EOT
2631 $BUGS
2632 EOT
2633 fi
2634 done
2635 echo "$MSG" ;;
2636 check)
2637 # Check installed packages set.
2639 check_root
2641 # Get repositories priority list.
2642 look_for_priority
2644 cd $INSTALLED
2645 for PACKAGE in `ls`; do
2646 if [ ! -f $PACKAGE/receipt ]; then
2647 eval_gettext "The package \$PACKAGE installation has not completed"; echo
2648 continue
2649 fi
2650 DEPENDS=""
2651 EXTRAVERSION=""
2652 . $PACKAGE/receipt
2653 if [ -s $PACKAGE/modifiers ]; then
2654 eval_gettext \
2655 "The package \$PACKAGE \$VERSION\$EXTRAVERSION has been modified by:"; echo
2656 for i in $(cat $PACKAGE/modifiers); do
2657 echo " $i"
2658 done
2659 fi
2660 MSG="$(eval_gettext "Files lost from \$PACKAGE \$VERSION\$EXTRAVERSION :")\n"
2661 while read file; do
2662 [ -e "$file" ] && continue
2663 if [ -L "$file" ]; then
2664 MSG="$MSG $(gettext "target of symlink")"
2665 fi
2666 echo -e "$MSG $file"
2667 MSG=""
2668 done < $PACKAGE/files.list
2669 MSG="$(gettext "Missing dependencies for") $PACKAGE $VERSION$EXTRAVERSION :\n"
2670 for i in $DEPENDS; do
2671 [ -d $i ] && continue
2672 [ -d $(equivalent_pkg $i) ] && continue
2673 echo -e "$MSG $i"
2674 MSG=""
2675 done
2676 MSG="$(gettext "Dependencies loop between") $PACKAGE and :\n"
2677 ALL_DEPS=""
2678 check_for_deps_loop $PACKAGE $DEPENDS
2679 done
2680 gettext "Looking for known bugs... "; echo
2681 tazpkg bugs
2682 if [ "$PACKAGE_FILE" = "--full" ]; then
2683 for file in */md5sum; do
2684 CONFIG_FILES=""
2685 . $(dirname "$file")/receipt
2686 [ -s "$file" ] || continue
2687 while read md5 f; do
2688 [ -f $f ] || continue
2689 for i in $CONFIG_FILES; do
2690 case "$f" in
2691 $i|$i/*) continue 2;;
2692 esac
2693 done
2694 echo "$md5 $f"
2695 done < "$file" | md5sum -c - 2> /dev/null | \
2696 grep -v OK$ | sed 's/FAILED$/MD5SUM MISMATCH/'
2697 done
2698 FILES=" "
2699 for file in $(cat */files.list); do
2700 [ -d "$file" ] && continue
2701 case "$FILES" in *\ $file\ *) continue;; esac
2702 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2703 wc -l) -gt 1 ] || continue
2704 FILES="$FILES$file "
2705 eval_gettext "The following packages provide \$file :"; echo
2706 grep -l "^$(echo $file | grepesc)$" */files.list | while read f
2707 do
2708 pkg=${f%/files.list}
2709 echo -n " $pkg"
2710 if [ -f $pkg/modifiers ]; then
2711 echo -en " (`gettext \"overridden by\"`) $(echo "$(cat $pkg/modifiers)"))"
2712 fi
2713 echo ""
2714 done
2715 done
2716 MSG="$(gettext "No package has installed the following files"):\n"
2717 find /etc /bin /sbin /lib /usr /var/www \
2718 -not -type d 2> /dev/null | while read file; do
2719 case "$file" in *\[*) continue;; esac
2720 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2721 echo -e "$MSG $file"
2722 MSG=""
2723 done
2724 fi
2725 gettext "Check completed."; echo ;;
2726 block)
2727 # Add a pkg name to the list of blocked packages.
2729 check_root
2730 check_for_package_on_cmdline
2731 echo ""
2732 if grep -qs "^$PACKAGE" $BLOCKED; then
2733 eval_gettext "\$PACKAGE is already in the blocked packages list."; echo
2734 echo ""
2735 exit 0
2736 else
2737 eval_gettext "Add \$PACKAGE to : \$BLOCKED..."
2738 echo $PACKAGE >> $BLOCKED
2739 status
2740 # Log this activity
2741 . $INSTALLED/$PACKAGE/receipt
2742 log Blocked
2743 fi
2744 echo "" ;;
2745 unblock)
2746 # Remove a pkg name from the list of blocked packages.
2748 check_root
2749 check_for_package_on_cmdline
2750 echo ""
2751 if grep -qs "^$PACKAGE" $BLOCKED; then
2752 eval_gettext "Removing \$PACKAGE from : \$BLOCKED..."
2753 sed -i s/$PACKAGE/''/ $BLOCKED
2754 sed -i '/^$/d' $BLOCKED
2755 status
2756 # Log this activity
2757 . $INSTALLED/$PACKAGE/receipt
2758 log Unblocked
2759 else
2760 eval_gettext "\$PACKAGE is not in the blocked packages list."; echo
2761 echo ""
2762 exit 0
2763 fi
2764 echo "" ;;
2765 get)
2766 # Downlowd a package with wget.
2768 check_root
2769 check_for_package_on_cmdline
2770 check_for_packages_list
2772 get_options_list="root rootconfig"
2773 get_options
2775 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2776 if [ "$rootconfig" ]; then
2777 if [ "$root" ]; then
2778 CACHE_DIR=$root/$CACHE_DIR
2779 SAVE_CACHE_DIR=$CACHE_DIR
2780 LOCALSTATE=$root/$LOCALSTATE
2781 else
2782 echo "rootconfig needs --root= option used." >&2
2783 exit 1
2784 fi
2785 fi
2787 # Get repositories priority list.
2788 look_for_priority
2790 CURRENT_DIR=$PWD
2791 check_for_package_in_list
2792 cd $CACHE_DIR
2793 if [ -f "$PACKAGE.tazpkg" ]; then
2794 eval_gettext "\$PACKAGE already in the cache : \$CACHE_DIR"; echo
2795 # Check package download was finished
2796 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2797 eval_gettext "Continuing \$PACKAGE download"; echo
2798 download $PACKAGE.tazpkg
2800 if [ "$(md5sum $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.md5)" ]; then
2801 rm -f $PACKAGE.tazpkg
2802 download $PACKAGE.tazpkg
2803 fi
2804 else
2805 download $PACKAGE.tazpkg
2806 fi
2807 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2808 cp -a $PACKAGE_FILE $CURRENT_DIR
2809 ;;
2810 get-install)
2811 # Download and install a package.
2813 check_root
2814 check_for_package_on_cmdline
2815 check_for_packages_list
2817 get_options_list="root forced list rootconfig"
2818 get_options
2820 DO_CHECK=""
2821 [ "$forced" ] && DO_CHECK=no
2822 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2823 [ "$list" ] && INSTALL_LIST="$list"
2824 if [ "$rootconfig" ]; then
2825 if [ "$root" ]; then
2826 CACHE_DIR=$root/$CACHE_DIR
2827 SAVE_CACHE_DIR=$CACHE_DIR
2828 LOCALSTATE=$root/$LOCALSTATE
2829 else
2830 echo "rootconfig needs --root= option used." >&2
2831 exit 1
2832 fi
2833 fi
2835 # Get repositories priority list.
2836 look_for_priority
2838 AUTOEXEC="no"
2839 if ! check_for_package_in_list check; then
2840 PACKAGE=get-$PACKAGE
2841 AUTOEXEC=$PACKAGE
2842 check_for_package_in_list
2843 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2844 CACHE_DIR="${CACHE_DIR%/*}/get"
2845 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2846 $AUTOEXEC $ROOT
2847 exit 0
2848 fi
2849 fi
2850 # Check if forced install.
2851 if ! [ "$forced" ]; then
2852 check_for_installed_package $ROOT
2853 fi
2854 cd $CACHE_DIR
2855 if [ -f "$PACKAGE.tazpkg" ]; then
2856 eval_gettext "\$PACKAGE already in the cache : \$CACHE_DIR"; echo
2857 # Check package download was finished
2858 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2859 eval_gettext "Continuing \$PACKAGE download"; echo
2860 download $PACKAGE.tazpkg
2862 if [ "$(md5sum $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.md5)" ]; then
2863 rm -f $PACKAGE.tazpkg
2864 download $PACKAGE.tazpkg
2865 fi
2866 else
2867 echo ""
2868 download $PACKAGE.tazpkg
2869 fi
2870 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2871 [ "$rootconfig" ] && LOCALSTATE=${LOCALSTATE#$root}
2872 install_package $ROOT
2873 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2874 update_desktop_database $ROOT
2875 update_mime_database $ROOT ;;
2876 clean-cache)
2877 # Remove all downloaded packages.
2879 check_root
2880 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2881 echo ""
2882 echo -e "\033[1m`gettext \"Clean cache:\"`\033[0m $CACHE_DIR"
2883 separator
2884 gettext "Cleaning cache directory..."
2885 rm -rf $CACHE_DIR/*
2886 status && separator
2887 eval_gettext "\$files file(s) removed from cache."; echo -e "\n" ;;
2888 list-undigest)
2889 # list undigest URLs.
2891 if [ "$2" = "--box" ]; then
2892 for i in $LOCALSTATE/undigest/*/mirror; do
2893 [ -f $i ] || continue
2894 echo "$(basename $(dirname $i))|$(cat $i)"
2895 done
2896 else
2897 echo ""
2898 echo -e "\033[1m`gettext \"Current undigest(s)\"`\033[0m"
2899 separator
2900 for i in $LOCALSTATE/undigest/*/mirror; do
2901 if [ ! -f $i ]; then
2902 gettext "No undigest mirror found."; echo
2903 exit 1
2904 fi
2905 echo "$(basename $(dirname $i)) $(cat $i)"
2906 done
2907 echo ""
2908 fi ;;
2909 remove-undigest)
2910 # remove undigest URL.
2912 check_root
2913 undigest="$2"
2914 if [ -d $LOCALSTATE/undigest/$2 ]; then
2915 eval_gettext "Remove \$undigest undigest"
2916 echo -n " (`translate_querry y`/`translate_querry N`) ? "
2917 read answer
2918 if [ "$answer" = "$(translate_querry y)" ]; then
2919 eval_gettext "Removing \$undigest undigest..."
2920 rm -rf $LOCALSTATE/undigest/$2
2921 status
2922 rmdir $LOCALSTATE/undigest 2> /dev/null
2923 fi
2924 else
2925 eval_gettext "Undigest \$undigest not found"; echo
2926 fi ;;
2927 add-undigest|setup-undigest)
2928 # Add undigest URL.
2930 check_root
2931 undigest=$2
2932 [ -d $LOCALSTATE/undigest ] || mkdir $LOCALSTATE/undigest
2933 if [ -z "$undigest" ]; then
2934 i=1
2935 while [ -d $LOCALSTATE/undigest/$i ]; do
2936 i=$(($i+1))
2937 done
2938 undigest=$i
2939 fi
2940 if [ ! -d $LOCALSTATE/undigest/$undigest ]; then
2941 eval_gettext "Creating new undigest \$undigest."; echo
2942 mkdir $LOCALSTATE/undigest/$undigest
2943 fi
2944 setup_mirror $LOCALSTATE/undigest/$undigest $3 ;;
2945 setup-mirror)
2946 # Change mirror URL.
2948 check_root
2949 setup_mirror $LOCALSTATE $2 ;;
2950 reconfigure)
2951 # Replay post_install from receipt
2953 check_for_package_on_cmdline
2954 check_root
2955 ROOT=""
2956 while [ -n "$3" ]; do
2957 case "$3" in
2958 --root=*)
2959 ROOT="${3#--root=}/" ;;
2960 *) shift 2
2961 echo -e "\n`gettext \"Unknow option\"` $*.\n" >&2
2962 exit 1 ;;
2963 esac
2964 shift
2965 done
2966 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2967 check_for_receipt $ROOT
2968 # Check for post_install
2969 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2970 . $ROOT$INSTALLED/$PACKAGE/receipt
2971 post_install $ROOT
2972 # Log this activity
2973 [ -n "$ROOT" ] || log Reconfigured
2974 else
2975 echo ""
2976 eval_gettext "Nothing to do for \$PACKAGE."; echo
2977 fi
2978 else
2979 echo ""
2980 eval_gettext "Package \$PACKAGE is not installed."; echo
2981 gettext "Install package with 'tazpkg install' or 'tazpkg get-install'"; echo
2982 echo ""
2983 fi ;;
2984 shell)
2985 # Tazpkg SHell
2987 if test $(id -u) = 0 ; then
2988 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2989 else
2990 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2991 fi
2992 if [ ! "$2" = "--noheader" ]; then
2993 clear
2994 echo ""
2995 echo -e "\033[1m`gettext \"Tazpkg SHell\"`.\033[0m"
2996 separator
2997 gettext "Type 'usage' to list all available commands or 'quit' or 'q' to exit."; echo
2998 echo ""
2999 fi
3000 while true
3001 do
3002 echo -en "$PROMPT"; read cmd
3003 case $cmd in
3004 q|quit)
3005 break ;;
3006 shell)
3007 gettext "You are already running a Tazpkg SHell."; echo ;;
3008 su)
3009 su -c 'exec tazpkg shell --noheader' && break ;;
3010 "")
3011 continue ;;
3012 *)
3013 tazpkg $cmd ;;
3014 esac
3015 done ;;
3016 depends)
3017 # Display dependencies tree
3018 cd $INSTALLED
3019 ALL_DEPS=""
3020 if [ -f $2/receipt ]; then
3021 dep_scan $2 ""
3022 fi ;;
3023 rdepends)
3024 # Display reverse dependencies tree
3025 cd $INSTALLED
3026 ALL_DEPS=""
3027 if [ -f $2/receipt ]; then
3028 rdep_scan $2
3029 fi ;;
3030 convert)
3031 # convert misc package format to .tazpkg
3032 check_for_package_file
3033 if [ "$(dd if=$PACKAGE_FILE bs=8 count=1 skip=1 2> /dev/null)" \
3034 == "debian-b" ]; then
3035 convert_deb
3036 else
3037 case "$PACKAGE_FILE" in
3038 *.deb|*.udeb)
3039 convert_deb;;
3040 *.rpm)
3041 convert_rpm;;
3042 *.tgz)
3043 convert_tgz;;
3044 *.apk|*.pkg.tar.gz)
3045 convert_arch;;
3046 *.ipk|*.opk)
3047 convert_ipk;;
3048 *)
3049 gettext "Unsupported format"; echo ;;
3050 esac
3051 fi ;;
3052 link)
3053 # link a package from another slitaz installation
3054 PACKAGE=$2
3055 if [ ! -d "$TARGET_DIR" -o \
3056 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
3057 cat <<EOT
3058 usage: tazpkg link package_name slitaz_root
3059 example: 'tazpkg link openoffice /mnt' will use less than 100k in
3060 your running system ram.
3061 EOT
3062 exit 1
3063 fi
3064 if [ -e "$INSTALLED/$PACKAGE" ]; then
3065 eval_gettext "\$PACKAGE is already installed."; echo
3066 exit 1
3067 fi
3068 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
3069 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
3070 MISSING=""
3071 for i in $DEPENDS; do
3072 [ -e $INSTALLED/$i ] && continue
3073 MISSING="$MISSING$i "
3074 eval_gettext "Missing : \$i"; echo
3075 done
3076 if [ -n "$MISSING" ]; then
3077 echo ""
3078 gettext "Link all missing dependencies"
3079 echo -n " (`translate_querry y`/`translate_querry N`) ? "
3080 read answer
3081 echo ""
3082 if [ "$answer" = "$(translate_querry y)" ]; then
3083 for i in $MISSING; do
3084 tazpkg link $i $TARGET_DIR
3085 done
3086 else
3087 echo ""
3088 eval_gettext "Leaving dependencies for \$PACKAGE unresolved."; echo
3089 gettext "The package is installed but probably will not work."; echo
3090 echo ""
3091 fi
3092 fi
3093 . $INSTALLED/$PACKAGE/receipt
3094 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
3095 pre_install
3096 fi
3097 while read path; do
3098 [ -e $path ] && continue
3099 while true; do
3100 dir=$(dirname $path)
3101 [ -e $dir ] && break
3102 path=$dir
3103 done
3104 ln -s $TARGET_DIR$path $dir
3105 done < $INSTALLED/$PACKAGE/files.list
3106 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
3107 post_install
3108 fi ;;
3109 usage|*)
3110 # Print a short help or give usage for an unknown or empty command.
3111 usage ;;
3112 esac
3114 exit 0