tazpkg view tazpkg @ rev 643

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