tazpkg view tazpkg @ rev 516

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