tazpkg view tazpkg @ rev 183

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