tazpkg view tazpkg @ rev 658

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