tazpkg view tazpkg @ rev 164

Add packages.equiv support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Oct 15 20:09:15 2008 +0000 (2008-10-15)
parents 105f46f3f623
children 9efce80882a7
line source
1 #!/bin/sh
2 # Tazpkg - Tiny autonomus zone packages manager.
3 #
4 # This is a lightwight packages manager for *.tazpkg files, all 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.
9 #
10 # (C) 2007-2008 SliTaz - GNU General Public License v3.
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 # Pascal Bellard <pascal.bellard@slitaz.org>
14 # Eric Joseph-Alexandre <erjo@slitaz.org>
15 #
16 VERSION=2.3
18 ####################
19 # Script variables #
20 ####################
22 # Packages categories.
23 CATEGORIES="
24 base-system
25 x-window
26 utilities
27 network
28 graphics
29 multimedia
30 office
31 development
32 system-tools
33 security
34 games
35 misc
36 meta
37 non-free"
39 # Initialize some variables to use words
40 # rather than numbers for functions and actions.
41 COMMAND=$1
42 if [ -f "$2" ]; then
43 # Set pkg basename for install, extract
44 PACKAGE=$(basename ${2%.tazpkg} 2>/dev/null)
45 else
46 # Pkg name for remove, search and all other cmds
47 PACKAGE=${2%.tazpkg}
48 fi
49 PACKAGE_FILE=$2
50 TARGET_DIR=$3
51 TOP_DIR=`pwd`
52 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
54 # Path to tazpkg used dir and configuration files
55 LOCALSTATE=/var/lib/tazpkg
56 INSTALLED=$LOCALSTATE/installed
57 CACHE_DIR=/var/cache/tazpkg
58 MIRROR=$LOCALSTATE/mirror
59 PACKAGES_LIST=$LOCALSTATE/packages.list
60 BLOCKED=$LOCALSTATE/blocked-packages.list
61 DEFAULT_MIRROR="http://mirror.slitaz.org/packages/`cat /etc/slitaz-release`/"
62 INSTALL_LIST=""
64 # Bold red warning for upgrade.
65 WARNING="\\033[1;31mWARNING\\033[0;39m"
67 # Check if the directories and files used by Tazpkg
68 # exist. If not and user is root we create them.
69 if test $(id -u) = 0 ; then
70 if [ ! -d "$CACHE_DIR" ]; then
71 mkdir -p $CACHE_DIR
72 fi
73 if [ ! -d "$INSTALLED" ]; then
74 mkdir -p $INSTALLED
75 fi
76 if [ ! -f "$LOCALSTATE/mirror" ]; then
77 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
78 fi
79 fi
81 ####################
82 # Script functions #
83 ####################
85 # Print the usage.
86 usage ()
87 {
88 echo -e "SliTaz package manager - Version: $VERSION\n
89 \033[1mUsage:\033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
90 tazpkg shell\n
91 \033[1mCommands: \033[0m
92 usage Print this short usage.
93 bugs Show known bugs in packages
94 list List installed packages on the system by category or all.
95 xhtml-list Create a xHTML list of installed packges.
96 list-mirror List all available packages on the mirror (--diff for new).
97 info Print information about a package.
98 desc Print description of a package (if it exists).
99 list-files List the files installed with a package.
100 list-config List the configuration files.
101 search Search for a package by pattern or name (options: -i|-l|-m).
102 search-file Search for file(s) in all installed packages files.
103 install Install a local (*.tazpkg) package (--forced to force).
104 install-list Install all packages from a list of packages.
105 remove Remove the specified package and all installed files.
106 extract Extract a (*.tazpkg) package into a directory.
107 pack Pack an unpacked or prepared package tree.
108 recharge Recharge your packages.list from the mirror.
109 repack Create a package archive from an installed package.
110 repack-config Create a package archive with configuration files.
111 upgrade Upgrade all installed and listed packages on the mirror.
112 block|unblock Block an installed package version or unblock it for upgrade.
113 get Download a package into the current directory.
114 get-install Download and install a package from the mirror.
115 get-install-list Download and install a list of packages from the mirror.
116 check Verify consistency of installed packages.
117 add-flavor Install the flavor list of packages.
118 install-flavor Install the flavor list of packages and remove other ones.
119 set-release Change release and update packages
120 clean-cache Clean all packages downloaded in cache directory.
121 setup-mirror Change the mirror url configuration.
122 reconfigure Replay post install script from package."
123 }
125 # Status function with color (supported by Ash).
126 status()
127 {
128 local CHECK=$?
129 echo -en "\\033[70G[ "
130 if [ $CHECK = 0 ]; then
131 echo -en "\\033[1;33mOK"
132 else
133 echo -en "\\033[1;31mFailed"
134 fi
135 echo -e "\\033[0;39m ]"
136 return $CHECK
137 }
139 # Check if user is root to install, or remove packages.
140 check_root()
141 {
142 if test $(id -u) != 0 ; then
143 echo -e "\nYou must be root to run `basename $0` with this option."
144 echo -e "Please use 'su' and root password to become super-user.\n"
145 exit 0
146 fi
147 }
149 # Check for a package name on cmdline.
150 check_for_package_on_cmdline()
151 {
152 if [ -z "$PACKAGE" ]; then
153 echo -e "\nPlease specify a package name on the command line.\n"
154 exit 0
155 fi
156 }
158 # Check if the package (*.tazpkg) exist before installing or extracting.
159 check_for_package_file()
160 {
161 if [ ! -f "$PACKAGE_FILE" ]; then
162 echo -e "
163 Unable to find : $PACKAGE_FILE\n"
164 exit 0
165 fi
166 }
168 # Check for the receipt of an installed package.
169 check_for_receipt()
170 {
171 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
172 echo -e "\nUnable to find the receipt : $INSTALLED/$PACKAGE/receipt\n"
173 exit 0
174 fi
175 }
177 # Get package name in a directory
178 package_fullname_in_dir()
179 {
180 [ -f $2$1/receipt ] || return
181 EXTRAVERSION=""
182 . $2$1/receipt
183 echo $PACKAGE-$VERSION$EXTRAVERSION
184 }
186 # Get package name that is already installed.
187 get_installed_package_pathname()
188 {
189 for i in $2$INSTALLED/${1%%-*}*; do
190 [ -d $i ] || continue
191 if [ "$1" = "$(package_fullname_in_dir $i $2)" ]; then
192 echo $i
193 return
194 fi
195 done
196 }
198 # Check if a package is already installed.
199 check_for_installed_package()
200 {
201 if [ -n "$(get_installed_package_pathname $PACKAGE $1)" ]; then
202 echo -e "
203 $PACKAGE is already installed. You can use the --forced option to force
204 installation or remove it and reinstall.\n"
205 exit 0
206 fi
207 }
209 # Check for packages.list to download and install packages.
210 check_for_packages_list()
211 {
212 if [ ! -f "$LOCALSTATE/packages.list" ]; then
213 if test $(id -u) = 0 ; then
214 tazpkg recharge
215 else
216 echo -e "
217 Unable to find the list : $LOCALSTATE/packages.list\n
218 You should probably run 'tazpkg recharge' as root to get the latest list of
219 packages available on the mirror.\n"
220 exit 0
221 fi
222 fi
223 }
225 # Check for a package in packages.list. Used by get and get-install to grep
226 # package basename.
227 check_for_package_in_list()
228 {
229 local pkg
230 pkg=$(grep "^$PACKAGE-[0-9]" $LOCALSTATE/packages.list | head -1)
231 [ -n "$pkg" ] || pkg=$(grep "^$PACKAGE-.[\.0-9]" $LOCALSTATE/packages.list | head -1)
232 if [ -n "$pkg" ]; then
233 PACKAGE=$pkg
234 else
235 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
236 exit 0
237 fi
238 }
240 # Download a file trying all mirrors
241 download()
242 {
243 for i in $(cat $MIRROR); do
244 wget -c $i$@ && break
245 done
246 }
248 # Extract a package with cpio and gzip.
249 extract_package()
250 {
251 echo -n "Extracting $PACKAGE... "
252 cpio -id < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
253 gzip -d fs.cpio.gz
254 echo -n "Extracting the pseudo fs... "
255 cpio -id < fs.cpio && rm fs.cpio
256 }
258 # This function installs a package in the rootfs.
259 install_package()
260 {
261 ROOT=$1
262 if [ -n "$ROOT" ]; then
263 # Get absolute path
264 ROOT=$(cd $ROOT; pwd)
265 fi
266 (
267 # Create package path early to avoid dependencies loop
268 mkdir -p $TMP_DIR
269 ( cd $TMP_DIR ; cpio -i receipt > /dev/null) < $PACKAGE_FILE
270 . $TMP_DIR/receipt
271 rm -rf $TMP_DIR
272 # Make the installed package data dir to store
273 # the receipt and the files list.
274 mkdir -p $ROOT$INSTALLED/$PACKAGE
275 )
276 # Resolve package deps.
277 check_for_deps $ROOT
278 if [ ! "$MISSING_PACKAGE" = "" ]; then
279 install_deps $ROOT
280 fi
281 mkdir -p $TMP_DIR
282 [ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> $INSTALL_LIST-processed
283 echo ""
284 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
285 echo "================================================================================"
286 echo -n "Copying $PACKAGE... "
287 cp $PACKAGE_FILE $TMP_DIR
288 status
289 cd $TMP_DIR
290 extract_package
291 SELF_INSTALL=0
292 EXTRAVERSION=""
293 CONFIG_FILES=""
294 # Include temporary receipt to get the right variables.
295 . $PWD/receipt
296 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
297 echo -n "Checking post install dependencies... "
298 [ -f $INSTALLED/$PACKAGE/receipt ]
299 if ! status; then
300 echo "Please run 'tazpkg install $PACKAGE_FILE' in / and retry."
301 cd .. && rm -rf $TMP_DIR
302 exit 1
303 fi
304 fi
305 # Remember modified packages
306 for i in $(grep -v '\[' files.list); do
307 [ -e "$ROOT$i" ] || continue
308 [ -d "$ROOT$i" ] && continue
309 for j in $(grep -l "^$i$" $ROOT$INSTALLED/*/files.list); do
310 [ "$j" = "$ROOT$INSTALLED/$PACKAGE/files.list" ] && continue
311 grep -qs ^$PACKAGE$ $(dirname $j)/modifiers && continue
312 if [ -s "$(dirname $j)/volatile.cpio.gz" ]; then
313 # We can modify backed up files
314 zcat $(dirname $j)/volatile.cpio.gz | \
315 cpio -t 2> /dev/null | \
316 grep -q "^${i#/}$" && continue
317 fi
318 echo "$PACKAGE" >> $(dirname $j)/modifiers
319 done
320 done
321 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
322 # Copy the description if found.
323 if [ -f "description.txt" ]; then
324 cp description.txt $ROOT$INSTALLED/$PACKAGE
325 fi
326 # Copy the md5sum if found.
327 if [ -f "md5sum" ]; then
328 cp md5sum $ROOT$INSTALLED/$PACKAGE
329 fi
330 # Pre install commands.
331 if grep -q ^pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
332 pre_install $ROOT
333 fi
334 if [ -n "$CONFIG_FILES" ]; then
335 # save 'official' configuration files
336 echo -n "Save configuration files for $PACKAGE... "
337 for i in $CONFIG_FILES; do
338 ( cd fs ; find ${i#/} -type f )
339 done | ( cd fs ; cpio -o -H newc | gzip -9 ) > \
340 $ROOT$INSTALLED/$PACKAGE/volatile.cpio.gz
341 # keep user configuration files
342 for i in $CONFIG_FILES; do
343 ( cd fs ; find ${i#/} -type f )
344 done | while read i; do
345 [ -e $ROOT/$i ] || continue
346 cp -a $ROOT/$i fs/$i
347 done
348 status
349 fi
350 echo -n "Installing $PACKAGE... "
351 cp -a fs/* $ROOT/
352 status
353 # Remove the temporary random directory.
354 echo -n "Removing all tmp files... "
355 cd .. && rm -rf $TMP_DIR
356 status
357 # Post install commands.
358 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
359 post_install $ROOT
360 fi
361 cd $TOP_DIR
362 echo "================================================================================"
363 echo "$PACKAGE ($VERSION$EXTRAVERSION) is installed."
364 echo ""
365 }
367 # Check for loop in deps tree.
368 check_for_deps_loop()
369 {
370 local list
371 local pkg
372 local deps
373 pkg=$1
374 shift
375 [ -n "$1" ] || return
376 list=""
377 # Filter out already processed deps
378 for i in $@; do
379 case " $ALL_DEPS" in
380 *\ $i\ *);;
381 *) list="$list $i";;
382 esac
383 done
384 ALL_DEPS="$ALL_DEPS$list "
385 for i in $list; do
386 [ -f $i/receipt ] || continue
387 deps="$(DEPENDS=""; . $i/receipt; echo $DEPENDS)"
388 case " $deps " in
389 *\ $pkg\ *) echo -e "$MSG $i"; MSG="";;
390 *) check_for_deps_loop $pkg $deps;;
391 esac
392 done
393 }
395 # get package from packages.equiv
396 equivalent_pkg()
397 {
398 for i in $(grep -s "^$1=" $2$LOCALSTATE/packages.equiv | sed "s/^$1=//"); do
399 if echo $i | grep -q : ; then
400 # format 'alternative:newname'
401 # if alternative is installed then substitute newname
402 if [ -f $2$INSTALLED/${i%:*}/receipt ]; then
403 # substitute package dependancy
404 echo ${i#*:}
405 return
406 fi
407 else
408 # if alternative is installed then nothing to install
409 if [ -f $2$INSTALLED/$i/receipt ]; then
410 # substitute installed package
411 echo $i
412 return
413 fi
414 fi
415 done
416 # if not found in packages.equiv then no substitution
417 echo $1
418 }
420 # Check for missing deps listed in a receipt packages.
421 check_for_deps()
422 {
423 local saved;
424 saved=$PACKAGE
425 mkdir -p $TMP_DIR
426 ( cd $TMP_DIR ; cpio -i receipt > /dev/null ) < $PACKAGE_FILE
427 . $TMP_DIR/receipt
428 PACKAGE=$saved
429 rm -rf $TMP_DIR
430 for pkgorg in $DEPENDS
431 do
432 i=$(equivalent_pkg $pkgorg $1)
433 if [ ! -d "$1$INSTALLED/$i" ]; then
434 MISSING_PACKAGE=$i
435 deps=$(($deps+1))
436 elif [ ! -f "$1$INSTALLED/$i/receipt" ]; then
437 echo -e "$WARNING Dependency loop between $PACKAGE and $i."
438 fi
439 done
440 if [ ! "$MISSING_PACKAGE" = "" ]; then
441 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
442 echo "================================================================================"
443 for pkgorg in $DEPENDS
444 do
445 i=$(equivalent_pkg $pkgorg $1)
446 if [ ! -d "$1$INSTALLED/$i" ]; then
447 MISSING_PACKAGE=$i
448 echo "Missing : $MISSING_PACKAGE"
449 fi
450 done
451 echo "================================================================================"
452 echo "$deps missing package(s) to install."
453 fi
454 }
456 # Install all missing deps. First ask user then install all missing deps
457 # from local dir, cdrom, media or from the mirror. In case we want to
458 # install packages from local, we need a packages.list to find the version.
459 install_deps()
460 {
461 local root
462 root=""
463 [ -n "$1" ] && root="--root=$1"
464 echo ""
465 echo -n "Install all missing dependencies (y/N) ? "; read anser
466 echo ""
467 if [ "$anser" = "y" ]; then
468 for pkgorg in $DEPENDS
469 do
470 pkg=$(equivalent_pkg $pkgorg $1)
471 if [ ! -d "$1$INSTALLED/$pkg" ]; then
472 local list
473 list="$INSTALL_LIST"
474 [ -n "$list" ] || list="$TOP_DIR/packages.list"
475 # We can install packages from a local dir by greping
476 # the TAZPKG_BASENAME in the local packages.list.
477 found=0
478 if [ -f "$list" ]; then
479 echo "Checking if $pkg exist in local list... "
480 mkdir $TMP_DIR
481 for i in $pkg-*.tazpkg; do
482 [ -f $i ] || continue
483 ( cd $TMP_DIR ; cpio -i receipt > /dev/null) < $i
484 [ "$(. $TMP_DIR/receipt; echo $PACKAGE)" = "$pkg" ] || continue
485 if grep -q ^$(package_fullname_in_dir $TMP_DIR).tazpkg$ $list
486 then
487 found=1
488 tazpkg install $i $root --list=$list
489 break
490 fi
491 done
492 rm -rf $TMP_DIR
493 fi
494 # Install deps from the mirror.
495 if [ $found -eq 0 ]; then
496 if [ ! -f "$LOCALSTATE/packages.list" ]; then
497 tazpkg recharge
498 fi
499 tazpkg get-install $pkg $root
500 fi
501 fi
502 done
503 else
504 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
505 echo -e "The package is installed but will probably not work.\n"
506 fi
507 }
509 # xHTML packages list header.
510 xhtml_header()
511 {
512 cat > $XHTML_LIST << _EOT_
513 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
514 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
515 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
516 <head>
517 <title>Installed packages list</title>
518 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
519 <meta name="modified" content="$DATE" />
520 <meta name="generator" content="Tazpkg" />
521 <style type="text/css"><!--
522 body { font: 12px sans-serif, vernada, arial; margin: 0; }
523 #header { background: #f0ba08; color: black; height: 50px;
524 border-top: 1px solid black; border-bottom: 1px solid black; }
525 #content { margin: 0px 50px 26px 50px; }
526 #footer { border-top: 1px solid black; padding-top: 10px;}
527 h1 { margin: 14px 0px 0px 16px; }
528 pre { padding-left: 5px; }
529 hr { color: white; background: white; height: 1px; border: 0; }
530 --></style>
531 </head>
532 <body bgcolor="#ffffff">
533 <div id="header">
534 <h1><font color="#3e1220">Installed packages list</font></h1>
535 </div>
536 <hr />
537 <!-- Start content -->
538 <div id="content">
540 <p>
541 _packages_ packages installed - List generated on : $DATE
542 <p>
544 _EOT_
545 }
547 # xHTML content with packages info.
548 xhtml_pkg_info()
549 {
550 cat >> $XHTML_LIST << _EOT_
551 <h3>$PACKAGE</h3>
552 <pre>
553 Version : $VERSION$EXTRAVERSION
554 Short desc : $SHORT_DESC
555 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
556 </pre>
558 _EOT_
559 }
561 # xHTML packages list footer.
562 xhtml_footer()
563 {
564 cat >> $XHTML_LIST << _EOT_
565 <hr />
566 <p id="footer">
567 $packages packages installed - List generated on : $DATE
568 </p>
570 <!-- End content -->
571 </div>
572 </body>
573 </html>
574 _EOT_
575 }
577 # Search pattern in installed packages.
578 search_in_installed_packages()
579 {
580 echo "Installed packages"
581 echo "================================================================================"
582 list=`ls -1 $INSTALLED | grep -i "$PATTERN"`
583 for pkg in $list
584 do
585 EXTRAVERSION=""
586 [ -f $INSTALLED/$pkg/receipt ] || continue
587 . $INSTALLED/$pkg/receipt
588 echo -n "$PACKAGE "
589 echo -en "\033[24G $VERSION$EXTRAVERSION"
590 echo -e "\033[42G $CATEGORY"
591 packages=$(($packages+1))
592 done
593 # Set correct ending messages.
594 if [ "$packages" = "" ]; then
595 echo "0 installed packages found for : $PATTERN"
596 echo ""
597 else
598 echo "================================================================================"
599 echo "$packages installed package(s) found for : $PATTERN"
600 echo ""
601 fi
602 }
604 # Search in packages.list for available pkgs.
605 search_in_packages_list()
606 {
607 echo "Available packages name-version"
608 echo "================================================================================"
609 if [ -f "$LOCALSTATE/packages.list" ]; then
610 cat $LOCALSTATE/packages.list | grep -i "$PATTERN"
611 packages=`cat $LOCALSTATE/packages.list | grep "$PATTERN" | wc -l`
612 else
613 echo -e "
614 No 'packages.list' found to check for mirrored packages. For more results,
615 please run 'tazpkg recharge' once as root before searching.\n"
616 fi
617 if [ "$packages" = "0" ]; then
618 echo "0 available packages found for : $PATTERN"
619 echo ""
620 else
621 echo "================================================================================"
622 echo "$packages available package(s) found for : $PATTERN"
623 echo ""
624 fi
625 }
627 # search --mirror: Search in packages.txt for available pkgs and give more
628 # info than --list or default.
629 search_in_packages_txt()
630 {
631 echo "Matching packages name with version and desc"
632 echo "================================================================================"
633 if [ -f "$LOCALSTATE/packages.txt" ]; then
634 cat $LOCALSTATE/packages.txt | grep -A 2 "^$PATTERN"
635 packages=`cat $LOCALSTATE/packages.txt | grep -i "^$PATTERN" | wc -l`
636 else
637 echo -e "
638 No 'packages.txt' found to check for mirrored packages. For more results,
639 please run 'tazpkg recharge' once as root before searching.\n"
640 fi
641 if [ "$packages" = "0" ]; then
642 echo "0 available packages found for : $PATTERN"
643 echo ""
644 else
645 echo "================================================================================"
646 echo "$packages available package(s) found for : $PATTERN"
647 echo ""
648 fi
649 }
651 # Install package-list from a flavor
652 install_flavor()
653 {
654 check_root
655 FLAVOR=$1
656 ARG=$2
657 mkdir -p $TMP_DIR
658 [ -f $FLAVOR.flavor ] && cp $FLAVOR.flavor $TMP_DIR
659 cd $TMP_DIR
660 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
661 zcat $FLAVOR.flavor | cpio -i 2>/dev/null
662 while read file; do
663 for pkg in $(ls -d $INSTALLED/${file%%-*}*); do
664 [ -f $pkg/receipt ] || continue
665 EXTRAVERSION=""
666 . $pkg/receipt
667 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && break
668 done
669 [ "$PACKAGE-$VERSION$EXTRAVERSION" = "$file" ] && continue
670 cd $CACHE_DIR
671 download $file.tazpkg
672 cd $TMP_DIR
673 tazpkg install $CACHE_DIR/$file.tazpkg --forced
674 done < $FLAVOR.pkglist
675 [ -f $FLAVOR.nonfree ] && while read pkg; do
676 [ -d $INSTALLED/$pkg ] || continue
677 [ -d $INSTALLED/get-$pkg ] && tazpkg get-install get-$pkg
678 get-$pkg
679 done < $FLAVOR.nonfree
680 [ "$ARG" == "--purge" ] && for pkg in $(ls $INSTALLED); do
681 [ -f $INSTALLED/$pkg/receipt ] || continue
682 EXTRAVERSION=""
683 . $INSTALLED/$pkg/receipt
684 grep -q ^$PACKAGE-$VERSION$EXTRAVERSION$ $FLAVOR.pkglist && continue
685 grep -qs ^$PACKAGE$ $FLAVOR.nonfree && continue
686 tazpkg remove $PACKAGE
687 done
688 else
689 echo "Can't find flavor $FLAVOR Abort."
690 fi
691 cd $TOP_DIR
692 rm -rf $TMP_DIR
693 }
695 ###################
696 # Tazpkg commands #
697 ###################
699 case "$COMMAND" in
700 list)
701 # List all installed packages or a specific category.
702 #
703 if [ "$2" = "blocked" ]; then
704 if [ -f $BLOCKED ]; then
705 LIST=`cat $BLOCKED`
706 fi
707 echo ""
708 echo -e "\033[1mBlocked packages\033[0m"
709 echo "================================================================================"
710 if [ -n $LIST ];then
711 echo $LIST
712 echo ""
713 else
714 echo -e "No blocked packages found.\n"
715 fi
716 exit 0
717 fi
718 # Display the list of categories.
719 if [ "$2" = "cat" -o "$2" = "categories" ]; then
720 echo ""
721 echo -e "\033[1mPackages categories :\033[0m"
722 echo "================================================================================"
723 for i in $CATEGORIES
724 do
725 echo $i
726 categories=$(($categories+1))
727 done
728 echo "================================================================================"
729 echo "$categories categories"
730 echo ""
731 exit 0
732 fi
733 # Check for an asked category.
734 if [ -n "$2" ]; then
735 ASKED_CATEGORY=$2
736 echo ""
737 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
738 echo "================================================================================"
739 for pkg in $INSTALLED/*
740 do
741 [ -f $pkg/receipt ] || continue
742 EXTRAVERSION=""
743 . $pkg/receipt
744 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
745 echo -n "$PACKAGE"
746 echo -e "\033[24G $VERSION$EXTRAVERSION"
747 packages=$(($packages+1))
748 fi
749 done
750 echo "================================================================================"
751 echo -e "$packages packages installed of category $ASKED_CATEGORY."
752 echo ""
753 else
754 # By default list all packages and versions.
755 echo ""
756 echo -e "\033[1mList of all installed packages\033[0m"
757 echo "================================================================================"
758 for pkg in $INSTALLED/*
759 do
760 [ -f $pkg/receipt ] || continue
761 EXTRAVERSION=""
762 . $pkg/receipt
763 echo -n "$PACKAGE"
764 echo -en "\033[24G $VERSION$EXTRAVERSION"
765 echo -e "\033[42G $CATEGORY"
766 packages=$(($packages+1))
767 done
768 echo "================================================================================"
769 echo "$packages packages installed."
770 echo ""
771 fi
772 ;;
773 xhtml-list)
774 # Get info in receipts and build list.
775 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
776 if [ -n "$2" ]; then
777 XHTML_LIST=$2
778 else
779 XHTML_LIST=installed-packages.html
780 fi
781 echo ""
782 echo -e "\033[1mCreating xHTML list of installed packages\033[0m"
783 echo "================================================================================"
784 echo -n "Generating xHTML header..."
785 xhtml_header
786 status
787 # Packages
788 echo -n "Creating packages information..."
789 for pkg in $INSTALLED/*
790 do
791 [ -f $pkg/receipt ] || continue
792 EXTRAVERSION=""
793 . $pkg/receipt
794 xhtml_pkg_info
795 packages=$(($packages+1))
796 done
797 status
798 echo -n "Generating xHTML footer..."
799 xhtml_footer
800 status
801 # sed pkgs nb in header.
802 sed -i s/'_packages_'/"$packages"/ $XHTML_LIST
803 echo "================================================================================"
804 echo "$XHTML_LIST created - $packages packages."
805 echo ""
806 ;;
807 list-mirror)
808 # List all available packages on the mirror. Option --diff display
809 # last mirrored packages diff (see recharge).
810 check_for_packages_list
811 case $2 in
812 --diff)
813 if [ -f "$LOCALSTATE/packages.diff" ]; then
814 echo ""
815 echo -e "\033[1mMirrored packages diff\033[0m"
816 echo "================================================================================"
817 cat $LOCALSTATE/packages.diff
818 echo "================================================================================"
819 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
820 echo "$pkgs new packages listed on the mirror."
821 echo ""
822 else
823 echo -e "\nUnable to list anything, no packages.diff found."
824 echo -e "Recharge your current list to create a first diff.\n"
825 fi && exit 0 ;;
826 --text|--txt)
827 echo ""
828 echo -e "\033[1mList of available packages on the mirror\033[0m"
829 echo "================================================================================"
830 cat $LOCALSTATE/packages.txt ;;
831 --raw|*)
832 echo ""
833 echo -e "\033[1mList of available packages on the mirror\033[0m"
834 echo "================================================================================"
835 cat $LOCALSTATE/packages.list ;;
836 esac
837 echo "================================================================================"
838 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
839 echo "$pkgs packages in the last recharged list."
840 echo ""
841 ;;
842 list-files)
843 # List files installed with the package.
844 #
845 check_for_package_on_cmdline
846 check_for_receipt
847 echo ""
848 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
849 echo "================================================================================"
850 cat $INSTALLED/$PACKAGE/files.list | sort
851 echo "================================================================================"
852 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
853 echo "$files files installed with $PACKAGE."
854 echo ""
855 ;;
856 info)
857 # Information about package.
858 #
859 check_for_package_on_cmdline
860 check_for_receipt
861 EXTRAVERSION=""
862 . $INSTALLED/$PACKAGE/receipt
863 echo ""
864 echo -e "\033[1mTazpkg information\033[0m
865 ================================================================================
866 Package : $PACKAGE
867 Version : $VERSION$EXTRAVERSION
868 Category : $CATEGORY
869 Short desc : $SHORT_DESC
870 Maintainer : $MAINTAINER"
871 if [ ! "$DEPENDS" = "" ]; then
872 echo -e "Depends : $DEPENDS"
873 fi
874 if [ ! "$SUGGESTED" = "" ]; then
875 echo -e "Suggested : $SUGGESTED"
876 fi
877 if [ ! "$BUILD_DEPENDS" = "" ]; then
878 echo -e "Build deps : $BUILD_DEPENDS"
879 fi
880 if [ ! "$WANTED" = "" ]; then
881 echo -e "Wanted src : $WANTED"
882 fi
883 if [ ! "$WEB_SITE" = "" ]; then
884 echo -e "Web site : $WEB_SITE"
885 fi
886 echo "================================================================================"
887 echo ""
888 ;;
889 desc)
890 # Display package description.txt if available.
891 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
892 echo ""
893 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
894 echo "================================================================================"
895 cat $INSTALLED/$PACKAGE/description.txt
896 echo "================================================================================"
897 echo ""
898 else
899 echo -e "\nSorry, no description available for this package.\n"
900 fi
901 ;;
902 search)
903 # Search for a package by pattern or name.
904 #
905 PATTERN="$2"
906 if [ -z "$PATTERN" ]; then
907 echo -e "\nPlease specify a pattern or package name to search for."
908 echo -e "Example : 'tazpkg search paint'.\n"
909 exit 0
910 fi
911 echo ""
912 echo -e "\033[1mSearch result for :\033[0m $PATTERN"
913 echo ""
914 # Default is to search in installed pkgs and the raw list.
915 case $3 in
916 -i|--installed)
917 search_in_installed_packages ;;
918 -l|--list)
919 search_in_packages_list ;;
920 -m|--mirror)
921 search_in_packages_txt ;;
922 *)
923 search_in_installed_packages
924 search_in_packages_list ;;
925 esac
926 ;;
927 search-file)
928 # Search for a file by pattern or name in all files.list.
929 #
930 if [ -z "$2" ]; then
931 echo -e "\nPlease specify a pattern or file name to search for."
932 echo -e "Example : 'tazpkg search-file libnss'. \n"
933 exit 0
934 fi
935 echo ""
936 echo -e "\033[1mSearch result for file :\033[0m $2"
937 echo "================================================================================"
939 if [ "$3" == "--mirror" ]; then
941 unlzma -c $LOCALSTATE/files.list.lzma | grep -- ".*:.*$2" | awk '
942 BEGIN { last="" }
943 {
944 pkg=substr($0,0,index($0,":")-1);
945 file=substr($0,index($0,":")+2);
946 if (last != pkg) {
947 last = pkg;
948 printf("\n%c[1mPackage %s :%c[0m\n",27,pkg,27);
949 }
950 printf("%s\n",file);
951 }'
952 match=`unlzma -c $LOCALSTATE/files.list.lzma | \
953 grep -- ".*:.*$2" | wc -l`
955 else
957 # Check all pkg files.list in search match with specify the package
958 # name and the full path to the file(s).
959 for pkg in $INSTALLED/*
960 do
961 if grep -qs "$2" $pkg/files.list; then
962 . $pkg/receipt
963 echo ""
964 echo -e "\033[1mPackage $PACKAGE :\033[0m"
965 grep "$2" $pkg/files.list
966 files=`grep $2 $pkg/files.list | wc -l`
967 match=$(($match+$files))
968 fi
969 done
971 fi
973 if [ "$match" = "" ]; then
974 echo "0 file found for : $2"
975 echo ""
976 else
977 echo ""
978 echo "================================================================================"
979 echo "$match file(s) found for : $2"
980 echo ""
981 fi
982 ;;
983 install)
984 # Install .tazpkg packages.
985 #
986 check_root
987 check_for_package_on_cmdline
988 check_for_package_file
989 # Check if forced install.
990 DO_CHECK="yes"
991 ROOT=""
992 while [ -n "$3" ]; do
993 case "$3" in
994 --forced)
995 DO_CHECK="no"
996 ;;
997 --root=*)
998 ROOT="${3#--root=}"
999 ;;
1000 --list=*)
1001 INSTALL_LIST="${3#--list=}"
1002 ;;
1003 *) shift 2
1004 echo -e "\nUnknown option $*.\n"
1005 exit 1
1006 ;;
1007 esac
1008 shift
1009 done
1010 if [ "$DO_CHECK" = "yes" ]; then
1011 check_for_installed_package $ROOT
1012 fi
1013 install_package $ROOT
1014 ;;
1015 install-list|get-install-list)
1016 # Install a set of packages from a list.
1018 check_root
1019 if [ -z "$2" ]; then
1020 echo -e "
1021 Please change directory (cd) to the packages repository, and specify the
1022 list of packages to install. Example : tazpkg install-list packages.list\n"
1023 exit 0
1024 fi
1025 # Check if the packages list exist.
1026 if [ ! -f "$2" ]; then
1027 echo "Unable to find : $2"
1028 exit 0
1029 else
1030 LIST=`cat $2`
1031 fi
1033 # Remember processed list
1034 export INSTALL_LIST="$2"
1036 # Set $COMMAND and install all packages.
1037 if [ "$1" = "get-install-list" ]; then
1038 COMMAND=get-install
1039 else
1040 COMMAND=install
1041 fi
1042 touch $2-processed
1043 for pkg in $LIST
1044 do
1045 grep -qs ^$pkg$ $2-processed && continue
1046 tazpkg $COMMAND $pkg --list=$2 "$3" "$4" "$5"
1047 done
1048 rm -f $2-processed
1049 ;;
1050 add-flavor)
1051 # Install a set of packages from a flavor.
1053 install_flavor $2
1054 ;;
1055 install-flavor)
1056 # Install a set of packages from a flavor and purge other ones.
1058 install_flavor $2 --purge
1059 ;;
1060 set-release)
1061 # Change curent release and upgrade packages.
1063 RELEASE=$2
1064 if [ -z "$RELEASE" ]; then
1065 echo -e "\nPlease specify the release you want on the command line."
1066 echo -e "Example: tazpkg set-release cooking\n"
1067 exit 0
1068 fi
1069 rm /var/lib/tazpkg/mirror
1070 echo "$RELEASE" > /etc/slitaz-release
1071 tazpkg recharge && tazpkg upgrade
1072 ;;
1073 remove)
1074 # Remove packages.
1076 check_root
1077 check_for_package_on_cmdline
1078 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
1079 echo -e "\n$PACKAGE is not installed.\n"
1080 exit 0
1081 else
1082 ALTERED=""
1083 THE_PACKAGE=$PACKAGE # altered by receipt
1084 for i in $(cd $INSTALLED ; ls); do
1085 [ -f $i/receipt ] || continue
1086 DEPENDS=""
1087 . $INSTALLED/$i/receipt
1088 case " $(echo $DEPENDS) " in
1089 *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";;
1090 esac
1091 done
1092 EXTRAVERSION=""
1093 . $INSTALLED/$THE_PACKAGE/receipt
1094 fi
1095 echo ""
1096 if [ -n "$ALTERED" ]; then
1097 echo "The following packages depend on $PACKAGE :"
1098 for i in $ALTERED; do
1099 echo " $i"
1100 done
1101 fi
1102 REFRESH=$(cd $INSTALLED ; grep -sl ^$PACKAGE$ */modifiers)
1103 if [ -n "$REFRESH" ]; then
1104 echo "The following packages have been modified $PACKAGE :"
1105 for i in $REFRESH; do
1106 echo " $i"
1107 done
1108 fi
1109 echo "Remove $PACKAGE ($VERSION$EXTRAVERSION) ?"
1110 echo -n "Please confirm uninstallation (y/N) : "; read anser
1111 if [ "$anser" = "y" ]; then
1112 echo ""
1113 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
1114 echo "================================================================================"
1115 # Pre remove commands.
1116 if grep -q ^pre_remove $INSTALLED/$PACKAGE/receipt; then
1117 pre_remove
1118 fi
1119 echo -n "Removing all files installed..."
1120 for file in `cat $INSTALLED/$PACKAGE/files.list`
1121 do
1122 [ $(grep ^$file$ $INSTALLED/*/files.list | wc -l) -gt 1 ] && continue
1123 rm -rf $file 2>/dev/null
1124 done
1125 status
1126 if grep -q ^post_remove $INSTALLED/$PACKAGE/receipt; then
1127 post_remove
1128 fi
1129 # Remove package receipt.
1130 echo -n "Removing package receipt..."
1131 rm -rf $INSTALLED/$PACKAGE
1132 status
1133 if [ -n "$ALTERED" ]; then
1134 echo -n "Remove packages depending on $PACKAGE"
1135 echo -n " (y/N) ? "; read anser
1136 if [ "$anser" = "y" ]; then
1137 for i in $ALTERED; do
1138 if [ -d "$INSTALLED/$i" ]; then
1139 tazpkg remove $i
1140 fi
1141 done
1142 fi
1143 fi
1144 if [ -n "$REFRESH" ]; then
1145 echo -n "Reinstall packages modified by $PACKAGE"
1146 echo -n " (y/N) ? "; read anser
1147 if [ "$anser" = "y" ]; then
1148 for i in $REFRESH; do
1149 if [ $(wc -l $INSTALLED/$i/modifiers) -gt 1 ]; then
1150 echo "Check $INSTALLED/$i/modifiers for reinstallation"
1151 continue
1152 fi
1153 rm -r $INSTALLED/$i/modifiers
1154 tazpkg get-install $i --forced
1155 done
1156 fi
1157 fi
1158 else
1159 echo ""
1160 echo "Uninstallation of $PACKAGE cancelled."
1161 fi
1162 echo ""
1163 ;;
1164 extract)
1165 # Extract .tazpkg cpio archive into a directory.
1167 check_for_package_on_cmdline
1168 check_for_package_file
1169 echo ""
1170 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
1171 echo "================================================================================"
1172 # If no directory destination is found on the cmdline
1173 # we create one in the current dir using the package name.
1174 if [ -n "$TARGET_DIR" ]; then
1175 DESTDIR=$TARGET_DIR/$PACKAGE
1176 else
1177 DESTDIR=$PACKAGE
1178 fi
1179 mkdir -p $DESTDIR
1180 echo -n "Copying original package..."
1181 cp $PACKAGE_FILE $DESTDIR
1182 status
1183 cd $DESTDIR
1184 extract_package
1185 echo "================================================================================"
1186 echo "$PACKAGE is extracted to : $DESTDIR"
1187 echo ""
1188 ;;
1189 list-config)
1190 # List configuration files installed.
1192 if [ "$2" = "--box" ]; then
1193 mkdir -p $TMP_DIR && cd $TMP_DIR
1194 for i in $INSTALLED/*/volatile.cpio.gz; do
1195 zcat $i | cpio -id > /dev/null
1196 find * -type f | while read file; do
1197 echo -n "$(stat -c "%A|%U|%G|%s|" /$file)"
1198 cmp $file /$file > /dev/null 2>&1 || \
1199 echo -n "$(stat -c "%.16y" /$file)"
1200 echo "|/$file"
1201 done
1202 rm -rf *
1203 done
1204 cd $TOP_DIR
1205 rm -rf $TMP_DIR
1206 else
1207 echo ""
1208 echo -e "\033[1mConfiguration files"
1209 echo "================================================================================"
1210 for i in $INSTALLED/*/volatile.cpio.gz; do
1211 [ -n "$2" -a "$i" != "$INSTALLED/$2/volatile.cpio.gz" ] && continue
1212 [ -f "$i" ] || continue
1213 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1214 done | sed 's|^|/|' | sort
1215 echo "================================================================================"
1216 echo ""
1217 fi
1218 ;;
1219 repack-config)
1220 # Create SliTaz package archive from configuration files.
1222 mkdir -p $TMP_DIR && cd $TMP_DIR
1223 CONFIG_VERSION=1.0
1224 mkdir config-$CONFIG_VERSION
1225 cd config-$CONFIG_VERSION
1226 for i in $INSTALLED/*/volatile.cpio.gz; do
1227 zcat $i | cpio -t | grep -v "[0-9]* blocks"
1228 done > files.list
1229 mkdir fs
1230 cd fs
1231 ( cd / ; cpio -o -H newc ) < ../files.list | cpio -id > /dev/null
1232 mkdir -p etc/tazlito
1233 for i in $INSTALLED/*/receipt; do
1234 EXTRAVERSION=""
1235 . $i
1236 echo "$PACKAGE-$VERSION$EXTRAVERSION"
1237 done > etc/tazlito/config-packages.list
1238 cd ..
1239 echo "etc/tazlito/config-packages.list" >> files.list
1240 cat > receipt <<EOT
1241 # SliTaz package receipt.
1243 PACKAGE="config"
1244 VERSION="$CONFIG_VERSION"
1245 CATEGORY="base-system"
1246 SHORT_DESC="User configuration backup on $(date)"
1247 DEPENDS="$(ls $INSTALLED)"
1248 EOT
1249 cd ..
1250 tazpkg pack config-$CONFIG_VERSION
1251 cp config-$CONFIG_VERSION.tazpkg $TOP_DIR
1252 cd $TOP_DIR
1253 rm -rf $TMP_DIR
1254 ;;
1255 repack)
1256 # Create SliTaz package archive from an installed package.
1258 check_for_package_on_cmdline
1259 check_for_receipt
1260 EXTRAVERSION=""
1261 . $INSTALLED/$PACKAGE/receipt
1262 echo ""
1263 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
1264 echo "================================================================================"
1265 if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
1266 echo "Can't repack $PACKAGE"
1267 exit 1
1268 fi
1269 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
1270 echo "Can't repack, $PACKAGE files have been modified by:"
1271 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
1272 echo " $i"
1273 done
1274 exit 1
1275 fi
1276 MISSING=""
1277 while read i; do
1278 [ -e "$i" ] && continue
1279 [ -L "$i" ] || MISSING="$MISSING\n $i"
1280 done < $INSTALLED/$PACKAGE/files.list
1281 if [ -n "$MISSING" ]; then
1282 echo -n "Can't repack, the following files are lost:"
1283 echo -e "$MISSING"
1284 exit 1
1285 fi
1286 mkdir -p $TMP_DIR && cd $TMP_DIR
1287 FILES="fs.cpio.gz\n"
1288 for i in $(ls $INSTALLED/$PACKAGE) ; do
1289 [ "$i" = "volatile.cpio.gz" ] && continue
1290 [ "$i" = "modifiers" ] && continue
1291 cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
1292 done
1293 ln -s / rootfs
1294 mkdir tmp
1295 sed 's/^/rootfs/' < files.list | cpio -o -H newc 2>/dev/null |\
1296 ( cd tmp ; cpio -id 2>/dev/null )
1297 mv tmp/rootfs fs
1298 if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
1299 zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
1300 ( cd fs; cpio -id )
1301 fi
1302 if grep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
1303 . $INSTALLED/$PACKAGE/receipt
1304 repack_cleanup fs
1305 fi
1306 if [ -f $INSTALLED/$PACKAGE/md5sum ]; then
1307 sed 's, , fs,' < $INSTALLED/$PACKAGE/md5sum | \
1308 if ! md5sum -s -c; then
1309 echo -n "Can't repack, md5sum error."
1310 cd $TOP_DIR
1311 \rm -R $TMP_DIR
1312 exit 1
1313 fi
1314 fi
1315 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
1316 echo -e "$FILES" | cpio -o -H newc 2> /dev/null > \
1317 $TOP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1318 cd $TOP_DIR
1319 \rm -R $TMP_DIR
1320 echo "Package $PACKAGE repacked successfully."
1321 echo "Size : `du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg`"
1322 echo ""
1323 ;;
1324 pack)
1325 # Create SliTaz package archive using cpio and gzip.
1327 check_for_package_on_cmdline
1328 cd $PACKAGE
1329 if [ ! -f "receipt" ]; then
1330 echo "Receipt is missing. Please read the documentation."
1331 exit 0
1332 else
1333 echo ""
1334 echo -e "\033[1mPacking :\033[0m $PACKAGE"
1335 echo "================================================================================"
1336 # Create files.list with redirecting find outpout.
1337 echo -n "Creating the list of files..." && cd fs
1338 find . -type f -print > ../files.list
1339 find . -type l -print >> ../files.list
1340 cd .. && sed -i s/'^.'/''/ files.list
1341 status
1342 echo -n "Creating md5sum of files..."
1343 while read file; do
1344 [ -L "fs$file" ] && continue
1345 [ -f "fs$file" ] || continue
1346 case "$file" in
1347 /lib/modules/*/modules.*|*.pyc) continue;;
1348 esac
1349 md5sum "fs$file" | sed 's/ fs/ /'
1350 done < files.list > md5sum
1351 status
1352 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
1353 description.txt 2> /dev/null | awk \
1354 '{ sz=$1 } END { print sz }')
1355 # Build cpio archives.
1356 echo -n "Compressing the fs... "
1357 find fs -print | cpio -o -H newc | gzip > fs.cpio.gz
1358 rm -rf fs
1359 status
1360 PACKED_SIZE=$(du -chs fs.cpio.gz receipt files.list \
1361 md5sum description.txt 2> /dev/null | awk \
1362 '{ sz=$1 } END { print sz }')
1363 echo -n "Undating receipt sizes..."
1364 sed -i s/^PACKED_SIZE.*$// receipt
1365 sed -i s/^UNPACKED_SIZE.*$// receipt
1366 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1367 status
1368 echo -n "Creating full cpio archive... "
1369 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
1370 status
1371 echo -n "Restoring original package tree... "
1372 zcat fs.cpio.gz | cpio -id
1373 status
1374 rm fs.cpio.gz && cd ..
1375 echo "================================================================================"
1376 echo "Package $PACKAGE compressed successfully."
1377 echo "Size : `du -sh $PACKAGE.tazpkg`"
1378 echo ""
1379 fi
1380 ;;
1381 recharge)
1382 # Recharge packages.list from a mirror.
1384 check_root
1385 cd $LOCALSTATE
1386 echo ""
1387 if [ -f "$LOCALSTATE/packages.list" ]; then
1388 echo -n "Creating backup of the last packages list..."
1389 mv -f packages.desc packages.desc.bak 2>/dev/null
1390 mv -f packages.txt packages.txt.bak 2>/dev/null
1391 mv -f packages.list packages.list.bak 2>/dev/null
1392 mv -f packages.equiv packages.equiv.bak 2>/dev/null
1393 mv -f files.list.lzma files.list.lzma.bak 2> /dev/nul
1394 status
1395 fi
1396 download packages.desc
1397 download packages.txt
1398 download packages.list
1399 download packages.equiv
1400 download files.list.lzma
1401 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
1402 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
1403 sed -i s/+// packages.diff
1404 echo ""
1405 echo -e "\033[1mMirrored packages diff\033[0m"
1406 echo "================================================================================"
1407 cat packages.diff
1408 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
1409 echo "================================================================================"
1410 echo "`cat packages.diff | wc -l` new packages on the mirror."
1411 echo ""
1412 else
1413 echo "`cat packages.diff | wc -l` new packages on the mirror."
1414 echo ""
1415 fi
1416 else
1417 echo -e "
1418 ================================================================================
1419 Last packages.list is ready to use. Note that next time you recharge the list,
1420 a list of differencies will be displayed to show new and upgradeable packages.\n"
1421 fi
1422 ;;
1423 upgrade)
1424 # Upgrade all installed packages with the new version from the mirror.
1426 check_root
1427 check_for_packages_list
1428 cd $LOCALSTATE
1429 # Touch the blocked pkgs list to avoid errors and remove any old
1430 # upgrade list.
1431 touch blocked-packages.list
1432 rm -f upgradeable-packages.list
1433 echo ""
1434 echo -e "\033[1mAvailable upgrades\033[0m"
1435 echo "================================================================================"
1436 echo ""
1437 # Some packages must be installed first
1438 FIRST_CLASS_PACKAGE=" glibc-base slitaz-base-files slitaz-boot-scripts "
1439 for pkg in $INSTALLED/*
1440 do
1441 [ -f $pkg/receipt ] || continue
1442 EXTRAVERSION=""
1443 . $pkg/receipt
1444 # Display package name to show that Tazpkg is working...
1445 echo -en "\\033[0G "
1446 echo -en "\\033[0G$PACKAGE"
1447 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
1448 if grep -q "^$PACKAGE" $BLOCKED; then
1449 blocked=$(($blocked+1))
1450 else
1451 # Check if the installed package is in the current list (other
1452 # mirror or local).
1453 NEW_PACKAGE=$(grep "^$PACKAGE-[0-9]" packages.list | head -1)
1454 [ -n "$NEW_PACKAGE" ] || NEW_PACKAGE=$(grep "^$PACKAGE-.[\.0-9]" packages.list | head -1)
1456 if [ -n "$NEW_PACKAGE" ]; then
1457 # Set new pkg and version for futur comparaison
1458 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
1459 # Change '-' and 'pre' to points.
1460 NEW_VERSION=`echo $NEW_VERSION | sed s/'-'/'.'/`
1461 VERSION=`echo $VERSION | sed s/'-'/'.'/`$EXTRAVERSION
1462 NEW_VERSION=`echo $NEW_VERSION | sed s/'pre'/'.'/`
1463 VERSION=`echo $VERSION | sed s/'pre'/'.'/`
1464 NEW_VERSION=`echo $NEW_VERSION | sed 's/[A-Z]\.//'`
1465 VERSION=`echo $VERSION | sed 's/[A-Z]\.//'`
1466 # Compare version. Upgrade are only available for official
1467 # packages, so we control de mirror and it should be ok if
1468 # we just check for egality.
1469 if [ "$VERSION" != "$NEW_VERSION" ]; then
1470 # Version seems different. Check for major, minor or
1471 # revision
1472 PKG_MAJOR=`echo ${VERSION%_*} | cut -f1 -d"."`
1473 NEW_MAJOR=`echo ${NEW_VERSION%_*} | cut -f1 -d"."`
1474 PKG_MINOR=`echo ${VERSION%_*} | cut -f2 -d"."`
1475 NEW_MINOR=`echo ${NEW_VERSION%_*} | cut -f2 -d"."`
1476 # Minor
1477 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
1478 RELEASE=minor
1479 fi
1480 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
1481 RELEASE=$WARNING
1482 FIXE=yes
1483 fi
1484 # Major
1485 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
1486 RELEASE=major
1487 FIXE=""
1488 fi
1489 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
1490 RELEASE=$WARNING
1491 FIXE=yes
1492 fi
1493 # Default to revision.
1494 if [ -z $RELEASE ]; then
1495 RELEASE=revision
1496 fi
1497 # Pkg name is already displayed by the check process.
1498 echo -en "\033[24G $VERSION"
1499 echo -en "\033[38G --->"
1500 echo -en "\033[43G $NEW_VERSION"
1501 echo -en "\033[58G $CATEGORY"
1502 echo -e "\033[72G $RELEASE"
1503 up=$(($up+1))
1504 echo "$PACKAGE" >> upgradeable-packages.list
1505 case "$FIRST_CLASS_PACKAGE" in
1506 *\ $PACKAGE\ *) echo "$PACKAGE" >> upgradeable-packages.list$$;;
1507 esac
1508 unset RELEASE
1509 fi
1510 packages=$(($packages+1))
1511 fi
1512 fi
1513 done
1514 if [ -z $blocked ]; then
1515 blocked=0
1516 fi
1517 # Clean last checked package and display summary.
1518 if [ ! "$up" = "" ]; then
1519 echo -e "\\033[0G "
1520 echo "================================================================================"
1521 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
1522 echo ""
1523 else
1524 echo -e "\\033[0GSystem is up-to-date. "
1525 echo ""
1526 echo "================================================================================"
1527 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
1528 echo ""
1529 exit 0
1530 fi
1531 # What to do if major or minor version is smaller.
1532 if [ "$FIXE" == "yes" ]; then
1533 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
1534 echo "You can block packages using the command : 'tazpkg block package'"
1535 echo "Or upgrade package at you own risks."
1536 echo ""
1537 fi
1538 # Ask for upgrade, it can be done another time.
1539 echo -n "Upgrade now (y/N) ? "; read anser
1540 if [ ! "$anser" = "y" ]; then
1541 echo -e "\nExiting. No package upgraded.\n"
1542 exit 0
1543 fi
1544 # If anser is yes (y). Install all new versions.
1545 cat upgradeable-packages.list >> upgradeable-packages.list$$
1546 mv -f upgradeable-packages.list$$ upgradeable-packages.list
1547 yes y | tazpkg get-install-list upgradeable-packages.list
1548 #rm -f upgradeable-packages.list
1549 ;;
1550 bugs)
1551 # Show known bugs in package(s)
1553 cd $INSTALLED
1554 shift
1555 LIST=$@
1556 [ -n "$LIST" ] || LIST=`ls`
1557 MSG="No known bugs."
1558 for PACKAGE in $LIST; do
1559 BUGS=""
1560 EXTRAVERSION=""
1561 . $PACKAGE/receipt
1562 if [ -n "$BUGS" ]; then
1563 MSG="
1564 Bug list completed"
1565 cat <<EOT
1567 Bugs in package $PACKAGE version $VERSION$EXTRAVERSION:
1568 $BUGS
1569 EOT
1570 fi
1571 done
1572 echo "$MSG"
1573 ;;
1574 check)
1575 # Check installed packages set.
1577 check_root
1578 cd $INSTALLED
1579 for PACKAGE in `ls`; do
1580 if [ ! -f $PACKAGE/receipt ]; then
1581 echo "The package $PACKAGE installation is not completed"
1582 continue
1583 fi
1584 DEPENDS=""
1585 EXTRAVERSION=""
1586 . $PACKAGE/receipt
1587 if [ -s $PACKAGE/modifiers ]; then
1588 echo "The package $PACKAGE $VERSION$EXTRAVERSION has been modified by :"
1589 for i in $(cat $PACKAGE/modifiers); do
1590 echo " $i"
1591 done
1592 fi
1593 MSG="Files lost from $PACKAGE $VERSION$EXTRAVERSION :\n"
1594 while read file; do
1595 [ -e "$file" ] && continue
1596 if [ -L "$file" ]; then
1597 MSG="$MSG target of symlink"
1598 fi
1599 echo -e "$MSG $file"
1600 MSG=""
1601 done < $PACKAGE/files.list
1602 MSG="Missing dependencies for $PACKAGE $VERSION$EXTRAVERSION :\n"
1603 for i in $DEPENDS; do
1604 [ -d $i ] && continue
1605 echo -e "$MSG $i"
1606 MSG=""
1607 done
1608 MSG="Dependencies loop between $PACKAGE and :\n"
1609 ALL_DEPS=""
1610 check_for_deps_loop $PACKAGE $DEPENDS
1611 done
1612 echo -n "Looking for known bugs... "
1613 tazpkg bugs
1614 if [ "$PACKAGE_FILE" = "--full" ]; then
1615 for file in */md5sum; do
1616 [ -s "$file" ] || continue
1617 md5sum -c "$file" 2> /dev/null | grep -v OK$ |\
1618 sed 's/FAILED$/MD5SUM MISMATCH/'
1619 done
1620 FILES=" "
1621 for file in $(cat */files.list); do
1622 [ -d "$file" ] && continue
1623 case "$FILES" in *\ $file\ *) continue;; esac
1624 [ $(grep "^$file$" */files.list 2> /dev/null | \
1625 wc -l) -gt 1 ] || continue
1626 FILES="$FILES$file "
1627 echo "The following packages provide $file :"
1628 grep -l "^$file$" */files.list | while read f
1629 do
1630 pkg=${f%/files.list}
1631 echo -n " $pkg"
1632 if [ -f $pkg/modifiers ]; then
1633 echo -n " (overridden by $(echo "$(cat $pkg/modifiers)"))"
1634 fi
1635 echo ""
1636 done
1637 done
1638 MSG="No package has installed the following files:\n"
1639 find /etc /bin /sbin /lib /usr /var/www \
1640 -not -type d 2> /dev/null | while read file; do
1641 case "$file" in *\[*) continue;; esac
1642 grep -q "^$file$" */files.list && continue
1643 echo -e "$MSG $file"
1644 MSG=""
1645 done
1646 fi
1647 echo "Check completed."
1648 ;;
1649 block)
1650 # Add a pkg name to the list of blocked packages.
1652 check_root
1653 check_for_package_on_cmdline
1654 echo ""
1655 if grep -q "^$PACKAGE" $BLOCKED; then
1656 echo "$PACKAGE is already in the blocked packages list."
1657 echo ""
1658 exit 0
1659 else
1660 echo -n "Add $PACKAGE to : $BLOCKED..."
1661 echo $PACKAGE >> $BLOCKED
1662 status
1663 fi
1664 echo ""
1665 ;;
1666 unblock)
1667 # Remove a pkg name from the list of blocked packages.
1669 check_root
1670 check_for_package_on_cmdline
1671 echo ""
1672 if grep -q "^$PACKAGE" $BLOCKED; then
1673 echo -n "Removing $PACKAGE from : $BLOCKED..."
1674 sed -i s/$PACKAGE/''/ $BLOCKED
1675 sed -i '/^$/d' $BLOCKED
1676 status
1677 else
1678 echo "$PACKAGE is not in the blocked packages list."
1679 echo ""
1680 exit 0
1681 fi
1682 echo ""
1683 ;;
1684 get)
1685 # Downlowd a package with wget.
1687 check_for_package_on_cmdline
1688 check_for_packages_list
1689 check_for_package_in_list
1690 echo ""
1691 download $PACKAGE.tazpkg
1692 echo ""
1693 ;;
1694 get-install)
1695 # Download and install a package.
1697 check_root
1698 check_for_package_on_cmdline
1699 check_for_packages_list
1700 check_for_package_in_list
1701 DO_CHECK=""
1702 while [ -n "$3" ]; do
1703 case "$3" in
1704 --forced)
1705 DO_CHECK="no"
1706 ;;
1707 --root=*)
1708 ROOT="${3#--root=}"
1709 ;;
1710 --list=*)
1711 INSTALL_LIST="${3#--list=}"
1712 ;;
1713 *) shift 2
1714 echo -e "\nUnknown option $*.\n"
1715 exit 1
1716 ;;
1717 esac
1718 shift
1719 done
1720 # Check if forced install.
1721 if [ "$DO_CHECK" = "no" ]; then
1722 rm -f $CACHE_DIR/$PACKAGE.tazpkg
1723 else
1724 check_for_installed_package $ROOT
1725 fi
1726 cd $CACHE_DIR
1727 if [ -f "$PACKAGE.tazpkg" ]; then
1728 echo "$PACKAGE already in the cache : $CACHE_DIR"
1729 # Check package download was finished
1730 tail -c 2k $PACKAGE.tazpkg | grep -q 00000000TRAILER || {
1731 echo "Continue $PACKAGE download"
1732 download $PACKAGE.tazpkg
1734 else
1735 echo ""
1736 download $PACKAGE.tazpkg
1737 fi
1738 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
1739 install_package $ROOT
1740 ;;
1741 clean-cache)
1742 # Remove all downloaded packages.
1744 check_root
1745 files=`ls -1 $CACHE_DIR | wc -l`
1746 echo ""
1747 echo -e "\033[1mClean cache :\033[0m $CACHE_DIR"
1748 echo "================================================================================"
1749 echo -n "Cleaning cache directory..."
1750 rm -rf $CACHE_DIR/*
1751 status
1752 echo "================================================================================"
1753 echo "$files file(s) removed from cache."
1754 echo ""
1755 ;;
1756 setup-mirror)
1757 # Change mirror URL.
1759 check_root
1760 # Backup old list.
1761 if [ -f "$LOCALSTATE/mirror" ]; then
1762 cp -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
1763 fi
1764 echo ""
1765 echo -e "\033[1mCurrent mirror(s)\033[0m"
1766 echo "================================================================================"
1767 echo " `cat $MIRROR`"
1768 echo "
1769 Please enter URL of the new mirror (http or ftp). You must specify the complete
1770 address to the directory of the packages and packages.list file."
1771 echo ""
1772 echo -n "New mirror URL : "
1773 read NEW_MIRROR_URL
1774 if [ "$NEW_MIRROR_URL" = "" ]; then
1775 echo "Nothing has been changed."
1776 else
1777 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
1778 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
1779 fi
1780 echo ""
1781 ;;
1782 reconfigure)
1783 # Replay post_install from receipt
1785 check_for_package_on_cmdline
1786 check_root
1787 if [ -d "$INSTALLED/$PACKAGE" ]; then
1788 check_for_receipt
1789 # Check for post_install
1790 if grep -q ^post_install $INSTALLED/$PACKAGE/receipt; then
1791 . $INSTALLED/$PACKAGE/receipt
1792 post_install
1793 else
1794 echo -e "\nNothing to do for $PACKAGE."
1795 fi
1796 else
1797 echo -e "\npackage $PACKAGE is not installed."
1798 echo -e "Install package with 'tazpkg install' or 'tazpkg get-install'\n"
1799 fi
1800 ;;
1801 shell)
1802 # Tazpkg SHell
1804 if test $(id -u) = 0 ; then
1805 PROMPT="\\033[1;33mtazpkg\\033[0;39m# "
1806 else
1807 PROMPT="\\033[1;33mtazpkg\\033[0;39m> "
1808 fi
1809 if [ ! "$2" = "--noheader" ]; then
1810 clear
1811 echo ""
1812 echo -e "\033[1mTazpkg SHell.\033[0m"
1813 echo "================================================================================"
1814 echo "Type 'usage' to list all available commands or 'quit' or 'q' to exit."
1815 echo ""
1816 fi
1817 while true
1818 do
1819 echo -en "$PROMPT"; read cmd
1820 case $cmd in
1821 q|quit)
1822 break ;;
1823 shell)
1824 echo "You are already running a Tazpkg SHell." ;;
1825 su)
1826 su -c 'exec tazpkg shell --noheader' && break ;;
1827 "")
1828 continue ;;
1829 *)
1830 tazpkg $cmd ;;
1831 esac
1832 done
1833 ;;
1834 usage|*)
1835 # Print a short help or give usage for an unknown or empty command.
1837 usage
1838 ;;
1839 esac
1841 exit 0