tazpkg view tazpkg @ rev 503

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