tazpkg view tazpkg @ rev 633

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