tazpkg view tazpkg @ rev 185

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