tazpkg view tazpkg @ rev 636

tazpkg/convert: add .pet support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jul 29 11:00:03 2013 +0200 (2013-07-29)
parents 5317ffe7bfbb
children d030d4ecb448
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/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/.apk package to .tazpkg
1182 convert_arch()
1184 mkdir -p $TMP_DIR/fs
1185 tar xzf $PACKAGE_FILE -C $TMP_DIR/fs
1186 if [ -f $TMP_DIR/fs/.PKGINFO ]; then
1187 cd $TMP_DIR
1188 package="$(grep ^pkgname fs/.PKGINFO | sed 's/.*= //')"
1189 version="$(grep ^pkgver fs/.PKGINFO | sed 's/.*= //')"
1190 descrip="$(grep ^pkgdesc fs/.PKGINFO | sed 's/.*= //')"
1191 url="$(grep ^url fs/.PKGINFO | sed 's/.*= //')"
1192 maintainer="$(grep ^packager fs/.PKGINFO | sed 's/.*= //')"
1193 file=$package-$version
1194 mkdir $file
1195 mv fs $file
1196 cat > $file/receipt <<EOT
1197 # SliTaz package receipt.
1198 # generated by tazpkg from Archlinux package $(basename $PACKAGE_FILE)
1199 PACKAGE="$package"
1200 VERSION="$version"
1201 CATEGORY="misc"
1202 SHORT_DESC="$descrip"
1203 WEB_SITE="$url"
1204 MAINTAINER="$maintainer"
1205 DEPENDS="$(find_depends)"
1206 EOT
1207 show_unresolved_lib $file/receipt
1208 rm -f $file/fs/.[A-Z]*
1209 tazpkg pack $file
1210 mv $file.tazpkg $TOP_DIR
1211 else
1212 eval_gettext "\$PACKAGE_FILE does not look like an Archlinux/Alpine package!"; echo
1213 fi
1214 cd $TOP_DIR
1215 rm -rf $TMP_DIR
1218 # convert a .pet package to .tazpkg
1219 convert_pet()
1221 mkdir -p $TMP_DIR
1222 cd $TMP_DIR
1223 package=$(basename $PACKAGE_FILE .pet)
1224 IFS='-'
1225 set -- $package
1226 unset IFS
1227 package=$1
1228 version=$2
1229 if [ -z "$version" ]; then
1230 tmp=${package%%[0-9\.]*}
1231 version=${package#$tmp}
1232 package=$tmp
1233 fi
1234 tar xzf $PACKAGE_FILE 2> /dev/null
1235 . $package*/*.specs
1236 rm -f $package*/*.specs
1237 file="$package-$version"
1238 mv $package*/ fs
1239 mkdir $file
1240 mv fs $file
1241 cat > $file/receipt <<EOT
1242 # SliTaz package receipt.
1243 # generated by tazpkg from puppy package $(basename $PACKAGE_FILE)
1244 PACKAGE="$package"
1245 VERSION="$version"
1246 CATEGORY="misc"
1247 SHORT_DESC="$PETMENUDESCR"
1248 WEB_SITE="http://puppylinux.org/"
1249 MAINTAINER="nobody@slitaz.org"
1250 DEPENDS="$(find_depends)"
1251 EOT
1252 show_unresolved_lib $file/receipt
1253 for i in install uninstall ; do
1254 [ -f $file/fs/p$i.sh ] && cat >> $file/receipt <<EOM
1256 post_$i()
1258 chroot \$1/ sh - << EOT
1259 cd /
1260 $(cat $file/fs/p$i.sh | sed -e 's/\\/\\\\/g' | sed -e 's/\$/\\$/g' ; rm -f $file/fs/p$i.sh)
1261 EOT
1263 EOM
1264 done
1265 sed -i 's/post_uninstall/post_remove/' $file/receipt
1266 tazpkg pack $file
1267 mv $file.tazpkg $TOP_DIR
1268 cd $TOP_DIR
1269 rm -rf $TMP_DIR
1272 # convert a .tgz package to .tazpkg
1273 convert_tgz()
1275 package=$(basename $PACKAGE_FILE)
1276 IFS='-'
1277 set -- $package
1278 unset IFS
1279 package=$1
1280 version=$2
1281 file="$package-$version"
1282 mkdir -p $TMP_DIR/$file/fs
1283 tar xzf $PACKAGE_FILE -C $TMP_DIR/$file/fs
1284 cd $TMP_DIR
1285 if [ -d $file/fs/install ]; then
1286 descrip=$(grep ^$package $file/fs/install/slack-desc | \
1287 head -1 | sed 's/.*(\(.*\)).*/\1/')
1288 cat > $file/receipt <<EOT
1289 # SliTaz package receipt.
1290 # generated by tazpkg from slackware package $(basename $PACKAGE_FILE)
1291 PACKAGE="$package"
1292 VERSION="$version"
1293 CATEGORY="misc"
1294 SHORT_DESC="$descrip"
1295 WEB_SITE="http://www.slackware.com/packages/"
1296 MAINTAINER="nobody@slitaz.org"
1297 DEPENDS="$(find_depends)"
1298 EOT
1299 show_unresolved_lib $file/receipt
1300 [ -f $file/fs/install/doinst.sh ] && cat >> $file/receipt <<EOM
1302 post_install()
1304 chroot \$1/ sh - << EOT
1305 cd /
1306 $(cat $file/fs/install/doinst.sh | sed -e 's/\\/\\\\/g' | sed -e 's/\$/\\$/g')
1307 EOT
1309 EOM
1310 grep ^$package $file/fs/install/slack-desc | \
1311 sed "s/^$package://" > $file/description.txt
1312 [ -s $file/description.txt ] || rm -f $file/description.txt
1313 rm -rf $file/fs/install
1314 tazpkg pack $file
1315 mv $file.tazpkg $TOP_DIR
1316 else
1317 eval_gettext "\$PACKAGE_FILE does not look like a Slackware package!"; echo
1318 fi
1319 cd $TOP_DIR
1320 rm -rf $TMP_DIR
1323 # convert a .deb package to .tazpkg
1324 convert_deb()
1326 mkdir -p $TMP_DIR
1327 dpkg-deb -e $PACKAGE_FILE $TMP_DIR
1328 package=$(grep '^ *Package:' $TMP_DIR/control)
1329 package=$(echo ${package##*:})
1330 version=$(grep '^ *Version:' $TMP_DIR/control)
1331 version=$(echo ${version##*:})
1332 descrip=$(grep '^ *Description:' $TMP_DIR/control)
1333 descrip=$(echo ${descrip##*:})
1334 target="$(grep ^Architecture $TMP_DIR/control | sed 's/.*: //')"
1335 case "$target" in
1336 i386|all)
1337 file="$package-$version"
1338 mkdir -p $TMP_DIR/$file/fs/
1339 dpkg-deb -x $PACKAGE_FILE $TMP_DIR/$file/fs
1340 cd $TMP_DIR
1341 cat > $file/receipt <<EOT
1342 # SliTaz package receipt.
1343 # generated by tazpkg from debian package $(basename $PACKAGE_FILE)
1344 PACKAGE="$package"
1345 VERSION="$version"
1346 CATEGORY="misc"
1347 SHORT_DESC="$descrip"
1348 WEB_SITE="http://packages.debian.org/search?keywords=$package"
1349 MAINTAINER="nobody@slitaz.org"
1350 EOT
1351 LICENSE="$(grep /usr/share/common-licenses/ \
1352 $PACKAGE_FILE $TMP_DIR/$file/fs/usr/share/doc/*/copyright | \
1353 sed 's|.*common-licenses/\([-\.A-Za-z0-9]*\).*|\1|;s|[-\.]$||q')"
1354 [ -n "$LICENSE" ] && echo "LICENSE=\"$LICENSE\"" >> $file/receipt
1355 echo "DEPENDS=\"$(find_depends)\"" >> $file/receipt
1356 [ -s conffiles ] && cat >> $file/receipt <<EOT
1357 CONFIG_FILES="$(cat conffiles)"
1358 EOT
1359 show_unresolved_lib $file/receipt
1360 awk '
1362 if (/^ / && show) print substr($0,2);
1363 else show=0;
1364 if (/^Description/) show=1;
1365 }' < $TMP_DIR/control > $file/description.txt
1366 sed -i 's/^\.$//' $file/description.txt
1367 [ -s $file/description.txt ] || rm -f $file/description.txt
1368 tazpkg pack $file
1369 mv $file.tazpkg $TOP_DIR
1370 ;;
1371 *)
1372 eval_gettext "Invalid target: \$target (expected i386)"; echo
1373 ;;
1374 esac
1375 cd $TOP_DIR
1376 rm -rf $TMP_DIR
1379 # convert a .rpm package to .tazpkg
1380 convert_rpm()
1382 mkdir -p $TMP_DIR
1383 cp $PACKAGE_FILE $TMP_DIR
1384 PACKAGE_FILE=$TMP_DIR/$(basename $PACKAGE_FILE)
1385 rpm -qip $PACKAGE_FILE | awk -v pkg=$(basename $PACKAGE_FILE) '
1386 BEGIN {
1387 goturl=0;
1388 printf "# SliTaz package receipt.\n";
1389 printf "# generated by tazpkg from rpm package %s\n",pkg;
1392 if (/^Name/) { name=$3; printf "PACKAGE=\"%s\"\n",$3; }
1393 if (/^Version/) printf "VERSION=\"%s-",$3;
1394 if (/^Release/) printf "%s\"\n",$3;
1395 if (/^Summary/) printf "SHORT_DESC=\"%s\"\n",substr($0,15);
1396 if (/^URL/) { goturl=1; printf "WEB_SITE=\"%s\"\n",$3; }
1398 END {
1399 if (goturl == 0)
1400 printf "WEB_SITE=\"http://rpmfind.net/linux/rpm2html/search.php?query=%s\"\n",name;
1401 printf "CATEGORY=\"misc\"\n";
1402 printf "MAINTAINER=\"nobody@slitaz.org\"\n";
1404 ' > $TMP_DIR/receipt
1405 . $TMP_DIR/receipt
1406 file=$PACKAGE-$VERSION
1407 mkdir -p $TMP_DIR/$file/fs/
1408 mv $TMP_DIR/receipt $TMP_DIR/$file
1409 rpm -qip $PACKAGE_FILE | awk '
1410 BEGIN { show=0 }
1412 if (show) print;
1413 if (/^Description/) show=1;
1415 ' > $TMP_DIR/$file/description.txt
1416 cd $TMP_DIR/$file/fs/
1417 rpm2cpio $PACKAGE_FILE | cpio -idm --quiet
1418 # rpm2cpio can't extract some new RPMs
1419 if [ $? == 1 ]; then
1420 if [ ! -e $INSTALLED/p7zip-full/receipt ]; then
1421 boldify $(gettext "Unable to extract the RPM using standard tools (rpm2cpio).")
1422 gettext "Do you want to install 'p7zip-full' package" && confirm
1423 if [ $? = 0 ]; then
1424 tazpkg -gi p7zip-full
1425 else
1426 rm -rf $TMP_DIR
1427 exit 1
1428 fi
1429 fi
1430 # we may already have 7z or may have just installed it in the step above
1431 if [ -e $INSTALLED/p7zip-full/receipt ]; then
1432 7z x -so $PACKAGE_FILE | cpio -idm --quiet
1433 fi
1434 fi
1435 cd ../..
1436 echo "DEPENDS=\"$(find_depends)\"" >> $TMP_DIR/$file/receipt
1437 show_unresolved_lib $TMP_DIR/$file/receipt
1438 tazpkg pack $file
1439 mv $file.tazpkg $TOP_DIR
1440 cd $TOP_DIR
1441 rm -rf $TMP_DIR
1444 update_desktop_database()
1446 if [ -f $1/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
1447 chroot "$1/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
1448 fi
1451 update_mime_database()
1453 if [ -f $1/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
1454 chroot "$1/" /usr/bin/update-mime-database /usr/share/mime
1455 fi
1458 update_icon_database()
1460 if [ -f $1/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
1461 chroot "$1/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
1462 fi
1465 compile_glib_schemas()
1467 if [ -f $1/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
1468 chroot "$1/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
1469 fi
1472 update_kernel_modules()
1474 if [ -f $1/sbin/depmod ] && [ -n "$updatedepmod" ]; then
1475 chroot "$1/" /sbin/depmod -a
1476 fi
1479 ###################
1480 # TazPkg commands #
1481 ###################
1483 case "$COMMAND" in
1484 list|-l)
1485 shift
1486 # List all installed packages or a specific category.
1487 if [ "$1" = "blocked" ]; then
1488 title 'Blocked packages'
1489 if [ -s "$BLOCKED" ];then
1490 cat $BLOCKED
1491 else
1492 gettext "No blocked packages found."; echo
1493 fi
1494 newline && exit 0
1495 fi
1496 # Display the list of categories.
1497 if [ "$1" = "cat" -o "$1" = "categories" ]; then
1498 title 'Packages categories'
1499 num=0
1500 for i in $PKGS_CATEGORIES
1501 do
1502 gettext $i; echo
1503 num=$(($num+1))
1504 done
1505 footer "$(eval_ngettext '$num category' '$num categories' $num)"; echo
1506 exit 0
1507 fi
1508 # Check for an asked category.
1509 ASKED_CATEGORY_I18N="$@"
1510 if [ -n "$ASKED_CATEGORY_I18N" ]; then
1511 ASKED_CATEGORY=$(reverse_translate_category "$ASKED_CATEGORY_I18N")
1512 title 'Installed packages of category: $ASKED_CATEGORY_I18N'
1513 for pkg in $INSTALLED/*
1514 do
1515 [ -f $pkg/receipt ] || continue
1516 EXTRAVERSION=""
1517 . $pkg/receipt
1518 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
1519 echo -e "$PACKAGE\033[24G $VERSION$EXTRAVERSION"
1520 packages=$(($packages+1))
1521 fi
1522 done
1523 num="<c 32>$packages</c>"; cat_name="<c 34>$ASKED_CATEGORY_I18N</c>"
1524 footer "$(emsg $(eval_ngettext \
1525 '$num package installed of category $cat_name.' \
1526 '$num packages installed of category $cat_name.' \
1527 $packages))"; echo
1528 else
1529 # By default list all packages and versions.
1530 title 'List of all installed packages'
1531 for pkg in $INSTALLED/*
1532 do
1533 [ -f $pkg/receipt ] || continue
1534 EXTRAVERSION=""
1535 . $pkg/receipt
1536 echo -e "$PACKAGE\033[35G $VERSION$EXTRAVERSION\033[53G $(gettext $CATEGORY)"
1537 packages=$(($packages+1))
1538 done
1539 num="<c 32>$packages</c>"
1540 footer "$(emsg $(eval_ngettext \
1541 '$num package installed.' \
1542 '$num packages installed.' $packages))"
1543 fi ;;
1544 list-mirror|-lm)
1545 # List all available packages on the mirror. Option --diff displays
1546 # last mirrored packages diff (see recharge).
1547 check_for_packages_list
1548 case $2 in
1549 --diff)
1550 if [ -f "$LOCALSTATE/packages.diff" ]; then
1551 title 'Mirrored packages diff'
1552 cat $LOCALSTATE/packages.diff
1553 num=$(cat $LOCALSTATE/packages.diff | wc -l)
1554 footer "$(eval_ngettext \
1555 '$num new package listed on the mirror.' \
1556 '$num new packages listed on the mirror.' $num)"
1557 else
1558 newline
1559 gettext "Unable to list anything, no packages.diff found."; echo
1560 gettext "Recharge your current list to create a first diff."; echo
1561 newline
1562 fi && exit 0 ;;
1563 --text|--txt|--raw|*)
1564 title 'List of available packages on the mirror'
1565 cat $LOCALSTATE/packages.txt ;;
1566 esac
1567 pkgs=$(cat $LOCALSTATE/packages.list | wc -l)
1568 num=$(emsg "<c 32>$pkgs</c>")
1569 footer "$(eval_ngettext \
1570 '$num package in the last recharged list.' \
1571 '$num packages in the last recharged list.' $pkgs)"
1572 ;;
1573 list-files|-lf)
1574 # List files installed with the package.
1575 check_for_package_on_cmdline
1576 check_for_receipt
1577 title 'Installed files by: $PACKAGE'
1578 cat $INSTALLED/$PACKAGE/files.list | sort
1579 files=$(cat $INSTALLED/$PACKAGE/files.list | wc -l)
1580 num=$(emsg "<c 32>$files</c>")
1581 footer "$(eval_ngettext \
1582 '$num file installed with $PACKAGE' \
1583 '$num files installed with $PACKAGE' $files)"
1584 ;;
1585 info)
1586 # Information about package.
1587 check_for_package_on_cmdline
1588 check_for_receipt
1589 EXTRAVERSION=""
1590 . $INSTALLED/$PACKAGE/receipt
1591 title 'TazPkg information'
1592 # Display localized short description
1593 if [ -e "$LOCALSTATE/packages-desc.$LANG" ]; then
1594 LOCDESC=$(grep -e "^$PACKAGE " $LOCALSTATE/packages-desc.$LANG | cut -d' ' -f2)
1595 [ "x$LOCDESC" != "x" ] && SHORT_DESC="$LOCDESC"
1596 fi
1597 emsg "\
1598 <b>$(gettext 'Package :')</b> $PACKAGE
1599 <b>$(gettext 'Version :')</b> $VERSION$EXTRAVERSION
1600 <b>$(gettext 'Category :')</b> $(gettext $CATEGORY)
1601 <b>$(gettext 'Short desc :')</b> $SHORT_DESC
1602 <b>$(gettext 'Maintainer :')</b> $MAINTAINER"
1603 [ "$LICENSE" ] && emsg "<b>$(gettext 'License :')</b> $DEPENDS"
1604 [ "$DEPENDS" ] && emsg "<b>$(gettext 'Depends :')</b> $DEPENDS"
1605 [ "$SUGGESTED" ] && emsg "<b>$(gettext 'Suggested :')</b> $SUGGESTED"
1606 [ "$BUILD_DEPENDS" ] && emsg "<b>$(gettext 'Build deps :')</b> $BUILD_DEPENDS"
1607 [ "$WANTED" ] && emsg "<b>$(gettext 'Wanted src :')</b> $WANTED"
1608 [ "$WEB_SITE" ] && emsg "<b>$(gettext 'Web site :')</b> $WEB_SITE"
1609 footer
1610 ;;
1611 desc)
1612 # Display package description.txt if available.
1613 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1614 title 'Description of: $PACKAGE'
1615 cat $INSTALLED/$PACKAGE/description.txt
1616 footer
1617 else
1618 newline
1619 gettext "Sorry, no description available for this package."; echo
1620 newline
1621 fi ;;
1622 search|-s)
1623 # Search for a package by pattern or name.
1624 PATTERN="$2"
1625 if [ -z "$PATTERN" ]; then
1626 newline
1627 gettext "Please specify a pattern or package name to search for."; echo
1628 echo "$(gettext 'Example:') 'tazpkg search paint'"
1629 newline
1630 exit 0
1631 fi
1632 title 'Search result for: $PATTERN'
1633 # Default is to search in installed pkgs and the raw list.
1634 case $3 in
1635 -i|--installed)
1636 search_in_installed_packages ;;
1637 -l|--list)
1638 search_in_packages_list ;;
1639 -m|--mirror)
1640 search_in_packages_txt ;;
1641 *)
1642 search_in_installed_packages
1643 search_in_packages_list ;;
1644 esac ;;
1645 search-file|-sf)
1646 # Search for a file by pattern or name in all files.list.
1647 if [ -z "$2" ]; then
1648 newline
1649 gettext "Please specify a pattern or file name to search for."; echo
1650 echo "$(gettext 'Example:') 'tazpkg search-file libnss'"
1651 newline
1652 exit 0
1653 fi
1654 s_file="$2"
1655 title 'Search result for file $s_file'
1657 if [ "$3" == "--mirror" ]; then
1659 match=0
1660 for i in $LOCALSTATE/files.list.lzma \
1661 $LOCALSTATE/undigest/*/files.list.lzma; do
1662 [ -f $i ] || continue
1663 unlzma -c $i | grep -- ".*:.*$2" | awk '
1664 BEGIN { last="" }
1666 pkg=substr($0,0,index($0,":")-1);
1667 file=substr($0,index($0,":")+2);
1668 if (last != pkg) {
1669 last = pkg;
1670 printf("\n%c[1mPackage %s:%c[0m\n",27,pkg,27);
1672 printf("%s\n",file);
1673 }'
1674 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | wc -l`))
1675 done
1677 else
1679 # Check all pkg files.list in search match which specify the package
1680 # name and the full path to the file(s).
1681 for pkg in $INSTALLED/*
1682 do
1683 if grep -qs "$2" $pkg/files.list; then
1684 . $pkg/receipt
1685 newline
1686 boldify "$(eval_gettext 'Package $PACKAGE:')"
1687 grep "$2" $pkg/files.list
1688 files=`grep $2 $pkg/files.list | wc -l`
1689 match=$(($match+$files))
1690 fi
1691 done
1693 fi
1694 pkg=$2
1695 if [ "$match" = "" ]; then
1696 eval_gettext "0 file found for: \$pkg"; echo
1697 else
1698 num=$(emsg "<c 32>$files</c>")
1699 footer "$(eval_ngettext \
1700 '$num file found for: $pkg' \
1701 '$num files found for: $pkg' $match)"
1702 fi
1703 ;;
1704 search-pkgname)
1705 # Search for a package name
1706 if [ -z "$2" ]; then
1707 newline
1708 gettext "Please specify a pattern or file name to search for."; echo
1709 echo "$(gettext 'Example:') 'tazpkg search-pkgname libnss'"
1710 newline
1711 exit 0
1712 fi
1713 s_pkg="$2"
1714 title 'Search result for package $s_pkg'
1716 # Search for a file on mirror and output only the package name
1717 match=0
1718 for i in $LOCALSTATE/files.list.lzma \
1719 $LOCALSTATE/undigest/*/files.list.lzma; do
1720 [ -f $i ] || continue
1721 unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | awk '{ print $1 }'
1722 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | wc -l`))
1723 done
1724 file=$2
1725 if [ "$match" = "0" ]; then
1726 eval_gettext "No file found for: \$file"; echo
1727 newline
1728 else
1729 num=$(emsg "<c 32>$files</c>")
1730 footer "$(eval_ngettext \
1731 '$num package found with file: $file' \
1732 '$num packages found with file: $file' $match)"
1733 fi
1734 ;;
1735 install|-i)
1736 # Install .tazpkg packages.
1737 check_root $@
1738 check_for_package_on_cmdline
1739 check_for_package_file
1741 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
1742 [ "$list" ] && INSTALL_LIST="$list"
1743 if [ "$rootconfig" ]; then
1744 if [ "$root" ]; then
1745 CACHE_DIR=$root/$CACHE_DIR
1746 SAVE_CACHE_DIR=$CACHE_DIR
1747 LOCALSTATE=$root/$LOCALSTATE
1748 else
1749 echo "rootconfig needs --root= option used." >&2
1750 exit 1
1751 fi
1752 fi
1754 # Get repositories priority list.
1755 look_for_priority
1757 # Check if forced install.
1758 if ! [ "$forced" ]; then
1759 check_for_installed_package $ROOT
1760 fi
1761 install_package $ROOT
1762 update_desktop_database $ROOT
1763 update_mime_database $ROOT
1764 update_icon_database $ROOT
1765 compile_glib_schemas $ROOT ;;
1766 install-list|get-install-list)
1767 # Install a set of packages from a list.
1768 check_root $@
1769 if [ -z "$2" ]; then
1770 newline
1771 gettext \
1772 "Please change directory (cd) to the packages repository and specify the
1773 list of packages to install. Example: tazpkg install-list packages.list"
1774 newline && exit 0
1775 fi
1776 # Check if the packages list exist.
1777 list_file=$2
1778 if [ ! -f "$list_file" ]; then
1779 eval_gettext "Unable to find: \$list_file"; echo
1780 exit 0
1781 else
1782 LIST=`cat $2`
1783 fi
1785 # Remember processed list
1786 export INSTALL_LIST="$2"
1788 # Set $COMMAND and install all packages.
1789 if [ "$1" = "get-install-list" ]; then
1790 COMMAND=get-install
1791 else
1792 COMMAND=install
1793 fi
1794 touch $2-processed
1796 # Upgrade tazpkg first. It may handle new features/formats...
1797 # then upgrade essential packages early
1798 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1799 slitaz-base-files tazpkg ; do
1800 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1801 [ -n "$pkg" ] || continue
1802 eval_gettext "Adding implicit depends \$pkg..."; echo
1803 LIST="$pkg
1804 $LIST"
1805 done
1807 for pkg in $LIST
1808 do
1809 grep -qs ^$pkg$ $2-processed && continue
1810 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1811 done
1812 rm -f $2-processed ;;
1813 add-flavor)
1814 # Install a set of packages from a flavor.
1815 install_flavor $2 ;;
1816 install-flavor)
1817 # Install a set of packages from a flavor and purge other ones.
1818 install_flavor $2 --purge ;;
1819 set-release)
1820 # Change curent release and upgrade packages.
1821 RELEASE=$2
1822 if [ -z "$RELEASE" ]; then
1823 newline
1824 gettext "Please specify the release you want on the command line."; echo
1825 echo "$(gettext 'Example:') tazpkg set-release cooking"
1826 newline
1827 exit 0
1828 fi
1829 rm $LOCALSTATE/mirror
1830 echo "$RELEASE" > /etc/slitaz-release
1831 tazpkg recharge && tazpkg upgrade
1833 # Install missing depends
1834 cd $INSTALLED
1835 for i in * ; do
1836 DEPENDS=""
1837 . $i/receipt
1838 for j in $DEPENDS ; do
1839 [ -d $j ] || tazpkg get-install $j
1840 done
1841 done ;;
1842 remove|-r)
1843 # Remove packages.
1844 check_root $@
1845 check_for_package_on_cmdline
1847 [ "$root" ] && ROOT="$root"
1848 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1849 newline
1850 eval_gettext "\$PACKAGE is not installed."; echo
1851 exit 0
1852 else
1853 ALTERED=""
1854 THE_PACKAGE=$PACKAGE # altered by receipt
1855 for i in $(cd $ROOT$INSTALLED ; ls); do
1856 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1857 DEPENDS=""
1858 . $ROOT$INSTALLED/$i/receipt
1859 case " $(echo $DEPENDS) " in
1860 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1861 esac
1862 done
1863 EXTRAVERSION=""
1864 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1865 fi
1866 newline
1867 if [ -n "$ALTERED" ]; then
1868 eval_gettext "The following packages depend on \$PACKAGE:"; echo
1869 for i in $ALTERED; do
1870 echo " $i"
1871 done
1872 fi
1873 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1874 if [ -n "$REFRESH" ]; then
1875 eval_gettext "The following packages have been modified by \$PACKAGE:"; echo
1876 for i in $REFRESH; do
1877 echo " ${i%/modifiers}"
1878 done
1879 fi
1880 if [ "$auto" ]; then
1881 answer=0
1882 else
1883 eval_gettext "Remove \$PACKAGE (\$VERSION\$EXTRAVERSION)" && confirm
1884 answer=$?
1885 fi
1886 if [ $answer = 0 ]; then
1887 title 'Removing: $PACKAGE'
1888 # Pre remove commands.
1889 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1890 pre_remove $ROOT
1891 fi
1892 action "Removing all files installed..."
1893 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1894 for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
1895 do
1896 for mod in `cat $ROOT$INSTALLED/$PACKAGE/modifiers`
1897 do
1898 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1899 done
1900 remove_with_path $ROOT$file
1901 done
1902 else
1903 for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
1904 do
1905 remove_with_path $ROOT$file
1906 done
1907 fi
1908 status
1909 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1910 post_remove $ROOT
1911 fi
1912 # Remove package receipt.
1913 action "Removing package receipt..."
1914 rm -rf $ROOT$INSTALLED/$PACKAGE
1915 status
1916 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1917 $LOCALSTATE/installed.$SUM 2> /dev/null
1918 # Log this activity
1919 log_pkg Removed
1920 if [ "$ALTERED" ]; then
1921 if [ "$auto" ]; then
1922 answer=0
1923 else
1924 eval_gettext "Remove packages depending on \$PACKAGE" && confirm
1925 answer=$?
1926 fi
1927 if [ $answer = 0 ]; then
1928 for i in $ALTERED; do
1929 if [ -d "$ROOT$INSTALLED/$i" ]; then
1930 tazpkg remove $i $ROOTOPTS
1931 fi
1932 done
1933 fi
1934 fi
1935 if [ "$REFRESH" ]; then
1936 if [ "$auto" ]; then
1937 answer=0
1938 else
1939 eval_gettext "Reinstall packages modified by \$PACKAGE" && confirm
1940 answer=$?
1941 fi
1942 if [ $answer = 0 ]; then
1943 for i in $REFRESH; do
1944 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1945 eval_gettext "Check \$INSTALLED/\$i for reinstallation"; echo
1946 continue
1947 fi
1948 rm -r $ROOT$INSTALLED/$i
1949 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1950 done
1951 fi
1952 fi
1953 else
1954 newline
1955 eval_gettext "Uninstallation of \$PACKAGE cancelled."; echo
1956 fi
1957 newline ;;
1958 extract|-e)
1959 # Extract .tazpkg cpio archive into a directory.
1960 check_for_package_on_cmdline
1961 check_for_package_file
1962 title 'Extracting: $PACKAGE'
1963 # If no directory destination is found on the cmdline
1964 # we create one in the current dir using the package name.
1965 if [ -n "$TARGET_DIR" ]; then
1966 DESTDIR=$TARGET_DIR/$PACKAGE
1967 else
1968 DESTDIR=$PACKAGE
1969 fi
1970 mkdir -p $DESTDIR
1971 action "Copying original package..."
1972 cp $PACKAGE_FILE $DESTDIR
1973 status
1974 cd $DESTDIR
1975 extract_package
1976 [ -e "receipt" ] && footer "$(eval_gettext '$PACKAGE is extracted to: $DESTDIR')"
1977 ;;
1978 recompress)
1979 # Recompress .tazpkg cpio archive with lzma.
1980 check_for_package_on_cmdline
1981 check_for_package_file
1982 title 'Recompressing: $PACKAGE'
1983 mkdir -p $TMP_DIR
1984 action "Copying original package..."
1985 cp $PACKAGE_FILE $TMP_DIR
1986 status
1987 cd $TMP_DIR
1988 extract_package
1989 action "Recompressing the fs..."
1990 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1991 rm -rf fs
1992 status
1993 action "Creating new package..."
1994 find . -print | cpio -o -H newc --quiet > \
1995 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1996 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1997 $TOP_DIR/$(basename $PACKAGE_FILE)
1998 status
1999 cd $TOP_DIR
2000 rm -rf $TMP_DIR
2001 separator; newline ;;
2002 list-config)
2003 # List configuration files installed.
2004 if [ "$2" = "--box" ]; then
2005 mkdir -p $TMP_DIR && cd $TMP_DIR
2006 FILES="$INSTALLED/*/volatile.cpio.gz"
2007 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
2008 for i in $FILES; do
2009 zcat $i | cpio -idm --quiet > /dev/null
2010 find * -type f 2>/dev/null | while read file; do
2011 if [ ! -e /$file ]; then
2012 echo -en "----------|----|----|`gettext \"File lost\"`"
2013 else
2014 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
2015 cmp $file /$file > /dev/null 2>&1 || \
2016 echo -n "$(stat -c "%.16y" /$file)"
2017 fi
2018 echo "|/$file"
2019 done
2020 rm -rf *
2021 done
2022 cd $TOP_DIR
2023 rm -rf $TMP_DIR
2024 else
2025 title 'Configuration files'
2026 for i in $INSTALLED/*/volatile.cpio.gz; do
2027 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
2028 [ -f "$i" ] || continue
2029 zcat $i | cpio -t --quiet
2030 done | sed 's|^|/|' | sort
2031 separator
2032 newline
2033 fi ;;
2034 repack-config)
2035 # Create SliTaz package archive from configuration files.
2036 mkdir -p $TMP_DIR && cd $TMP_DIR
2037 CONFIG_VERSION=1.0
2038 mkdir config-$CONFIG_VERSION
2039 cd config-$CONFIG_VERSION
2040 for i in $INSTALLED/*/volatile.cpio.gz; do
2041 zcat $i | cpio -t --quiet
2042 done > files.list
2043 mkdir fs
2044 cd fs
2045 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
2046 mkdir -p etc/tazlito
2047 for i in $INSTALLED/*/receipt; do
2048 EXTRAVERSION=""
2049 . $i
2050 echo "$PACKAGE-$VERSION$EXTRAVERSION"
2051 done > etc/tazlito/config-packages.list
2052 cd ..
2053 echo "etc/tazlito/config-packages.list" >> files.list
2054 pkg_date=$(date +"%x %X")
2055 cat > receipt <<EOT
2056 # SliTaz package receipt.
2058 PACKAGE="config"
2059 VERSION="$CONFIG_VERSION"
2060 CATEGORY="base-system"
2061 SHORT_DESC="$(eval_gettext 'User configuration backup on $pkg_date')"
2062 DEPENDS="$(ls $INSTALLED)"
2063 EOT
2064 cd ..
2065 tazpkg pack config-$CONFIG_VERSION
2066 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
2067 cd $TOP_DIR
2068 rm -rf $TMP_DIR
2069 ;;
2070 repack)
2071 # Create SliTaz package archive from an installed package.
2072 check_for_package_on_cmdline
2073 check_for_receipt
2074 EXTRAVERSION=""
2075 . $INSTALLED/$PACKAGE/receipt
2076 title 'Repacking: $PACKAGE-$VERSION$EXTRAVERSION.tazpkg'
2077 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2078 eval_gettext "Can't repack \$PACKAGE"; echo
2079 exit 1
2080 fi
2081 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2082 eval_gettext "Can't repack, \$PACKAGE files have been modified by:"; echo
2083 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2084 echo " $i"
2085 done
2086 exit 1
2087 fi
2088 MISSING=""
2089 while read i; do
2090 [ -e "$i" ] && continue
2091 [ -L "$i" ] || MISSING="$MISSING\n $i"
2092 done < $INSTALLED/$PACKAGE/files.list
2093 if [ -n "$MISSING" ]; then
2094 gettext "Can't repack, the following files are lost:"
2095 echo -e "$MISSING"
2096 exit 1
2097 fi
2098 mkdir -p $TMP_DIR && cd $TMP_DIR
2099 FILES="fs.cpio.lzma\n"
2100 for i in $(ls $INSTALLED/$PACKAGE) ; do
2101 [ "$i" = "volatile.cpio.gz" ] && continue
2102 [ "$i" = "modifiers" ] && continue
2103 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
2104 done
2105 ln -s / rootfs
2106 mkdir tmp
2107 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet |\
2108 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2109 mv tmp/rootfs fs
2110 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2111 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2112 { cd fs; cpio -idm --quiet; cd ..; }
2113 fi
2114 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2115 . $INSTALLED/$PACKAGE/receipt
2116 repack_cleanup fs
2117 fi
2118 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2119 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2120 $CHECKSUM -s -c || {
2121 eval_gettext "Can't repack, \$CHECKSUM error."; echo
2122 cd $TOP_DIR
2123 rm -rf $TMP_DIR
2124 exit 1
2126 fi
2127 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2128 echo -e "$FILES" | cpio -o -H newc --quiet > \
2129 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2130 cd $TOP_DIR
2131 \rm -R $TMP_DIR
2132 eval_gettext "Package \$PACKAGE repacked successfully."; echo
2133 pkg_size=$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)
2134 eval_gettext "Size: \$pkg_size"; echo
2135 newline ;;
2136 pack)
2137 # Create SliTaz package archive using cpio and lzma.
2138 # TODO: Cook also pack packages, we should share code in libpkg.sh
2139 check_for_package_on_cmdline
2140 cd $PACKAGE
2141 if [ ! -f "receipt" ]; then
2142 gettext "Receipt is missing. Please read the documentation."; echo
2143 exit 0
2144 else
2145 title 'Packing: $PACKAGE'
2146 # Create files.list with redirecting find outpout.
2147 action "Creating the list of files..."
2148 cd fs
2149 find . -type f -print > ../files.list
2150 find . -type l -print >> ../files.list
2151 cd .. && sed -i s/'^.'/''/ files.list
2152 status
2153 action "Creating \$CHECKSUM of files..."
2154 while read file; do
2155 [ -L "fs$file" ] && continue
2156 [ -f "fs$file" ] || continue
2157 case "$file" in
2158 /lib/modules/*/modules.*|*.pyc) continue;;
2159 esac
2160 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2161 done < files.list > $CHECKSUM
2162 status
2163 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2164 description.txt 2> /dev/null | awk \
2165 '{ sz=$1 } END { print sz }')
2166 # Build cpio archives.
2167 action "Compressing the fs..."
2168 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2169 rm -rf fs
2170 status
2171 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2172 $CHECKSUM description.txt 2> /dev/null | awk \
2173 '{ sz=$1 } END { print sz }')
2174 action "Updating receipt sizes..."
2175 sed -i s/^PACKED_SIZE.*$// receipt
2176 sed -i s/^UNPACKED_SIZE.*$// receipt
2177 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2178 status
2179 action "Creating full cpio archive..."
2180 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2181 status
2182 action "Restoring original package tree..."
2183 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2184 status
2185 rm fs.cpio.lzma && cd ..
2186 footer "$(eval_gettext 'Package $PACKAGE compressed successfully.')"
2187 pkg_size=$(du -sh $PACKAGE.tazpkg)
2188 eval_gettext "Size: \$pkg_size"; echo
2189 newline
2190 fi ;;
2191 recharge)
2192 # Recharge packages.list from a mirror.
2194 # WARNING: The mirrors file has all SliTaz mirrors but mirror
2195 # must have only the chosen main mirror.
2197 check_root $@
2199 ARG=$2
2200 if [ "$root" ]; then
2201 LOCALSTATE=$root$LOCALSTATE
2202 [ "${2#--}" != "$2" ] && ARG=$3
2203 fi
2204 if [ "$ARG" = main ]; then
2205 repository_to_recharge=$LOCALSTATE
2206 elif [ "$ARG" ]; then
2207 if [ -d "$LOCALSTATE/undigest/$ARG" ]; then
2208 repository_to_recharge=$LOCALSTATE/undigest/$ARG
2209 else
2210 repo="$LOCALSTATE/undigest/$ARG"
2211 eval_gettext "\$repo doesn't exist." >&2
2212 echo >&2
2213 exit 1
2214 fi
2215 else
2216 repository_to_recharge="$LOCALSTATE $LOCALSTATE/undigest/*"
2217 fi
2218 for path in $repository_to_recharge; do
2219 [ -f $path/mirror ] || continue
2220 cd $path
2222 # Quietly check if recharging is needed.
2223 [ -f ID ] && mv ID ID.bak
2224 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2225 if [ -f ID ] && fgrep -q `cat ID.bak 2>/dev/null || echo "null"` ID; then
2226 if [ "$path" = "$LOCALSTATE" ]; then
2227 repository_name=Main
2228 else
2229 base_path="$(basename $path)"
2230 repository_name="$(eval_gettext 'Undigest $base_path')"
2231 fi
2232 eval_gettext "\$repository_name is up to date."; echo
2233 rm ID.bak
2234 continue
2235 fi
2237 # Don't let ID be a symlink when using local repository.
2238 if [ -f ID ]; then
2239 mv -f ID ID.bak
2240 cat ID.bak > ID
2241 rm ID.bak
2242 fi
2244 newline
2245 if [ "$path" != "$LOCALSTATE" ]; then
2246 base_path="$(basename $path)"
2247 eval_gettext "Recharging undigest \$base_path:"; echo
2248 fi
2250 if [ -f "packages.list" ]; then
2251 action "Creating backup of the last packages list..."
2252 for i in packages.desc packages.$SUM packages.txt \
2253 packages.list packages.equiv files.list.lzma \
2254 mirrors
2255 do
2256 mv -f $i $i.bak 2>/dev/null
2257 done
2258 status
2259 fi
2261 for i in desc md5 txt list equiv; do
2262 download_from "$(cat mirror)" packages.$i
2263 done
2264 download_from "$(cat mirror)" files.list.lzma
2265 download_from "$(sed 's|packages/.*||' < mirror)" mirrors
2267 if [ -f "packages.list.bak" ]; then
2268 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2269 sed -i s/+// packages.diff
2270 title 'Mirrored packages diff'
2271 cat packages.diff
2272 new_pkgs=`cat packages.diff | wc -l`
2273 if [ "$new_pkgs" != 0 ]; then
2274 num=$(emsg "<c 32>$new_pkgs</c>")
2275 footer "$(eval_ngettext \
2276 '$num new package on the mirror.' \
2277 '$num new packages on the mirror.' $new_pkgs)"
2278 else
2279 gettext "No new packages on the mirror."; echo
2280 newline
2281 fi
2282 else
2283 footer "$(gettext \
2284 'Last packages.list is ready to use. Note that next time you recharge the
2285 list, a list of differences will be displayed to show new and upgradeable
2286 packages.')"
2287 fi
2288 done ;;
2289 help-up)
2290 # Options available for the command: up
2291 newline; usage_up; newline
2292 exit 1
2293 ;;
2294 up|upgrade)
2296 # This is the new way to upgrade packages making 'upgrade' and
2297 # upgradeable out-of-date. This new way is much, much more faster!
2298 # Look into installed packages and get data from receipt, it is fast
2299 # and easy to handle vars after using only md5sum to compare packages
2301 for opt in $@
2302 do
2303 case "$opt" in
2304 --recharge|-r)
2305 tazpkg recharge ;;
2306 --install|-i)
2307 install="y" ;;
2308 --check|-c)
2309 install="n" ;;
2310 esac
2311 done
2312 time=$(date +%s)
2313 installed_sum=$LOCALSTATE/installed.$SUM
2314 look_for_priority
2315 for repo in $priority; do
2316 pkg_list=$repo/packages.list
2317 mtime=`find $pkg_list -mtime +7`
2318 if [ "$mtime" ]; then
2319 if [ "$repo" = "$LOCALSTATE" ]; then
2320 repo_name=main
2321 else
2322 repo_name="${repo##*/}"
2323 fi
2324 eval_gettext "\$pkg_list is older than one week... recharging"; echo
2325 tazpkg recharge $repo_name
2326 fi
2327 done
2328 emsg "<n><b>$(gettext 'Package')</b><i 28> $(gettext 'Version')<i 48> $(gettext 'Status')<->"
2329 cd $INSTALLED
2330 newline > $UP_LIST
2331 blocked_count=0
2332 for pkg in *
2333 do
2334 unset VERSION EXTRAVERSION
2335 . $pkg/receipt
2336 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2337 $installed_sum | awk '{print $1}')
2338 for repo in $priority; do
2339 pkg_desc=$repo/packages.desc
2340 pkg_list=$repo/packages.list
2341 pkg_sum=$repo/packages.$SUM
2343 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2344 # Jump to next repository in priority if pkg doesn't exists
2345 # in this one.
2346 grep -q ^$PACKAGE- $pkg_list || continue
2348 emsg -n "$PACKAGE<i 28> $VERSION"
2350 # Skip pkgs listed in $LOCALSTATE/blocked-packages.list
2351 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2352 blocked_count=$(($blocked_count + 1))
2353 emsg "<i 48><c 31> $(gettext 'Blocked')</c>"
2354 break
2355 fi
2357 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2359 if [ "$VERSION" == "$new" ]; then
2360 emsg "<i 48><c 34> $(gettext 'New build')</c>"
2361 else
2362 emsg "<i 48><c 32> $(eval_gettext 'New version $new')</c>"
2363 fi
2364 echo "$PACKAGE" >> $UP_LIST
2365 break
2366 fi
2367 done
2368 done
2369 sed -i /^$/d $UP_LIST
2370 upnb=$(cat $UP_LIST | wc -l)
2371 pkgs=$(ls | wc -l)
2372 time=$(($(date +%s) - $time))
2373 if [ "$upnb" = 0 ]; then
2374 install="n"
2375 gettext "System is up-to-date..."; echo
2376 newline
2377 fi
2378 num=$(emsg "<c 32>$new_pkgs</c>")
2379 footer "$(eval_ngettext \
2380 '$num installed package scanned in ${time}s' \
2381 '$num installed packages scanned in ${time}s' $pkgs)"
2382 if [ "$upnb" != 0 ]; then
2383 if [ "$blocked_count" -gt 0 ]; then
2384 num=$blocked_count
2385 blocked=$(eval_ngettext '$num blocked' '$num blocked' $num)
2386 fi
2387 num=$upnb
2388 boldify "$(eval_ngettext \
2389 'You have $num available upgrade ($blocked)' \
2390 'You have $num available upgrades ($blocked)' $num)"
2391 newline
2392 fi
2393 # Pkgs to upgrade ? Skip, let install them all or ask user
2394 [ "$install" == "n" ] && exit 0
2395 if [ "$upnb" -gt 0 ]; then
2396 if [ "$install" == "y" ]; then
2397 continue
2398 else
2399 gettext "Do you wish to install them now: y/n ? "
2400 read install
2401 fi
2402 case "$install" in
2403 y|Y|yes|YES|Yes)
2404 for pkg in $(cat $UP_LIST)
2405 do
2406 echo 'y' | tazpkg get-install $pkg --forced
2407 done
2408 # List is generated each time and must be cleaned so
2409 # tazpkg-notify don't find upgrade anymore.
2410 rm $UP_LIST && touch $UP_LIST ;;
2411 *)
2412 gettext "Leaving without any upgrades installed."; echo
2413 newline
2414 exit 0 ;;
2415 esac
2416 fi
2417 newline ;;
2418 bugs)
2419 # Show known bugs in package(s)
2420 cd $INSTALLED
2421 shift
2422 LIST=$@
2423 [ -n "$LIST" ] || LIST=`ls`
2424 MSG=$(gettext "No known bugs.")
2425 for PACKAGE in $LIST; do
2426 BUGS=""
2427 EXTRAVERSION=""
2428 . $PACKAGE/receipt
2429 if [ -n "$BUGS" ]; then
2430 MSG=$(gettext "Bug list completed")
2431 newline
2432 eval_gettext "Bugs in package \$PACKAGE version \$VERSION\$EXTRAVERSION:"; echo
2433 cat <<EOT
2434 $BUGS
2435 EOT
2436 fi
2437 done
2438 echo "$MSG" ;;
2439 check)
2440 # Check installed packages set.
2441 check_root $@
2443 # Get repositories priority list.
2444 look_for_priority
2446 cd $INSTALLED
2447 for PACKAGE in `ls`; do
2448 if [ ! -f $PACKAGE/receipt ]; then
2449 eval_gettext "The package \$PACKAGE installation has not completed"; echo
2450 continue
2451 fi
2452 DEPENDS=""
2453 EXTRAVERSION=""
2454 . $PACKAGE/receipt
2455 if [ -s $PACKAGE/modifiers ]; then
2456 eval_gettext \
2457 "The package \$PACKAGE-\$VERSION\$EXTRAVERSION has been modified by:"; echo
2458 for i in $(cat $PACKAGE/modifiers); do
2459 echo " $i"
2460 done
2461 fi
2462 MSG="$(eval_gettext 'Files lost from $PACKAGE-$VERSION$EXTRAVERSION:')\n"
2463 while read file; do
2464 [ -e "$file" ] && continue
2465 if [ -L "$file" ]; then
2466 MSG="$MSG $(gettext 'target of symlink')"
2467 fi
2468 echo -e "$MSG $file"
2469 MSG=""
2470 done < $PACKAGE/files.list
2471 MSG="$(eval_gettext 'Missing dependencies for $PACKAGE-$VERSION$EXTRAVERSION:')\n"
2472 for i in $DEPENDS; do
2473 [ -d $i ] && continue
2474 [ -d $(equivalent_pkg $i) ] && continue
2475 echo -e "$MSG $i"
2476 MSG=""
2477 done
2478 MSG="$(eval_gettext 'Dependencies loop between $PACKAGE and:')\n"
2479 ALL_DEPS=""
2480 check_for_deps_loop $PACKAGE $DEPENDS
2481 done
2482 gettext "Looking for known bugs..."; echo
2483 tazpkg bugs
2484 if [ "$PACKAGE_FILE" = "--full" ]; then
2485 for file in */$CHECKSUM; do
2486 CONFIG_FILES=""
2487 . $(dirname "$file")/receipt
2488 [ -s "$file" ] || continue
2489 while read md5 f; do
2490 [ -f $f ] || continue
2491 for i in $CONFIG_FILES; do
2492 case "$f" in
2493 $i|$i/*) continue 2;;
2494 esac
2495 done
2496 echo "$md5 $f"
2497 done < "$file" | $CHECKSUM -c - 2> /dev/null | \
2498 grep -v OK$ | sed 's/FAILED$/$CHECKSUM MISMATCH/'
2499 done
2500 FILES=" "
2501 for file in $(cat */files.list); do
2502 [ -d "$file" ] && continue
2503 case "$FILES" in *\ $file\ *) continue;; esac
2504 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2505 wc -l) -gt 1 ] || continue
2506 FILES="$FILES$file "
2507 eval_gettext "The following packages provide \$file:"; echo
2508 grep -l "^$(echo $file | grepesc)$" */files.list | while read f
2509 do
2510 pkg=${f%/files.list}
2511 if [ -f $pkg/modifiers ]; then
2512 pkg_list="$(cat $pkg/modifiers)"
2513 overriders=$(eval_gettext '(overridden by $pkg_list)')
2514 else
2515 overriders=''
2516 fi
2517 echo -n " $pkg $overriders"
2518 newline
2519 done
2520 done
2521 MSG="$(gettext 'No package has installed the following files:')\n"
2522 find /etc /bin /sbin /lib /usr /var/www \
2523 -not -type d 2> /dev/null | while read file; do
2524 case "$file" in *\[*) continue;; esac
2525 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2526 echo -e "$MSG $file"
2527 MSG=""
2528 done
2529 fi
2530 gettext "Check completed."; echo ;;
2531 block)
2532 # Add a pkg name to the list of blocked packages.
2533 check_root $@
2534 check_for_package_on_cmdline
2535 newline
2536 if grep -qs "^$PACKAGE" $BLOCKED; then
2537 eval_gettext "\$PACKAGE is already in the blocked packages list."; echo
2538 newline
2539 exit 0
2540 else
2541 action "Add \$PACKAGE to: \$BLOCKED..."
2542 echo $PACKAGE >> $BLOCKED
2543 status
2544 # Log this activity
2545 . $INSTALLED/$PACKAGE/receipt
2546 log_pkg Blocked
2547 fi
2548 newline ;;
2549 unblock)
2550 # Remove a pkg name from the list of blocked packages.
2551 check_root $@
2552 check_for_package_on_cmdline
2553 newline
2554 if grep -qs "^$PACKAGE" $BLOCKED; then
2555 action "Removing \$PACKAGE from: \$BLOCKED..."
2556 sed -i s/$PACKAGE/''/ $BLOCKED
2557 sed -i '/^$/d' $BLOCKED
2558 status
2559 # Log this activity
2560 . $INSTALLED/$PACKAGE/receipt
2561 log_pkg Unblocked
2562 else
2563 eval_gettext "\$PACKAGE is not in the blocked packages list."; echo
2564 newline
2565 exit 0
2566 fi
2567 newline ;;
2568 get)
2569 # Download a package with wget.
2570 check_root $@
2571 check_for_package_on_cmdline
2572 check_for_packages_list
2574 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2575 if [ "$rootconfig" ]; then
2576 if [ "$root" ]; then
2577 CACHE_DIR=$root/$CACHE_DIR
2578 SAVE_CACHE_DIR=$CACHE_DIR
2579 LOCALSTATE=$root/$LOCALSTATE
2580 else
2581 gettext "rootconfig needs --root= option used." >&2
2582 echo >&2
2583 exit 1
2584 fi
2585 fi
2587 # Get repositories priority list.
2588 look_for_priority
2590 CURRENT_DIR=$PWD
2591 check_for_package_in_list
2592 cd $CACHE_DIR
2593 if [ -f "$PACKAGE.tazpkg" ]; then
2594 eval_gettext "\$PACKAGE already in the cache: \$CACHE_DIR"; echo
2595 # Check package download was finished
2596 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2597 eval_gettext "Continuing \$PACKAGE download"; echo
2598 download $PACKAGE.tazpkg
2600 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2601 rm -f $PACKAGE.tazpkg
2602 download $PACKAGE.tazpkg
2603 fi
2604 else
2605 download $PACKAGE.tazpkg
2606 fi
2607 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2608 cp -a $PACKAGE_FILE $CURRENT_DIR
2609 ;;
2610 get-install|-gi)
2611 # Download and install a package.
2612 check_root $@
2613 check_for_package_on_cmdline
2614 check_for_packages_list
2616 DO_CHECK=""
2617 [ "$forced" ] && DO_CHECK=no
2618 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2619 [ "$list" ] && INSTALL_LIST="$list"
2620 if [ "$rootconfig" ]; then
2621 if [ "$root" ]; then
2622 CACHE_DIR=$root/$CACHE_DIR
2623 SAVE_CACHE_DIR=$CACHE_DIR
2624 LOCALSTATE=$root/$LOCALSTATE
2625 else
2626 gettext "rootconfig needs --root= option used." >&2
2627 echo >&2
2628 exit 1
2629 fi
2630 fi
2632 # Get repositories priority list.
2633 look_for_priority
2635 AUTOEXEC="no"
2636 if ! check_for_package_in_list check; then
2637 PACKAGE=get-$PACKAGE
2638 AUTOEXEC=$PACKAGE
2639 check_for_package_in_list
2640 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2641 CACHE_DIR="${CACHE_DIR%/*}/get"
2642 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2643 $AUTOEXEC $ROOT
2644 exit 0
2645 fi
2646 fi
2647 # Check if forced install.
2648 if ! [ "$forced" ]; then
2649 check_for_installed_package $ROOT
2650 fi
2651 cd $CACHE_DIR
2652 if [ -f "$PACKAGE.tazpkg" ]; then
2653 eval_gettext "\$PACKAGE already in the cache: \$CACHE_DIR"; echo
2654 # Check package download was finished
2655 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2656 eval_gettext "Continuing \$PACKAGE download"; echo
2657 download $PACKAGE.tazpkg
2659 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2660 rm -f $PACKAGE.tazpkg
2661 download $PACKAGE.tazpkg
2662 fi
2663 else
2664 newline
2665 download $PACKAGE.tazpkg
2666 fi
2667 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2668 [ "$rootconfig" ] && LOCALSTATE=${LOCALSTATE#$root}
2669 install_package $ROOT
2670 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2671 update_desktop_database $ROOT
2672 update_mime_database $ROOT ;;
2673 clean-cache|-cc)
2674 # Remove all downloaded packages.
2675 check_root $@
2676 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2677 title 'Clean cache: $CACHE_DIR'
2678 action "Cleaning cache directory..."
2679 rm -rf $CACHE_DIR/*
2680 status
2681 num=$(emsg "<c 32>$new_pkgs</c>")
2682 footer "$(eval_ngettext \
2683 '$num file removed from cache.' \
2684 '$num files removed from cache.' $files)"
2685 ;;
2686 list-undigest)
2687 # list undigest URLs.
2688 if [ "$2" = "--box" ]; then
2689 for i in $LOCALSTATE/undigest/*/mirror; do
2690 [ -f $i ] || continue
2691 echo "$(basename $(dirname $i))|$(cat $i)"
2692 done
2693 else
2694 title 'Current undigest(s)'
2695 for i in $LOCALSTATE/undigest/*/mirror; do
2696 if [ ! -f $i ]; then
2697 gettext "No undigest mirror found."; echo
2698 exit 1
2699 fi
2700 echo "$(basename $(dirname $i)) $(cat $i)"
2701 done
2702 newline
2703 fi ;;
2704 remove-undigest)
2705 # remove undigest URL.
2706 check_root $@
2707 undigest="$2"
2708 if [ -d $LOCALSTATE/undigest/$2 ]; then
2709 eval_gettext "Remove \$undigest undigest" && confirm
2710 if [ $? = 0 ]; then
2711 action "Removing \$undigest undigest..."
2712 rm -rf $LOCALSTATE/undigest/$2
2713 status
2714 rmdir $LOCALSTATE/undigest 2> /dev/null
2715 fi
2716 else
2717 eval_gettext "Undigest \$undigest not found"; echo
2718 fi ;;
2719 add-undigest|setup-undigest)
2720 # Add undigest URL.
2721 check_root $@
2722 undigest=$2
2723 [ -d $LOCALSTATE/undigest ] || mkdir $LOCALSTATE/undigest
2724 if [ -z "$undigest" ]; then
2725 i=1
2726 while [ -d $LOCALSTATE/undigest/$i ]; do
2727 i=$(($i+1))
2728 done
2729 undigest=$i
2730 fi
2731 if [ ! -d $LOCALSTATE/undigest/$undigest ]; then
2732 eval_gettext "Creating new undigest \$undigest."; echo
2733 mkdir $LOCALSTATE/undigest/$undigest
2734 fi
2735 setup_mirror $LOCALSTATE/undigest/$undigest $3 ;;
2736 setup-mirror|-sm)
2737 # Change mirror URL.
2738 check_root $@
2739 setup_mirror $LOCALSTATE $2 ;;
2740 reconfigure)
2741 # Replay post_install from receipt
2742 check_for_package_on_cmdline
2743 check_root $@
2744 ROOT=""
2745 while [ -n "$3" ]; do
2746 case "$3" in
2747 --root=*)
2748 ROOT="${3#--root=}/" ;;
2749 *) shift 2
2750 u_opt="$*"
2751 echo -e "\n$(gettext 'Unknown option $u_opt.')\n" >&2
2752 exit 1 ;;
2753 esac
2754 shift
2755 done
2756 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2757 check_for_receipt $ROOT
2758 # Check for post_install
2759 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2760 . $ROOT$INSTALLED/$PACKAGE/receipt
2761 post_install $ROOT
2762 # Log this activity
2763 [ -n "$ROOT" ] || log_pkg Reconfigured
2764 else
2765 newline
2766 eval_gettext "Nothing to do for \$PACKAGE."; echo
2767 fi
2768 else
2769 newline
2770 eval_gettext "Package \$PACKAGE is not installed."; echo
2771 gettext "Install package with 'tazpkg install' or 'tazpkg get-install'"; echo
2772 newline
2773 fi ;;
2774 shell)
2775 # TazPkg SHell
2776 if test $(id -u) = 0 ; then
2777 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2778 else
2779 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2780 fi
2781 if [ ! "$2" = "--noheader" ]; then
2782 clear
2783 title 'TazPkg SHell.'
2784 gettext "Type 'usage' to list all available commands or 'quit' or 'q' to exit."; echo
2785 newline
2786 fi
2787 while true
2788 do
2789 echo -en "$PROMPT"; read cmd
2790 case $cmd in
2791 q|quit)
2792 break ;;
2793 shell)
2794 gettext "You are already running a TazPkg SHell."; echo ;;
2795 su)
2796 su -c 'exec tazpkg shell --noheader' && break ;;
2797 "")
2798 continue ;;
2799 *)
2800 tazpkg $cmd ;;
2801 esac
2802 done ;;
2803 depends)
2804 # Display dependencies tree
2805 cd $INSTALLED
2806 ALL_DEPS=""
2807 if [ -f $2/receipt ]; then
2808 dep_scan $2 ""
2809 fi ;;
2810 rdepends)
2811 # Display reverse dependencies tree
2812 cd $INSTALLED
2813 ALL_DEPS=""
2814 if [ -f $2/receipt ]; then
2815 rdep_scan $2
2816 fi ;;
2817 convert|-c)
2818 # convert misc package format to .tazpkg
2819 check_for_package_file
2820 [ -n "$TARGET_DIR" -a -s "$TARGET_DIR/files.list.lzma" ] &&
2821 TMPLOCALSTATE="$TARGET_DIR"
2822 if [ "$(dd if=$PACKAGE_FILE bs=8 count=1 skip=1 2> /dev/null)" \
2823 == "debian-b" ]; then
2824 convert_deb
2825 else
2826 case "$PACKAGE_FILE" in
2827 *.deb|*.udeb)
2828 convert_deb;;
2829 *.rpm)
2830 convert_rpm;;
2831 *.pet)
2832 convert_pet;;
2833 *.tgz)
2834 convert_tgz;;
2835 *.apk|*.pkg.tar.gz)
2836 convert_arch;;
2837 *.ipk|*.opk)
2838 convert_ipk;;
2839 *)
2840 gettext "Unsupported format"; echo ;;
2841 esac
2842 fi ;;
2843 link)
2844 # link a package from another slitaz installation
2845 PACKAGE=$2
2846 if [ ! -d "$TARGET_DIR" -o \
2847 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2848 gettext "
2849 usage: tazpkg link package_name slitaz_root
2850 example: 'tazpkg link openoffice /mnt' will use less than 100k in
2851 your running system ram.
2853 exit 1
2854 fi
2855 if [ -e "$INSTALLED/$PACKAGE" ]; then
2856 eval_gettext "\$PACKAGE is already installed."; echo
2857 exit 1
2858 fi
2859 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2860 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2861 MISSING=""
2862 for i in $DEPENDS; do
2863 [ -e $INSTALLED/$i ] && continue
2864 MISSING="$MISSING$i "
2865 eval_gettext "Missing: \$i"; echo
2866 done
2867 if [ -n "$MISSING" ]; then
2868 newline
2869 gettext "Link all missing dependencies" && confirm
2870 answer=$?
2871 newline
2872 if [ $answer = 0 ]; then
2873 for i in $MISSING; do
2874 tazpkg link $i $TARGET_DIR
2875 done
2876 else
2877 newline
2878 eval_gettext "Leaving dependencies unresolved for: \$PACKAGE"; echo
2879 gettext "The package is installed but probably will not work."; echo
2880 newline
2881 fi
2882 fi
2883 . $INSTALLED/$PACKAGE/receipt
2884 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2885 pre_install
2886 fi
2887 while read path; do
2888 [ -e $path ] && continue
2889 while true; do
2890 dir=$(dirname $path)
2891 [ -e $dir ] && break
2892 path=$dir
2893 done
2894 ln -s $TARGET_DIR$path $dir
2895 done < $INSTALLED/$PACKAGE/files.list
2896 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2897 post_install
2898 fi ;;
2899 usage|*)
2900 # Print a short help or give usage for an unknown or empty command.
2901 usage ;;
2902 esac
2904 exit 0