tazpkg view tazpkg @ rev 187

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