tazpkg view tazpkg @ rev 487

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