tazpkg view tazpkg @ rev 632

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