tazpkg view tazpkg @ rev 648

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