tazpkg view tazpkg @ rev 622

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