tazpkg view tazpkg @ rev 620

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