tazpkg view tazpkg @ rev 590

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