tazpkg view tazpkg @ rev 631

convert/deb: add license
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jul 04 09:44:37 2013 +0200 (2013-07-04)
parents 889e293abdc7
children 85d62a4756ce
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 [ "$DEPENDS" ] && emsg "<b>$(gettext 'Depends :')</b> $DEPENDS"
1539 [ "$SUGGESTED" ] && emsg "<b>$(gettext 'Suggested :')</b> $SUGGESTED"
1540 [ "$BUILD_DEPENDS" ] && emsg "<b>$(gettext 'Build deps :')</b> $BUILD_DEPENDS"
1541 [ "$WANTED" ] && emsg "<b>$(gettext 'Wanted src :')</b> $WANTED"
1542 [ "$WEB_SITE" ] && emsg "<b>$(gettext 'Web site :')</b> $WEB_SITE"
1543 footer
1544 ;;
1545 desc)
1546 # Display package description.txt if available.
1547 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
1548 title 'Description of: $PACKAGE'
1549 cat $INSTALLED/$PACKAGE/description.txt
1550 footer
1551 else
1552 newline
1553 gettext "Sorry, no description available for this package."; echo
1554 newline
1555 fi ;;
1556 search|-s)
1557 # Search for a package by pattern or name.
1558 PATTERN="$2"
1559 if [ -z "$PATTERN" ]; then
1560 newline
1561 gettext "Please specify a pattern or package name to search for."; echo
1562 gettext "Example : 'tazpkg search paint'"; echo
1563 newline
1564 exit 0
1565 fi
1566 title 'Search result for: $PATTERN'
1567 # Default is to search in installed pkgs and the raw list.
1568 case $3 in
1569 -i|--installed)
1570 search_in_installed_packages ;;
1571 -l|--list)
1572 search_in_packages_list ;;
1573 -m|--mirror)
1574 search_in_packages_txt ;;
1575 *)
1576 search_in_installed_packages
1577 search_in_packages_list ;;
1578 esac ;;
1579 search-file|-sf)
1580 # Search for a file by pattern or name in all files.list.
1581 if [ -z "$2" ]; then
1582 newline
1583 gettext "Please specify a pattern or file name to search for."; echo
1584 gettext "Example : 'tazpkg search-file libnss'"; echo
1585 newline
1586 exit 0
1587 fi
1588 s_file="$2"
1589 title 'Search result for file $s_file'
1591 if [ "$3" == "--mirror" ]; then
1593 match=0
1594 for i in $LOCALSTATE/files.list.lzma \
1595 $LOCALSTATE/undigest/*/files.list.lzma; do
1596 [ -f $i ] || continue
1597 unlzma -c $i | grep -- ".*:.*$2" | awk '
1598 BEGIN { last="" }
1600 pkg=substr($0,0,index($0,":")-1);
1601 file=substr($0,index($0,":")+2);
1602 if (last != pkg) {
1603 last = pkg;
1604 printf("\n%c[1mPackage %s:%c[0m\n",27,pkg,27);
1606 printf("%s\n",file);
1607 }'
1608 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | wc -l`))
1609 done
1611 else
1613 # Check all pkg files.list in search match which specify the package
1614 # name and the full path to the file(s).
1615 for pkg in $INSTALLED/*
1616 do
1617 if grep -qs "$2" $pkg/files.list; then
1618 . $pkg/receipt
1619 newline
1620 boldify "$(eval_gettext 'Package $PACKAGE:')"
1621 grep "$2" $pkg/files.list
1622 files=`grep $2 $pkg/files.list | wc -l`
1623 match=$(($match+$files))
1624 fi
1625 done
1627 fi
1628 pkg=$2
1629 if [ "$match" = "" ]; then
1630 eval_gettext "0 file found for: \$pkg"; echo
1631 else
1632 footer "$(eval_ngettext \
1633 '$match file found for: $pkg' \
1634 '$match files found for: $pkg' $match)"
1635 fi
1636 ;;
1637 search-pkgname)
1638 # Search for a package name
1639 if [ -z "$2" ]; then
1640 newline
1641 gettext "Please specify a pattern or file name to search for."; echo
1642 gettext "Example : 'tazpkg search-pkgname libnss'"; echo
1643 newline
1644 exit 0
1645 fi
1646 s_pkg="$2"
1647 title 'Search result for package $s_pkg'
1649 # Search for a file on mirror and output only the package name
1650 match=0
1651 for i in $LOCALSTATE/files.list.lzma \
1652 $LOCALSTATE/undigest/*/files.list.lzma; do
1653 [ -f $i ] || continue
1654 unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | awk '{ print $1 }'
1655 match=$(($match + `unlzma -c $i | grep -- ".*:.*$2" | cut -d: -f1 | uniq | wc -l`))
1656 done
1657 file=$2
1658 if [ "$match" = "0" ]; then
1659 eval_gettext "0 file found for: \$file"; echo
1660 newline
1661 else
1662 footer "$(eval_ngettext \
1663 '$match package found with file: $file' \
1664 '$match packages found with file: $file' $match)"
1665 fi
1666 ;;
1667 install|-i)
1668 # Install .tazpkg packages.
1669 check_root $@
1670 check_for_package_on_cmdline
1671 check_for_package_file
1673 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
1674 [ "$list" ] && INSTALL_LIST="$list"
1675 if [ "$rootconfig" ]; then
1676 if [ "$root" ]; then
1677 CACHE_DIR=$root/$CACHE_DIR
1678 SAVE_CACHE_DIR=$CACHE_DIR
1679 LOCALSTATE=$root/$LOCALSTATE
1680 else
1681 echo "rootconfig needs --root= option used." >&2
1682 exit 1
1683 fi
1684 fi
1686 # Get repositories priority list.
1687 look_for_priority
1689 # Check if forced install.
1690 if ! [ "$forced" ]; then
1691 check_for_installed_package $ROOT
1692 fi
1693 install_package $ROOT
1694 update_desktop_database $ROOT
1695 update_mime_database $ROOT
1696 update_icon_database $ROOT
1697 compile_glib_schemas $ROOT ;;
1698 install-list|get-install-list)
1699 # Install a set of packages from a list.
1700 check_root $@
1701 if [ -z "$2" ]; then
1702 newline
1703 gettext \
1704 "Please change directory (cd) to the packages repository and specify the
1705 list of packages to install. Example: tazpkg install-list packages.list"
1706 newline && exit 0
1707 fi
1708 # Check if the packages list exist.
1709 list_file=$2
1710 if [ ! -f "$list_file" ]; then
1711 eval_gettext "Unable to find: \$list_file"; echo
1712 exit 0
1713 else
1714 LIST=`cat $2`
1715 fi
1717 # Remember processed list
1718 export INSTALL_LIST="$2"
1720 # Set $COMMAND and install all packages.
1721 if [ "$1" = "get-install-list" ]; then
1722 COMMAND=get-install
1723 else
1724 COMMAND=install
1725 fi
1726 touch $2-processed
1728 # Upgrade tazpkg first. It may handle new features/formats...
1729 # then upgrade essential packages early
1730 for pkg in busybox-pam busybox gcc-lib-base glibc-base \
1731 slitaz-base-files tazpkg ; do
1732 pkg=$(egrep $pkg-[0-9] $INSTALL_LIST)
1733 [ -n "$pkg" ] || continue
1734 eval_gettext "Adding implicit depends \$pkg..."; echo
1735 LIST="$pkg
1736 $LIST"
1737 done
1739 for pkg in $LIST
1740 do
1741 grep -qs ^$pkg$ $2-processed && continue
1742 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1743 done
1744 rm -f $2-processed ;;
1745 add-flavor)
1746 # Install a set of packages from a flavor.
1747 install_flavor $2 ;;
1748 install-flavor)
1749 # Install a set of packages from a flavor and purge other ones.
1750 install_flavor $2 --purge ;;
1751 set-release)
1752 # Change curent release and upgrade packages.
1753 RELEASE=$2
1754 if [ -z "$RELEASE" ]; then
1755 newline
1756 gettext "Please specify the release you want on the command line."; echo
1757 gettext "Example: tazpkg set-release cooking"; echo
1758 newline
1759 exit 0
1760 fi
1761 rm $LOCALSTATE/mirror
1762 echo "$RELEASE" > /etc/slitaz-release
1763 tazpkg recharge && tazpkg upgrade
1765 # Install missing depends
1766 cd $INSTALLED
1767 for i in * ; do
1768 DEPENDS=""
1769 . $i/receipt
1770 for j in $DEPENDS ; do
1771 [ -d $j ] || tazpkg get-install $j
1772 done
1773 done ;;
1774 remove|-r)
1775 # Remove packages.
1776 check_root $@
1777 check_for_package_on_cmdline
1779 [ "$root" ] && ROOT="$root"
1780 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then
1781 newline
1782 eval_gettext "\$PACKAGE is not installed."; echo
1783 exit 0
1784 else
1785 ALTERED=""
1786 THE_PACKAGE=$PACKAGE # altered by receipt
1787 for i in $(cd $ROOT$INSTALLED ; ls); do
1788 [ -f $ROOT$INSTALLED/$i/receipt ] || continue
1789 DEPENDS=""
1790 . $ROOT$INSTALLED/$i/receipt
1791 case " $(echo $DEPENDS) " in
1792 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1793 esac
1794 done
1795 EXTRAVERSION=""
1796 . $ROOT$INSTALLED/$THE_PACKAGE/receipt
1797 fi
1798 newline
1799 if [ -n "$ALTERED" ]; then
1800 eval_gettext "The following packages depend on \$PACKAGE:"; echo
1801 for i in $ALTERED; do
1802 echo " $i"
1803 done
1804 fi
1805 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1806 if [ -n "$REFRESH" ]; then
1807 eval_gettext "The following packages have been modified by \$PACKAGE:"; echo
1808 for i in $REFRESH; do
1809 echo " ${i%/modifiers}"
1810 done
1811 fi
1812 if [ "$auto" ]; then
1813 answer=0
1814 else
1815 eval_gettext "Remove \$PACKAGE (\$VERSION\$EXTRAVERSION)" && confirm
1816 answer=$?
1817 fi
1818 if [ $answer = 0 ]; then
1819 title 'Removing: $PACKAGE'
1820 # Pre remove commands.
1821 if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1822 pre_remove $ROOT
1823 fi
1824 action "Removing all files installed..."
1825 if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then
1826 for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
1827 do
1828 for mod in `cat $ROOT$INSTALLED/$PACKAGE/modifiers`
1829 do
1830 [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2
1831 done
1832 remove_with_path $ROOT$file
1833 done
1834 else
1835 for file in `cat $ROOT$INSTALLED/$PACKAGE/files.list`
1836 do
1837 remove_with_path $ROOT$file
1838 done
1839 fi
1840 status
1841 if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then
1842 post_remove $ROOT
1843 fi
1844 # Remove package receipt.
1845 action "Removing package receipt..."
1846 rm -rf $ROOT$INSTALLED/$PACKAGE
1847 status
1848 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \
1849 $LOCALSTATE/installed.$SUM 2> /dev/null
1850 # Log this activity
1851 log_pkg Removed
1852 if [ "$ALTERED" ]; then
1853 if [ "$auto" ]; then
1854 answer=0
1855 else
1856 eval_gettext "Remove packages depending on \$PACKAGE" && confirm
1857 answer=$?
1858 fi
1859 if [ $answer = 0 ]; then
1860 for i in $ALTERED; do
1861 if [ -d "$ROOT$INSTALLED/$i" ]; then
1862 tazpkg remove $i $ROOTOPTS
1863 fi
1864 done
1865 fi
1866 fi
1867 if [ "$REFRESH" ]; then
1868 if [ "$auto" ]; then
1869 answer=0
1870 else
1871 eval_gettext "Reinstall packages modified by \$PACKAGE" && confirm
1872 answer=$?
1873 fi
1874 if [ $answer = 0 ]; then
1875 for i in $REFRESH; do
1876 if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then
1877 eval_gettext "Check \$INSTALLED/\$i for reinstallation"; echo
1878 continue
1879 fi
1880 rm -r $ROOT$INSTALLED/$i
1881 tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced
1882 done
1883 fi
1884 fi
1885 else
1886 newline
1887 eval_gettext "Uninstallation of \$PACKAGE cancelled."; echo
1888 fi
1889 newline ;;
1890 extract|-e)
1891 # Extract .tazpkg cpio archive into a directory.
1892 check_for_package_on_cmdline
1893 check_for_package_file
1894 title 'Extracting: $PACKAGE'
1895 # If no directory destination is found on the cmdline
1896 # we create one in the current dir using the package name.
1897 if [ -n "$TARGET_DIR" ]; then
1898 DESTDIR=$TARGET_DIR/$PACKAGE
1899 else
1900 DESTDIR=$PACKAGE
1901 fi
1902 mkdir -p $DESTDIR
1903 action "Copying original package..."
1904 cp $PACKAGE_FILE $DESTDIR
1905 status
1906 cd $DESTDIR
1907 extract_package
1908 [ -e "receipt" ] && footer "$(eval_gettext '$PACKAGE is extracted to: $DESTDIR')"
1909 ;;
1910 recompress)
1911 # Recompress .tazpkg cpio archive with lzma.
1912 check_for_package_on_cmdline
1913 check_for_package_file
1914 title 'Recompressing: $PACKAGE'
1915 mkdir -p $TMP_DIR
1916 action "Copying original package..."
1917 cp $PACKAGE_FILE $TMP_DIR
1918 status
1919 cd $TMP_DIR
1920 extract_package
1921 action "Recompressing the fs..."
1922 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1923 rm -rf fs
1924 status
1925 action "Creating new package..."
1926 find . -print | cpio -o -H newc --quiet > \
1927 $TOP_DIR/$(basename $PACKAGE_FILE).$$ && mv -f \
1928 $TOP_DIR/$(basename $PACKAGE_FILE).$$ \
1929 $TOP_DIR/$(basename $PACKAGE_FILE)
1930 status
1931 cd $TOP_DIR
1932 rm -rf $TMP_DIR
1933 separator; newline ;;
1934 list-config)
1935 # List configuration files installed.
1936 if [ "$2" = "--box" ]; then
1937 mkdir -p $TMP_DIR && cd $TMP_DIR
1938 FILES="$INSTALLED/*/volatile.cpio.gz"
1939 [ -n "$3" ] && FILES="$INSTALLED/$3/volatile.cpio.gz"
1940 for i in $FILES; do
1941 zcat $i | cpio -idm --quiet > /dev/null
1942 find * -type f 2>/dev/null | while read file; do
1943 if [ ! -e /$file ]; then
1944 echo -en "----------|----|----|`gettext \"File lost\"`"
1945 else
1946 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1947 cmp $file /$file > /dev/null 2>&1 || \
1948 echo -n "$(stat -c "%.16y" /$file)"
1949 fi
1950 echo "|/$file"
1951 done
1952 rm -rf *
1953 done
1954 cd $TOP_DIR
1955 rm -rf $TMP_DIR
1956 else
1957 title 'Configuration files'
1958 for i in $INSTALLED/*/volatile.cpio.gz; do
1959 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1960 [ -f "$i" ] || continue
1961 zcat $i | cpio -t --quiet
1962 done | sed 's|^|/|' | sort
1963 separator
1964 newline
1965 fi ;;
1966 repack-config)
1967 # Create SliTaz package archive from configuration files.
1968 mkdir -p $TMP_DIR && cd $TMP_DIR
1969 CONFIG_VERSION=1.0
1970 mkdir config-$CONFIG_VERSION
1971 cd config-$CONFIG_VERSION
1972 for i in $INSTALLED/*/volatile.cpio.gz; do
1973 zcat $i | cpio -t --quiet
1974 done > files.list
1975 mkdir fs
1976 cd fs
1977 ( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
1978 mkdir -p etc/tazlito
1979 for i in $INSTALLED/*/receipt; do
1980 EXTRAVERSION=""
1981 . $i
1982 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1983 done > etc/tazlito/config-packages.list
1984 cd ..
1985 echo "etc/tazlito/config-packages.list" >> files.list
1986 pkg_date=$(date +"%x %X")
1987 cat > receipt <<EOT
1988 # SliTaz package receipt.
1990 PACKAGE="config"
1991 VERSION="$CONFIG_VERSION"
1992 CATEGORY="base-system"
1993 SHORT_DESC="$(eval_gettext 'User configuration backup on $pkg_date')"
1994 DEPENDS="$(ls $INSTALLED)"
1995 EOT
1996 cd ..
1997 tazpkg pack config-$CONFIG_VERSION
1998 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
1999 cd $TOP_DIR
2000 rm -rf $TMP_DIR
2001 ;;
2002 repack)
2003 # Create SliTaz package archive from an installed package.
2004 check_for_package_on_cmdline
2005 check_for_receipt
2006 EXTRAVERSION=""
2007 . $INSTALLED/$PACKAGE/receipt
2008 title 'Repacking: $PACKAGE-$VERSION$EXTRAVERSION.tazpkg'
2009 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
2010 eval_gettext "Can't repack \$PACKAGE"; echo
2011 exit 1
2012 fi
2013 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
2014 eval_gettext "Can't repack, \$PACKAGE files have been modified by:"; echo
2015 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
2016 echo " $i"
2017 done
2018 exit 1
2019 fi
2020 MISSING=""
2021 while read i; do
2022 [ -e "$i" ] && continue
2023 [ -L "$i" ] || MISSING="$MISSING\n $i"
2024 done < $INSTALLED/$PACKAGE/files.list
2025 if [ -n "$MISSING" ]; then
2026 gettext "Can't repack, the following files are lost:"
2027 echo -e "$MISSING"
2028 exit 1
2029 fi
2030 mkdir -p $TMP_DIR && cd $TMP_DIR
2031 FILES="fs.cpio.lzma\n"
2032 for i in $(ls $INSTALLED/$PACKAGE) ; do
2033 [ "$i" = "volatile.cpio.gz" ] && continue
2034 [ "$i" = "modifiers" ] && continue
2035 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
2036 done
2037 ln -s / rootfs
2038 mkdir tmp
2039 sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet |\
2040 { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
2041 mv tmp/rootfs fs
2042 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
2043 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
2044 { cd fs; cpio -idm --quiet; cd ..; }
2045 fi
2046 if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
2047 . $INSTALLED/$PACKAGE/receipt
2048 repack_cleanup fs
2049 fi
2050 if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
2051 sed 's, , fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
2052 $CHECKSUM -s -c || {
2053 eval_gettext "Can't repack, \$CHECKSUM error."; echo
2054 cd $TOP_DIR
2055 rm -rf $TMP_DIR
2056 exit 1
2058 fi
2059 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2060 echo -e "$FILES" | cpio -o -H newc --quiet > \
2061 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
2062 cd $TOP_DIR
2063 \rm -R $TMP_DIR
2064 eval_gettext "Package \$PACKAGE repacked successfully."; echo
2065 pkg_size=$(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)
2066 eval_gettext "Size: \$pkg_size"; echo
2067 newline ;;
2068 pack)
2069 # Create SliTaz package archive using cpio and lzma.
2070 # TODO: Cook also pack packages, we should share code in libpkg.sh
2071 check_for_package_on_cmdline
2072 cd $PACKAGE
2073 if [ ! -f "receipt" ]; then
2074 gettext "Receipt is missing. Please read the documentation."; echo
2075 exit 0
2076 else
2077 title 'Packing: $PACKAGE'
2078 # Create files.list with redirecting find outpout.
2079 action "Creating the list of files..."
2080 cd fs
2081 find . -type f -print > ../files.list
2082 find . -type l -print >> ../files.list
2083 cd .. && sed -i s/'^.'/''/ files.list
2084 status
2085 action "Creating \$CHECKSUM of files..."
2086 while read file; do
2087 [ -L "fs$file" ] && continue
2088 [ -f "fs$file" ] || continue
2089 case "$file" in
2090 /lib/modules/*/modules.*|*.pyc) continue;;
2091 esac
2092 $CHECKSUM "fs$file" | sed 's/ fs/ /'
2093 done < files.list > $CHECKSUM
2094 status
2095 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
2096 description.txt 2> /dev/null | awk \
2097 '{ sz=$1 } END { print sz }')
2098 # Build cpio archives.
2099 action "Compressing the fs..."
2100 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
2101 rm -rf fs
2102 status
2103 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
2104 $CHECKSUM description.txt 2> /dev/null | awk \
2105 '{ sz=$1 } END { print sz }')
2106 action "Updating receipt sizes..."
2107 sed -i s/^PACKED_SIZE.*$// receipt
2108 sed -i s/^UNPACKED_SIZE.*$// receipt
2109 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
2110 status
2111 action "Creating full cpio archive..."
2112 find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
2113 status
2114 action "Restoring original package tree..."
2115 unlzma -c fs.cpio.lzma | cpio -idm --quiet
2116 status
2117 rm fs.cpio.lzma && cd ..
2118 footer "$(eval_gettext 'Package $PACKAGE compressed successfully.')"
2119 pkg_size=$(du -sh $PACKAGE.tazpkg)
2120 eval_gettext "Size: \$pkg_size"; echo
2121 newline
2122 fi ;;
2123 recharge)
2124 # Recharge packages.list from a mirror.
2126 # WARNING: The mirrors file has all SliTaz mirrors but mirror
2127 # must have only the chosen main mirror.
2129 check_root $@
2131 ARG=$2
2132 if [ "$root" ]; then
2133 LOCALSTATE=$root$LOCALSTATE
2134 [ "${2#--}" != "$2" ] && ARG=$3
2135 fi
2136 if [ "$ARG" = main ]; then
2137 repository_to_recharge=$LOCALSTATE
2138 elif [ "$ARG" ]; then
2139 if [ -d "$LOCALSTATE/undigest/$ARG" ]; then
2140 repository_to_recharge=$LOCALSTATE/undigest/$ARG
2141 else
2142 repo="$LOCALSTATE/undigest/$ARG"
2143 eval_gettext "\$repo doesn't exist." >&2
2144 echo >&2
2145 exit 1
2146 fi
2147 else
2148 repository_to_recharge="$LOCALSTATE $LOCALSTATE/undigest/*"
2149 fi
2150 for path in $repository_to_recharge; do
2151 [ -f $path/mirror ] || continue
2152 cd $path
2154 # Quietly check if recharging is needed.
2155 [ -f ID ] && mv ID ID.bak
2156 download_from "$(cat mirror)" ID >/dev/null 2>/dev/null
2157 if [ -f ID ] && fgrep -q `cat ID.bak 2>/dev/null || echo "null"` ID; then
2158 if [ "$path" = "$LOCALSTATE" ]; then
2159 repository_name=Main
2160 else
2161 base_path="$(basename $path)"
2162 repository_name="$(eval_gettext 'Undigest $base_path')"
2163 fi
2164 eval_gettext "\$repository_name is up to date."; echo
2165 rm ID.bak
2166 continue
2167 fi
2169 # Don't let ID be a symlink when using local repository.
2170 if [ -f ID ]; then
2171 mv -f ID ID.bak
2172 cat ID.bak > ID
2173 rm ID.bak
2174 fi
2176 newline
2177 if [ "$path" != "$LOCALSTATE" ]; then
2178 base_path="$(basename $path)"
2179 eval_gettext "Recharging undigest \$base_path:"; echo
2180 fi
2182 if [ -f "packages.list" ]; then
2183 action "Creating backup of the last packages list..."
2184 for i in packages.desc packages.$SUM packages.txt \
2185 packages.list packages.equiv files.list.lzma \
2186 mirrors
2187 do
2188 mv -f $i $i.bak 2>/dev/null
2189 done
2190 status
2191 fi
2193 for i in desc md5 txt list equiv; do
2194 download_from "$(cat mirror)" packages.$i
2195 done
2196 download_from "$(cat mirror)" files.list.lzma
2197 download_from "$(sed 's|packages/.*||' < mirror)" mirrors
2199 if [ -f "packages.list.bak" ]; then
2200 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
2201 sed -i s/+// packages.diff
2202 title 'Mirrored packages diff'
2203 cat packages.diff
2204 new_pkgs=`cat packages.diff | wc -l`
2205 if [ "$new_pkgs" != 0 ]; then
2206 footer "$(eval_ngettext \
2207 '$new_pkgs new package on the mirror.' \
2208 '$new_pkgs new packages on the mirror.' $new_pkgs)"
2209 else
2210 gettext "No new packages on the mirror."; echo
2211 newline
2212 fi
2213 else
2214 footer "$(gettext \
2215 'Last packages.list is ready to use. Note that next time you recharge the
2216 list, a list of differences will be displayed to show new and upgradeable
2217 packages.')"
2218 fi
2219 done ;;
2220 help-up)
2221 # Options available for the command: up
2222 newline; usage_up; newline
2223 exit 1
2224 ;;
2225 up|upgrade)
2227 # This is the new way to upgrade packages making 'upgrade' and
2228 # upgradeable out-of-date. This new way is much, much more faster!
2229 # Look into installed packages and get data from receipt, it is fast
2230 # and easy to handle vars after using only md5sum to compare packages
2232 for opt in $@
2233 do
2234 case "$opt" in
2235 --recharge|-r)
2236 tazpkg recharge ;;
2237 --install|-i)
2238 install="y" ;;
2239 --check|-c)
2240 install="n" ;;
2241 esac
2242 done
2243 time=$(date +%s)
2244 installed_sum=$LOCALSTATE/installed.$SUM
2245 look_for_priority
2246 for repo in $priority; do
2247 pkg_list=$repo/packages.list
2248 mtime=`find $pkg_list -mtime +7`
2249 if [ "$mtime" ]; then
2250 if [ "$repo" = "$LOCALSTATE" ]; then
2251 repo_name=main
2252 else
2253 repo_name="${repo##*/}"
2254 fi
2255 eval_gettext "\$pkg_list is older than one week... recharging"; echo
2256 tazpkg recharge $repo_name
2257 fi
2258 done
2259 emsg "<n><b>$(gettext 'Package')</b><i 28> $(gettext 'Version')<i 48> $(gettext 'Status')<->"
2260 cd $INSTALLED
2261 newline > $UP_LIST
2262 blocked_count=0
2263 for pkg in *
2264 do
2265 unset VERSION EXTRAVERSION
2266 . $pkg/receipt
2267 md5=$(fgrep " $PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" \
2268 $installed_sum | awk '{print $1}')
2269 for repo in $priority; do
2270 pkg_desc=$repo/packages.desc
2271 pkg_list=$repo/packages.list
2272 pkg_sum=$repo/packages.$SUM
2274 if ! fgrep -q "$md5 $PACKAGE-" $pkg_sum; then
2275 # Jump to next repository in priority if pkg doesn't exists
2276 # in this one.
2277 grep -q ^$PACKAGE- $pkg_list || continue
2279 emsg -n "$PACKAGE<i 28> $VERSION"
2281 # Skip pkgs listed in $LOCALSTATE/blocked-packages.list
2282 if $(grep -qs "^$PACKAGE" $BLOCKED); then
2283 blocked_count=$(($blocked_count + 1))
2284 emsg "<i 48><c 31> $(gettext 'Blocked')</c>"
2285 break
2286 fi
2288 new=$(grep "^$PACKAGE |" $pkg_desc | awk '{print $3}')
2290 if [ "$VERSION" == "$new" ]; then
2291 emsg "<i 48><c 34> $(gettext 'New build')</c>"
2292 else
2293 emsg "<i 48><c 32> $(eval_gettext 'New version $new')</c>"
2294 fi
2295 echo "$PACKAGE" >> $UP_LIST
2296 break
2297 fi
2298 done
2299 done
2300 sed -i /^$/d $UP_LIST
2301 upnb=$(cat $UP_LIST | wc -l)
2302 pkgs=$(ls | wc -l)
2303 time=$(($(date +%s) - $time))
2304 if [ "$upnb" = 0 ]; then
2305 install="n"
2306 gettext "System is up-to-date..."; echo
2307 newline
2308 fi
2309 footer "$(eval_ngettext \
2310 '$pkgs installed package scanned in ${time}s' \
2311 '$pkgs installed packages scanned in ${time}s' $pkgs)"
2312 if [ "$upnb" != 0 ]; then
2313 if [ "$blocked_count" -gt 0 ]; then
2314 blocks="("$(eval_ngettext '$blocked_count blocked' \
2315 '$blocked_count blocked' $blocked_count)")"
2316 fi
2317 boldify "$(eval_ngettext \
2318 'You have $upnb available upgrade $blocks' \
2319 'You have $upnb available upgrades $blocks' $upnb)"
2320 newline
2321 fi
2322 # Pkgs to upgrade ? Skip, let install them all or ask user
2323 [ "$install" == "n" ] && exit 0
2324 if [ "$upnb" -gt 0 ]; then
2325 if [ "$install" == "y" ]; then
2326 continue
2327 else
2328 gettext "Do you wish to install them now: y/n ? "
2329 read install
2330 fi
2331 case "$install" in
2332 y|Y|yes|YES|Yes)
2333 for pkg in $(cat $UP_LIST)
2334 do
2335 echo 'y' | tazpkg get-install $pkg --forced
2336 done
2337 # List is generated each time and must be cleaned so
2338 # tazpkg-notify dont find upgrade anymore.
2339 rm $UP_LIST && touch $UP_LIST ;;
2340 *)
2341 gettext "Leaving without any upgrades installed."; echo
2342 newline
2343 exit 0 ;;
2344 esac
2345 fi
2346 newline ;;
2347 bugs)
2348 # Show known bugs in package(s)
2349 cd $INSTALLED
2350 shift
2351 LIST=$@
2352 [ -n "$LIST" ] || LIST=`ls`
2353 MSG=$(gettext "No known bugs.")
2354 for PACKAGE in $LIST; do
2355 BUGS=""
2356 EXTRAVERSION=""
2357 . $PACKAGE/receipt
2358 if [ -n "$BUGS" ]; then
2359 MSG=$(gettext "Bug list completed")
2360 newline
2361 eval_gettext "Bugs in package \$PACKAGE version \$VERSION\$EXTRAVERSION:"; echo
2362 cat <<EOT
2363 $BUGS
2364 EOT
2365 fi
2366 done
2367 echo "$MSG" ;;
2368 check)
2369 # Check installed packages set.
2370 check_root $@
2372 # Get repositories priority list.
2373 look_for_priority
2375 cd $INSTALLED
2376 for PACKAGE in `ls`; do
2377 if [ ! -f $PACKAGE/receipt ]; then
2378 eval_gettext "The package \$PACKAGE installation has not completed"; echo
2379 continue
2380 fi
2381 DEPENDS=""
2382 EXTRAVERSION=""
2383 . $PACKAGE/receipt
2384 if [ -s $PACKAGE/modifiers ]; then
2385 eval_gettext \
2386 "The package \$PACKAGE-\$VERSION\$EXTRAVERSION has been modified by:"; echo
2387 for i in $(cat $PACKAGE/modifiers); do
2388 echo " $i"
2389 done
2390 fi
2391 MSG="$(eval_gettext 'Files lost from $PACKAGE-$VERSION$EXTRAVERSION:')\n"
2392 while read file; do
2393 [ -e "$file" ] && continue
2394 if [ -L "$file" ]; then
2395 MSG="$MSG $(gettext 'target of symlink')"
2396 fi
2397 echo -e "$MSG $file"
2398 MSG=""
2399 done < $PACKAGE/files.list
2400 MSG="$(eval_gettext 'Missing dependencies for $PACKAGE-$VERSION$EXTRAVERSION:')\n"
2401 for i in $DEPENDS; do
2402 [ -d $i ] && continue
2403 [ -d $(equivalent_pkg $i) ] && continue
2404 echo -e "$MSG $i"
2405 MSG=""
2406 done
2407 MSG="$(eval_gettext 'Dependencies loop between $PACKAGE and:')\n"
2408 ALL_DEPS=""
2409 check_for_deps_loop $PACKAGE $DEPENDS
2410 done
2411 gettext "Looking for known bugs..."; echo
2412 tazpkg bugs
2413 if [ "$PACKAGE_FILE" = "--full" ]; then
2414 for file in */$CHECKSUM; do
2415 CONFIG_FILES=""
2416 . $(dirname "$file")/receipt
2417 [ -s "$file" ] || continue
2418 while read md5 f; do
2419 [ -f $f ] || continue
2420 for i in $CONFIG_FILES; do
2421 case "$f" in
2422 $i|$i/*) continue 2;;
2423 esac
2424 done
2425 echo "$md5 $f"
2426 done < "$file" | $CHECKSUM -c - 2> /dev/null | \
2427 grep -v OK$ | sed 's/FAILED$/$CHECKSUM MISMATCH/'
2428 done
2429 FILES=" "
2430 for file in $(cat */files.list); do
2431 [ -d "$file" ] && continue
2432 case "$FILES" in *\ $file\ *) continue;; esac
2433 [ $(grep "^$(echo $file | grepesc)$" */files.list 2> /dev/null | \
2434 wc -l) -gt 1 ] || continue
2435 FILES="$FILES$file "
2436 eval_gettext "The following packages provide \$file:"; echo
2437 grep -l "^$(echo $file | grepesc)$" */files.list | while read f
2438 do
2439 pkg=${f%/files.list}
2440 if [ -f $pkg/modifiers ]; then
2441 overriders="$(cat $pkg/modifiers)"
2442 eval_gettext ' $pkg (overridden by $overriders)'
2443 else
2444 echo -n " $pkg"
2445 fi
2446 newline
2447 done
2448 done
2449 MSG="$(gettext 'No package has installed the following files:')\n"
2450 find /etc /bin /sbin /lib /usr /var/www \
2451 -not -type d 2> /dev/null | while read file; do
2452 case "$file" in *\[*) continue;; esac
2453 grep -q "^$(echo $file | grepesc)$" */files.list && continue
2454 echo -e "$MSG $file"
2455 MSG=""
2456 done
2457 fi
2458 gettext "Check completed."; echo ;;
2459 block)
2460 # Add a pkg name to the list of blocked packages.
2461 check_root $@
2462 check_for_package_on_cmdline
2463 newline
2464 if grep -qs "^$PACKAGE" $BLOCKED; then
2465 eval_gettext "\$PACKAGE is already in the blocked packages list."; echo
2466 newline
2467 exit 0
2468 else
2469 action "Add \$PACKAGE to: \$BLOCKED..."
2470 echo $PACKAGE >> $BLOCKED
2471 status
2472 # Log this activity
2473 . $INSTALLED/$PACKAGE/receipt
2474 log_pkg Blocked
2475 fi
2476 newline ;;
2477 unblock)
2478 # Remove a pkg name from the list of blocked packages.
2479 check_root $@
2480 check_for_package_on_cmdline
2481 newline
2482 if grep -qs "^$PACKAGE" $BLOCKED; then
2483 action "Removing \$PACKAGE from: \$BLOCKED..."
2484 sed -i s/$PACKAGE/''/ $BLOCKED
2485 sed -i '/^$/d' $BLOCKED
2486 status
2487 # Log this activity
2488 . $INSTALLED/$PACKAGE/receipt
2489 log_pkg Unblocked
2490 else
2491 eval_gettext "\$PACKAGE is not in the blocked packages list."; echo
2492 newline
2493 exit 0
2494 fi
2495 newline ;;
2496 get)
2497 # Download a package with wget.
2498 check_root $@
2499 check_for_package_on_cmdline
2500 check_for_packages_list
2502 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2503 if [ "$rootconfig" ]; then
2504 if [ "$root" ]; then
2505 CACHE_DIR=$root/$CACHE_DIR
2506 SAVE_CACHE_DIR=$CACHE_DIR
2507 LOCALSTATE=$root/$LOCALSTATE
2508 else
2509 gettext "rootconfig needs --root= option used." >&2
2510 echo >&2
2511 exit 1
2512 fi
2513 fi
2515 # Get repositories priority list.
2516 look_for_priority
2518 CURRENT_DIR=$PWD
2519 check_for_package_in_list
2520 cd $CACHE_DIR
2521 if [ -f "$PACKAGE.tazpkg" ]; then
2522 eval_gettext "\$PACKAGE already in the cache: \$CACHE_DIR"; echo
2523 # Check package download was finished
2524 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2525 eval_gettext "Continuing \$PACKAGE download"; echo
2526 download $PACKAGE.tazpkg
2528 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2529 rm -f $PACKAGE.tazpkg
2530 download $PACKAGE.tazpkg
2531 fi
2532 else
2533 download $PACKAGE.tazpkg
2534 fi
2535 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2536 cp -a $PACKAGE_FILE $CURRENT_DIR
2537 ;;
2538 get-install|-gi)
2539 # Download and install a package.
2540 check_root $@
2541 check_for_package_on_cmdline
2542 check_for_packages_list
2544 DO_CHECK=""
2545 [ "$forced" ] && DO_CHECK=no
2546 [ "$root" ] && ROOT="$root" && check_base_dir "$root"
2547 [ "$list" ] && INSTALL_LIST="$list"
2548 if [ "$rootconfig" ]; then
2549 if [ "$root" ]; then
2550 CACHE_DIR=$root/$CACHE_DIR
2551 SAVE_CACHE_DIR=$CACHE_DIR
2552 LOCALSTATE=$root/$LOCALSTATE
2553 else
2554 gettext "rootconfig needs --root= option used." >&2
2555 echo >&2
2556 exit 1
2557 fi
2558 fi
2560 # Get repositories priority list.
2561 look_for_priority
2563 AUTOEXEC="no"
2564 if ! check_for_package_in_list check; then
2565 PACKAGE=get-$PACKAGE
2566 AUTOEXEC=$PACKAGE
2567 check_for_package_in_list
2568 if [ -n "$(get_installed_package_pathname $PACKAGE $ROOT)" ]; then
2569 CACHE_DIR="${CACHE_DIR%/*}/get"
2570 [ -d "$CACHE_DIR" ] || mkdir -p $CACHE_DIR
2571 $AUTOEXEC $ROOT
2572 exit 0
2573 fi
2574 fi
2575 # Check if forced install.
2576 if ! [ "$forced" ]; then
2577 check_for_installed_package $ROOT
2578 fi
2579 cd $CACHE_DIR
2580 if [ -f "$PACKAGE.tazpkg" ]; then
2581 eval_gettext "\$PACKAGE already in the cache: \$CACHE_DIR"; echo
2582 # Check package download was finished
2583 tail -c 2k $PACKAGE.tazpkg | fgrep -q 00000000TRAILER || {
2584 eval_gettext "Continuing \$PACKAGE download"; echo
2585 download $PACKAGE.tazpkg
2587 if [ "$($CHECKSUM $PACKAGE.tazpkg)" != "$(fgrep " $PACKAGE.tazpkg" $rep/packages.$SUM)" ]; then
2588 rm -f $PACKAGE.tazpkg
2589 download $PACKAGE.tazpkg
2590 fi
2591 else
2592 newline
2593 download $PACKAGE.tazpkg
2594 fi
2595 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
2596 [ "$rootconfig" ] && LOCALSTATE=${LOCALSTATE#$root}
2597 install_package $ROOT
2598 [ "$AUTOEXEC" != "no" ] && $PACKAGE $ROOT
2599 update_desktop_database $ROOT
2600 update_mime_database $ROOT ;;
2601 clean-cache|-cc)
2602 # Remove all downloaded packages.
2603 check_root $@
2604 files=$(find $CACHE_DIR -name *.tazpkg | wc -l)
2605 title 'Clean cache: $CACHE_DIR'
2606 action "Cleaning cache directory..."
2607 rm -rf $CACHE_DIR/*
2608 status
2609 footer "$(eval_ngettext \
2610 '$files file removed from cache.' \
2611 '$files files removed from cache.' $files)"
2612 ;;
2613 list-undigest)
2614 # list undigest URLs.
2615 if [ "$2" = "--box" ]; then
2616 for i in $LOCALSTATE/undigest/*/mirror; do
2617 [ -f $i ] || continue
2618 echo "$(basename $(dirname $i))|$(cat $i)"
2619 done
2620 else
2621 title 'Current undigest(s)'
2622 for i in $LOCALSTATE/undigest/*/mirror; do
2623 if [ ! -f $i ]; then
2624 gettext "No undigest mirror found."; echo
2625 exit 1
2626 fi
2627 echo "$(basename $(dirname $i)) $(cat $i)"
2628 done
2629 newline
2630 fi ;;
2631 remove-undigest)
2632 # remove undigest URL.
2633 check_root $@
2634 undigest="$2"
2635 if [ -d $LOCALSTATE/undigest/$2 ]; then
2636 eval_gettext "Remove \$undigest undigest" && confirm
2637 if [ $? = 0 ]; then
2638 action "Removing \$undigest undigest..."
2639 rm -rf $LOCALSTATE/undigest/$2
2640 status
2641 rmdir $LOCALSTATE/undigest 2> /dev/null
2642 fi
2643 else
2644 eval_gettext "Undigest \$undigest not found"; echo
2645 fi ;;
2646 add-undigest|setup-undigest)
2647 # Add undigest URL.
2648 check_root $@
2649 undigest=$2
2650 [ -d $LOCALSTATE/undigest ] || mkdir $LOCALSTATE/undigest
2651 if [ -z "$undigest" ]; then
2652 i=1
2653 while [ -d $LOCALSTATE/undigest/$i ]; do
2654 i=$(($i+1))
2655 done
2656 undigest=$i
2657 fi
2658 if [ ! -d $LOCALSTATE/undigest/$undigest ]; then
2659 eval_gettext "Creating new undigest \$undigest."; echo
2660 mkdir $LOCALSTATE/undigest/$undigest
2661 fi
2662 setup_mirror $LOCALSTATE/undigest/$undigest $3 ;;
2663 setup-mirror|-sm)
2664 # Change mirror URL.
2665 check_root $@
2666 setup_mirror $LOCALSTATE $2 ;;
2667 reconfigure)
2668 # Replay post_install from receipt
2669 check_for_package_on_cmdline
2670 check_root $@
2671 ROOT=""
2672 while [ -n "$3" ]; do
2673 case "$3" in
2674 --root=*)
2675 ROOT="${3#--root=}/" ;;
2676 *) shift 2
2677 u_opt="$*"
2678 echo -e "\n$(gettext 'Unknown option $u_opt.')\n" >&2
2679 exit 1 ;;
2680 esac
2681 shift
2682 done
2683 if [ -d "$ROOT$INSTALLED/$PACKAGE" ]; then
2684 check_for_receipt $ROOT
2685 # Check for post_install
2686 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
2687 . $ROOT$INSTALLED/$PACKAGE/receipt
2688 post_install $ROOT
2689 # Log this activity
2690 [ -n "$ROOT" ] || log_pkg Reconfigured
2691 else
2692 newline
2693 eval_gettext "Nothing to do for \$PACKAGE."; echo
2694 fi
2695 else
2696 newline
2697 eval_gettext "Package \$PACKAGE is not installed."; echo
2698 gettext "Install package with 'tazpkg install' or 'tazpkg get-install'"; echo
2699 newline
2700 fi ;;
2701 shell)
2702 # Tazpkg SHell
2703 if test $(id -u) = 0 ; then
2704 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
2705 else
2706 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
2707 fi
2708 if [ ! "$2" = "--noheader" ]; then
2709 clear
2710 title 'Tazpkg SHell.'
2711 gettext "Type 'usage' to list all available commands or 'quit' or 'q' to exit."; echo
2712 newline
2713 fi
2714 while true
2715 do
2716 echo -en "$PROMPT"; read cmd
2717 case $cmd in
2718 q|quit)
2719 break ;;
2720 shell)
2721 gettext "You are already running a Tazpkg SHell."; echo ;;
2722 su)
2723 su -c 'exec tazpkg shell --noheader' && break ;;
2724 "")
2725 continue ;;
2726 *)
2727 tazpkg $cmd ;;
2728 esac
2729 done ;;
2730 depends)
2731 # Display dependencies tree
2732 cd $INSTALLED
2733 ALL_DEPS=""
2734 if [ -f $2/receipt ]; then
2735 dep_scan $2 ""
2736 fi ;;
2737 rdepends)
2738 # Display reverse dependencies tree
2739 cd $INSTALLED
2740 ALL_DEPS=""
2741 if [ -f $2/receipt ]; then
2742 rdep_scan $2
2743 fi ;;
2744 convert|-c)
2745 # convert misc package format to .tazpkg
2746 check_for_package_file
2747 [ -n "$TARGET_DIR" -a -s "$TARGET_DIR/files.list.lzma" ] &&
2748 TMPLOCALSTATE="$TARGET_DIR"
2749 if [ "$(dd if=$PACKAGE_FILE bs=8 count=1 skip=1 2> /dev/null)" \
2750 == "debian-b" ]; then
2751 convert_deb
2752 else
2753 case "$PACKAGE_FILE" in
2754 *.deb|*.udeb)
2755 convert_deb;;
2756 *.rpm)
2757 convert_rpm;;
2758 *.tgz)
2759 convert_tgz;;
2760 *.apk|*.pkg.tar.gz)
2761 convert_arch;;
2762 *.ipk|*.opk)
2763 convert_ipk;;
2764 *)
2765 gettext "Unsupported format"; echo ;;
2766 esac
2767 fi ;;
2768 link)
2769 # link a package from another slitaz installation
2770 PACKAGE=$2
2771 if [ ! -d "$TARGET_DIR" -o \
2772 ! -d "$TARGET_DIR$INSTALLED/$PACKAGE" ]; then
2773 gettext "
2774 usage: tazpkg link package_name slitaz_root
2775 example: 'tazpkg link openoffice /mnt' will use less than 100k in
2776 your running system ram.
2778 exit 1
2779 fi
2780 if [ -e "$INSTALLED/$PACKAGE" ]; then
2781 eval_gettext "\$PACKAGE is already installed."; echo
2782 exit 1
2783 fi
2784 ln -s $TARGET_DIR$INSTALLED/$PACKAGE $INSTALLED
2785 DEPENDS="$(. $INSTALLED/$PACKAGE/receipt ; echo $DEPENDS)"
2786 MISSING=""
2787 for i in $DEPENDS; do
2788 [ -e $INSTALLED/$i ] && continue
2789 MISSING="$MISSING$i "
2790 eval_gettext "Missing: \$i"; echo
2791 done
2792 if [ -n "$MISSING" ]; then
2793 newline
2794 gettext "Link all missing dependencies" && confirm
2795 answer=$?
2796 newline
2797 if [ $answer = 0 ]; then
2798 for i in $MISSING; do
2799 tazpkg link $i $TARGET_DIR
2800 done
2801 else
2802 newline
2803 eval_gettext "Leaving dependencies unresolved for: \$PACKAGE"; echo
2804 gettext "The package is installed but probably will not work."; echo
2805 newline
2806 fi
2807 fi
2808 . $INSTALLED/$PACKAGE/receipt
2809 if grep -q ^pre_install $INSTALLED/$PACKAGE/receipt; then
2810 pre_install
2811 fi
2812 while read path; do
2813 [ -e $path ] && continue
2814 while true; do
2815 dir=$(dirname $path)
2816 [ -e $dir ] && break
2817 path=$dir
2818 done
2819 ln -s $TARGET_DIR$path $dir
2820 done < $INSTALLED/$PACKAGE/files.list
2821 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
2822 post_install
2823 fi ;;
2824 usage|*)
2825 # Print a short help or give usage for an unknown or empty command.
2826 usage ;;
2827 esac
2829 exit 0