tazpkg view tazpkg @ rev 197

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