tazpkg view tazpkg @ rev 191

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