tazpkg view tazpkg @ rev 23

Repack: do not forget description.txt
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Dec 14 19:22:56 2007 +0000 (2007-12-14)
parents 28c9ef6dbf16
children a74b3a7e64e7
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 let 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 a short description. Tazpkg
8 # also relolv dependencies and can upgrade packages from a mirror.
9 #
10 # (C) 2007 SliTaz - GNU General Public License v3.
11 # Initial author : <pankso@slitaz.org>
12 #
13 VERSION=1.4
15 ####################
16 # Script variables #
17 ####################
19 # Packages categories.
20 CATEGORIES="base-system base-apps x-window extra devel"
22 # Initialize some variables to use words
23 # rater than numbers for functions and actions.
24 COMMAND=$1
25 if [ -f $2 ]; then
26 # Set pkg basename for install, extract
27 PACKAGE=$(basename ${2%.tazpkg} 2>/dev/null)
28 else
29 # Pkg name for remove, search and all other cmds
30 PACKAGE=${2%.tazpkg}
31 fi
32 PACKAGE_FILE=$2
33 TARGET_DIR=$3
34 TOP_DIR=`pwd`
35 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
37 # Path to tazpkg used dir and configuration files
38 LOCALSTATE=/var/lib/tazpkg
39 INSTALLED=$LOCALSTATE/installed
40 CACHE_DIR=/var/cache/tazpkg
41 MIRROR=$LOCALSTATE/mirror
42 PACKAGES_LIST=$LOCALSTATE/packages.list
43 BLOCKED=$LOCALSTATE/blocked-packages.list
45 # Bold red warnig for upgrade.
46 WARNING="\\033[1;31mWARNING\\033[0;39m"
48 # Check if the directories and files used by Tazpkg
49 # exists. If not and user is root we creat them.
50 if test $(id -u) = 0 ; then
51 if [ ! -d "$CACHE_DIR" ]; then
52 mkdir -p $CACHE_DIR
53 fi
54 if [ ! -d "$INSTALLED" ]; then
55 mkdir -p $INSTALLED
56 fi
57 if [ ! -f "$LOCALSTATE/mirror" ]; then
58 echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
59 fi
60 fi
62 ####################
63 # Script functions #
64 ####################
66 # Print the usage.
67 usage ()
68 {
69 echo -e "SliTaz packages manager - Version: $VERSION
70 \033[1mUsage: \033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
71 \033[1mCommands: \033[0m
72 usage Print this short usage.
73 list List installed packages on the system by category or all.
74 list-mirror List all available packages on the mirror (--diff for new).
75 info Print informations about the package.
76 desc Print description of a package (if it exist).
77 list-files List of files installed with the package.
78 search Search for a package by pattern or name.
79 search-file Search for file(s) in all installed packages files.
80 install Install a local (*.tazpkg) package (--forced to force).
81 install-list Install all packages from a list of packages.
82 remove Remove the specified package and all installed files.
83 extract Extract a (*.tazpkg) package into a directory.
84 pack Pack an unpacked or prepared package tree.
85 recharge Recharge your packages.list from the mirror.
86 repack Creat a package archive from an installed package.
87 upgrade Upgrade all installed and listed packages on the mirror.
88 block|unblock Block an installed package version or unblock it for upgrade.
89 get Download a package into the current directory.
90 get-install Download and install a package from the mirror.
91 clean-cache Clean all packages downloaded in cache directory.
92 setup-mirror Change the mirror url configuration."
93 }
95 # Status function with color (supported by Ash).
96 status()
97 {
98 local CHECK=$?
99 echo -en "\\033[70G[ "
100 if [ $CHECK = 0 ]; then
101 echo -en "\\033[1;33mOK"
102 else
103 echo -en "\\033[1;31mFailed"
104 fi
105 echo -e "\\033[0;39m ]"
106 return $CHECK
107 }
109 # Check if user is root to install, or remove packages.
110 check_root()
111 {
112 if test $(id -u) != 0 ; then
113 echo -e "\nYou must be root to run `basename $0` with this option."
114 echo -e "Please type 'su' and root password to become super-user.\n"
115 exit 0
116 fi
117 }
119 # Check for a package name on cmdline.
120 check_for_package_on_cmdline()
121 {
122 if [ -z "$PACKAGE" ]; then
123 echo -e "\nPlease specify a package name on the command line.\n"
124 exit 0
125 fi
126 }
128 # Check if the package (*.tazpkg) exist before installing or extracting.
129 check_for_package_file()
130 {
131 if [ ! -f "$PACKAGE_FILE" ]; then
132 echo -e "
133 Unable to find : $PACKAGE_FILE\n"
134 exit 0
135 fi
136 }
138 # Check for the receipt of an installed package.
139 check_for_receipt()
140 {
141 if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
142 echo -e "\nUnable to find the receipt : $INSTALLED/$PACKAGE/receipt\n"
143 exit 0
144 fi
145 }
147 # Check if a package is already installed.
148 check_for_installed_package()
149 {
150 if [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]; then
151 echo -e "
152 $PACKAGE is already installed. You can use the --forced option to force
153 installation or remove it and reinstall.\n"
154 exit 0
155 fi
156 }
158 # Check for packages.list to download and install packages.
159 check_for_packages_list()
160 {
161 if [ ! -f "$LOCALSTATE/packages.list" ]; then
162 echo -e "
163 Unable to find the list : $LOCALSTATE/packages.list\n
164 You must probably run 'tazpkg recharge' as root to get the last list of
165 packages avalaible on the mirror.\n"
166 exit 0
167 fi
168 }
170 # Check for a package in packages.list. Used by get and get-install to grep
171 # package basename.
172 check_for_package_in_list()
173 {
174 if grep -q "^$PACKAGE-[0-9]" $LOCALSTATE/packages.list; then
175 PACKAGE=`grep ^$PACKAGE-[0-9] $LOCALSTATE/packages.list`
176 else
177 echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
178 exit 0
179 fi
180 }
182 # Download a file trying all mirrors
183 download()
184 {
185 for i in $(cat $MIRROR); do
186 wget $i$@
187 done
188 }
190 # Extract a package with cpio and gzip.
191 extract_package()
192 {
193 echo -n "Extracting $PACKAGE..."
194 cpio -id < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
195 gzip -d fs.cpio.gz
196 echo -n "Extracting the pseudo fs... "
197 cpio -id < fs.cpio && rm fs.cpio
198 }
200 # This function install a package in the rootfs.
201 install_package()
202 {
203 ROOT=$1
204 if [ -n "$ROOT" ]; then
205 # get absolute path
206 ROOT=$(cd $ROOT; pwd)
207 fi
208 mkdir -p $TMP_DIR
209 echo ""
210 echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
211 echo "================================================================================"
212 echo -n "Copying $PACKAGE... "
213 cp $PACKAGE_FILE $TMP_DIR
214 status
215 cd $TMP_DIR
216 extract_package
217 SELF_INSTALL=0
218 MODIFY_PACKAGES=""
219 # Include temporary receipt to get the right variables.
220 . $PWD/receipt
221 if [ $SELF_INSTALL -ne 0 -a -n "$ROOT" ]; then
222 echo -n "Checking post install dependencies... "
223 [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]
224 if ! status; then
225 echo "Please run 'tazpkg install $PACKAGE_FILE' and retry."
226 cd .. && rm -rf $TMP_DIR
227 exit 1
228 fi
229 fi
230 # Remember modified packages
231 for i in $MODIFY_PACKAGES; do
232 [ -d $ROOT$INSTALLED/$i ] || continue
233 grep -qs ^$PACKAGE$ $ROOT$INSTALLED/$i/modifiers && continue
234 echo "$PACKAGE" >> $ROOT$INSTALLED/$i/modifiers
235 done
236 # Make the installed package data dir to store
237 # the receipt and the files list.
238 mkdir -p $ROOT$INSTALLED/$PACKAGE
239 cp receipt files.list $ROOT$INSTALLED/$PACKAGE
240 # Copy the description if found.
241 if [ -f "description.txt" ]; then
242 cp description.txt $ROOT$INSTALLED/$PACKAGE
243 fi
244 if grep -q pre_install $ROOT$INSTALLED/$PACKAGE/receipt; then
245 # Execute post install commands.
246 pre_install $ROOT
247 fi
248 echo -n "Installing $PACKAGE... "
249 cp -a fs/* $ROOT/
250 status
251 # Remove the temporary random directory.
252 echo -n "Removing all tmp files... "
253 cd .. && rm -rf $TMP_DIR
254 status
255 if grep -q post_install $ROOT$INSTALLED/$PACKAGE/receipt; then
256 # Execute post install commands.
257 post_install $ROOT
258 fi
259 cd $TOP_DIR
260 echo "================================================================================"
261 echo "$PACKAGE ($VERSION) is installed."
262 echo ""
263 }
265 # Check for missing deps listed in a receipt packages.
266 check_for_deps()
267 {
268 for i in $DEPENDS
269 do
270 if [ ! -d "$INSTALLED/$i" ]; then
271 MISSING_PACKAGE=$i
272 deps=$(($deps+1))
273 fi
274 done
275 if [ ! "$MISSING_PACKAGE" = "" ]; then
276 echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
277 echo "================================================================================"
278 for i in $DEPENDS
279 do
280 if [ ! -d "$INSTALLED/$i" ]; then
281 MISSING_PACKAGE=$i
282 echo "Missing : $MISSING_PACKAGE"
283 fi
284 done
285 echo "================================================================================"
286 echo "$deps missing package(s) to install."
287 fi
288 }
290 # Install all missing deps. First ask user then install all missing deps
291 # from local dir, cdrom, media or from the mirror. In case we want to
292 # install packages from local, we need a packages.list to find the version.
293 install_deps()
294 {
295 echo ""
296 echo -n "Install all missing dependencies (y/N) ? "; read anser
297 if [ "$anser" = "y" ]; then
298 for pkg in $DEPENDS
299 do
300 if [ ! -d "$INSTALLED/$pkg" ]; then
301 # We can install packages from a local dir by greping
302 # the TAZPKG_BASENAME in the local packages.list.
303 if [ -f "$TOP_DIR/packages.list" ]; then
304 echo "Checking if $pkg exist in local list... "
305 TAZPKG_BASENAME=`grep -e ^$pkg-[0-9] $TOP_DIR/packages.list`
306 if [ -f "$TAZPKG_BASENAME.tazpkg" ]; then
307 tazpkg install $TAZPKG_BASENAME.tazpkg
308 fi
309 # Install deps from the mirror.
310 else
311 if [ ! -f "$LOCALSTATE/packages.list" ]; then
312 tazpkg recharge
313 fi
314 tazpkg get-install $pkg
315 fi
316 fi
317 done
318 else
319 echo -e "\nLeaving dependencies for $PACKAGE unsolved."
320 echo -e "The package is installed but will probably not work.\n"
321 fi
322 }
324 ###################
325 # Tazpkg commands #
326 ###################
328 case "$COMMAND" in
329 list)
330 # List all installed packages or a specific category.
331 #
332 if [ "$2" = "category" ]; then
333 echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
334 exit 0
335 fi
336 # Check for an asked category.
337 if [ -n "$2" ]; then
338 ASKED_CATEGORY=$2
339 echo ""
340 echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
341 echo "================================================================================"
342 for pkg in $INSTALLED/*
343 do
344 . $pkg/receipt
345 if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
346 echo -n "$PACKAGE"
347 echo -e "\033[24G $VERSION"
348 packages=$(($packages+1))
349 fi
350 done
351 echo "================================================================================"
352 echo -e "$packages packages installed of category $ASKED_CATEGORY."
353 echo ""
354 else
355 # By default list all packages and version.
356 echo ""
357 echo -e "\033[1mList of all installed packages\033[0m"
358 echo "================================================================================"
359 for pkg in $INSTALLED/*
360 do
361 . $pkg/receipt
362 echo -n "$PACKAGE"
363 echo -en "\033[24G $VERSION"
364 echo -e "\033[42G $CATEGORY"
365 packages=$(($packages+1))
366 done
367 echo "================================================================================"
368 echo "$packages packages installed."
369 echo ""
370 fi
371 ;;
372 list-mirror)
373 # List all available packages on the mirror. Option --diff display
374 # last mirrored packages diff (see recharge).
375 check_for_packages_list
376 if [ "$2" = "--diff" ]; then
377 if [ -f "$LOCALSTATE/packages.diff" ]; then
378 echo ""
379 echo -e "\033[1mMirrored packages diff\033[0m"
380 echo "================================================================================"
381 cat $LOCALSTATE/packages.diff
382 echo "================================================================================"
383 pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
384 echo "$pkgs new packages listed on the mirror."
385 echo ""
386 else
387 echo -e "\nUnable to list anything, no packages.diff found."
388 echo -e "Recharge your current list to creat a first diff.\n"
389 fi
390 else
391 echo ""
392 echo -e "\033[1mList of available packages on the mirror\033[0m"
393 echo "================================================================================"
394 cat $LOCALSTATE/packages.list
395 echo "================================================================================"
396 pkgs=`cat $LOCALSTATE/packages.list | wc -l`
397 echo "$pkgs packages in the last recharged list."
398 echo ""
399 fi
400 ;;
401 list-files)
402 # List files installed with the package.
403 #
404 check_for_package_on_cmdline
405 check_for_receipt
406 echo ""
407 echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
408 echo "================================================================================"
409 cat $INSTALLED/$PACKAGE/files.list | sort
410 echo "================================================================================"
411 files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
412 echo "$files files installed with $PACKAGE."
413 echo ""
414 ;;
415 info)
416 # Informations about package.
417 #
418 check_for_package_on_cmdline
419 check_for_receipt
420 . $INSTALLED/$PACKAGE/receipt
421 echo ""
422 echo -e "\033[1mTazpkg informations\033[0m
423 ================================================================================
424 Package : $PACKAGE
425 Version : $VERSION
426 Category : $CATEGORY
427 Short desc : $SHORT_DESC
428 Maintainer : $MAINTAINER"
429 if [ ! "$DEPENDS" = "" ]; then
430 echo -e "Depends : $DEPENDS"
431 fi
432 if [ ! "$WANTED" = "" ]; then
433 echo -e "Wanted src : $WANTED"
434 fi
435 if [ ! "$WEB_SITE" = "" ]; then
436 echo -e "Web site : $WEB_SITE"
437 fi
438 echo "================================================================================"
439 echo ""
440 ;;
441 desc)
442 # Display package description.txt if available.
443 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
444 echo ""
445 echo -e "\033[1mDescription of :\033[0m $PACKAGE"
446 echo "================================================================================"
447 cat $INSTALLED/$PACKAGE/description.txt
448 echo "================================================================================"
449 echo ""
450 else
451 echo -e "\nSorry, no description available for this package.\n"
452 fi
453 ;;
454 search)
455 # Search for a package by pattern or name.
456 #
457 if [ -z "$2" ]; then
458 echo -e "\nPlease specify a pattern or a package name to search."
459 echo -e "Example : 'tazpkg search paint'. \n"
460 exit 0
461 fi
462 echo ""
463 echo -e "\033[1mSearch result for :\033[0m $2"
464 echo ""
465 echo "Installed packages"
466 echo "================================================================================"
467 list=`ls -1 $INSTALLED | grep $2`
468 for pkg in $list
469 do
470 . $INSTALLED/$pkg/receipt
471 echo -n "$PACKAGE "
472 echo -en "\033[24G $VERSION"
473 echo -e "\033[42G $CATEGORY"
474 packages=$(($packages+1))
475 done
476 # Set correct ending messages.
477 if [ "$packages" = "" ]; then
478 echo "0 installed packages found for : $2"
479 echo ""
480 else
481 echo "================================================================================"
482 echo "$packages installed package(s) found for : $2"
483 echo ""
484 fi
485 echo "Available packages"
486 echo "================================================================================"
487 if [ -f "$LOCALSTATE/packages.list" ]; then
488 cat $LOCALSTATE/packages.list | grep $2
489 packages=`cat $LOCALSTATE/packages.list | grep $2 | wc -l`
490 else
491 echo -e "
492 No 'packages.list' found to check for mirrored packages. For more results,
493 please run once 'tazpkg recharge' as root before searching.\n"
494 fi
495 if [ "$packages" = "0" ]; then
496 echo "0 available packages found for : $2"
497 echo ""
498 else
499 echo "================================================================================"
500 echo "$packages available package(s) found for : $2"
501 echo ""
502 fi
503 ;;
504 search-file)
505 # Search for a file by pattern or name in all files.list.
506 #
507 if [ -z "$2" ]; then
508 echo -e "\nPlease specify a pattern or a file name to search."
509 echo -e "Example : 'tazpkg search-file libnss'. \n"
510 exit 0
511 fi
512 echo ""
513 echo -e "\033[1mSearch result for file :\033[0m $2"
514 echo "================================================================================"
515 # Check all pkg files.list in search match with specify the package
516 # name and the full path to the file(s).
517 for pkg in $INSTALLED/*
518 do
519 if grep -q $2 $pkg/files.list; then
520 . $pkg/receipt
521 echo ""
522 echo -e "\033[1mPackage $PACKAGE :\033[0m"
523 grep $2 $pkg/files.list
524 files=`grep $2 $pkg/files.list | wc -l`
525 match=$(($match+$files))
526 fi
527 done
528 if [ "$match" = "" ]; then
529 echo "0 file found for : $2"
530 echo ""
531 else
532 echo ""
533 echo "================================================================================"
534 echo "$match file(s) found for : $2"
535 echo ""
536 fi
537 ;;
538 install)
539 # Install .tazpkg packages.
540 #
541 check_root
542 check_for_package_on_cmdline
543 check_for_package_file
544 # Check if forced install.
545 DO_CHECK="yes"
546 while [ -n "$3" ]; do
547 case "$3" in
548 --forced)
549 DO_CHECK="no"
550 ;;
551 --root=*)
552 install_package ${3#--root=}
553 exit $?
554 ;;
555 *) shift 2
556 echo -e "\nUnknown option $*.\n"
557 exit 1
558 ;;
559 esac
560 shift
561 done
562 if [ "$DO_CHECK" = "yes" ]; then
563 check_for_installed_package
564 fi
565 install_package
566 # Resolv package deps.
567 check_for_deps
568 if [ ! "$MISSING_PACKAGE" = "" ]; then
569 install_deps
570 fi
571 ;;
572 install-list)
573 # Install a set of packages from a list.
574 #
575 check_root
576 if [ -z "$2" ]; then
577 echo -e "
578 Please change directory (cd) to the packages repository, and specify the
579 list of packages to install. Example : tazpkg install-list packages.list\n"
580 exit 0
581 fi
582 # Check if the packages list exist.
583 if [ ! -f "$2" ]; then
584 echo "Unable to find : $2"
585 exit 0
586 else
587 LIST=`cat $2`
588 fi
589 # Install all packages.
590 for pkg in $LIST
591 do
592 if [ "$3" = "--forced" ]; then
593 tazpkg install $pkg --forced
594 else
595 tazpkg install $pkg
596 fi
597 done
598 ;;
599 remove)
600 # Remove packages.
601 #
602 check_root
603 check_for_package_on_cmdline
604 if [ ! -d "$INSTALLED/$PACKAGE" ]; then
605 echo -e "\n$PACKAGE is not installed.\n"
606 exit 0
607 else
608 . $INSTALLED/$PACKAGE/receipt
609 fi
610 echo ""
611 echo "Remove $PACKAGE ($VERSION) ?"
612 echo -n "Please confirm uninstallation (y/N) : "; read anser
613 if [ "$anser" = "y" ]; then
614 echo ""
615 echo -e "\033[1mRemoving :\033[0m $PACKAGE"
616 echo "================================================================================"
617 echo -n "Removing all files installed..."
618 for file in `cat $INSTALLED/$PACKAGE/files.list`
619 do
620 rm -f $file
621 done
622 status
623 # Remove package receipt.
624 echo -n "Removing package receipt..."
625 rm -rf $INSTALLED/$PACKAGE
626 status
627 else
628 echo ""
629 echo "Uninstallation of $PACKAGE cancelled."
630 fi
631 echo ""
632 ;;
633 extract)
634 # Extract .tazpkg cpio archive into a directory.
635 #
636 check_for_package_on_cmdline
637 check_for_package_file
638 echo ""
639 echo -e "\033[1mExtracting :\033[0m $PACKAGE"
640 echo "================================================================================"
641 # If any directory destination is found on the cmdline
642 # we creat one in the current dir using the package name.
643 if [ -n "$TARGET_DIR" ]; then
644 DESTDIR=$TARGET_DIR/$PACKAGE
645 else
646 DESTDIR=$PACKAGE
647 fi
648 mkdir -p $DESTDIR
649 echo -n "Copying original package..."
650 cp $PACKAGE_FILE $DESTDIR
651 status
652 cd $DESTDIR
653 extract_package
654 echo "================================================================================"
655 echo "$PACKAGE is extracted to : $DESTDIR"
656 echo ""
657 ;;
658 repack)
659 # Creat SliTaz package archive from an installed package.
660 #
661 check_for_package_on_cmdline
662 check_for_receipt
663 eval $(grep ^VERSION= $INSTALLED/$PACKAGE/receipt)
664 echo ""
665 echo -e "\033[1mRepacking :\033[0m $PACKAGE-$VERSION.tazpkg"
666 echo "================================================================================"
667 if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
668 echo "Can't repack, $PACKAGE files have been modified by:"
669 for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
670 echo " $i"
671 done
672 exit 1
673 fi
674 MISSING=""
675 for i in $(sed 's,^fs,,g' < $INSTALLED/$PACKAGE/files.list); do
676 [ -e "$i" ] && continue
677 [ -L "$i" ] || MISSING="$MISSING $i"
678 done
679 if [ -n "$MISSING" ]; then
680 echo "Can't repack, the following files are lost:"
681 for i in $MISSING; do
682 echo " $i"
683 done
684 exit 1
685 fi
686 HERE=`pwd`
687 FILES="receipt\nfiles.list\nfs.cpio.gz"
688 mkdir -p $TMP_DIR
689 cd $TMP_DIR
690 cp $INSTALLED/$PACKAGE/files.list .
691 cp $INSTALLED/$PACKAGE/receipt .
692 if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
693 cp $INSTALLED/$PACKAGE/description.txt .
694 FILES="${FILES}\ndescription.txt"
695 fi
696 cpio -pd fs < files.list 2> /dev/null
697 . ./receipt
698 src=$TMP_DIR/nowhere
699 _pkg=$TMP_DIR/nowhere
700 fs=fs
701 # go on if errors and catch exit
702 ( set +e ; genpkg_rules > /dev/null 2>&1 )
703 cd $TMP_DIR
704 find fs | cpio -o -H newc 2> /dev/null | gzip -9 > fs.cpio.gz
705 echo -e "$FILES" | cpio -o -H newc > \
706 $HERE/$PACKAGE-$VERSION.tazpkg 2> /dev/null
707 cd $HERE
708 \rm -R $TMP_DIR
709 echo "Package $PACKAGE repacked successfully."
710 echo "Size : `du -sh $PACKAGE-$VERSION.tazpkg`"
711 echo ""
712 ;;
713 pack)
714 # Creat SliTaz package archive using cpio and gzip.
715 #
716 check_for_package_on_cmdline
717 cd $PACKAGE
718 if [ ! -f "receipt" ]; then
719 echo "Receipt is missing. Please read the documentation."
720 exit 0
721 else
722 echo ""
723 echo -e "\033[1mPacking :\033[0m $PACKAGE"
724 echo "================================================================================"
725 # Creat files.list with redirecting find outpout.
726 echo -n "Creating the list of files..." && cd fs
727 find . -type f -print > ../files.list
728 find . -type l -print >> ../files.list
729 cd .. && sed -i s/'^.'/''/ files.list
730 status
731 # Build cpio archives.
732 echo -n "Compressing the fs... "
733 find fs -print | cpio -o -H newc > fs.cpio
734 gzip fs.cpio && rm -rf fs
735 echo -n "Creating full cpio archive... "
736 find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
737 echo -n "Restoring original package tree... "
738 gzip -d fs.cpio.gz && cpio -id < fs.cpio
739 rm fs.cpio && cd ..
740 echo "================================================================================"
741 echo "Package $PACKAGE compressed successfully."
742 echo "Size : `du -sh $PACKAGE.tazpkg`"
743 echo ""
744 fi
745 ;;
746 recharge)
747 # Recharge packages.list from a mirror.
748 #
749 check_root
750 cd $LOCALSTATE
751 echo ""
752 if [ -f "$LOCALSTATE/packages.list" ]; then
753 echo -n "Creating backup of the last packages list..."
754 mv -f packages.list packages.list.bak
755 status
756 fi
757 download packages.list
758 if [ -f "$LOCALSTATE/packages.list.bak" ]; then
759 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
760 sed -i s/+// packages.diff
761 echo ""
762 echo -e "\033[1mMirrored packages diff\033[0m"
763 echo "================================================================================"
764 cat packages.diff
765 if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
766 echo "================================================================================"
767 echo "`cat packages.diff | wc -l` new packages on the mirror."
768 echo ""
769 else
770 echo "`cat packages.diff | wc -l` new packages on the mirror."
771 echo ""
772 fi
773 else
774 echo -e "
775 ================================================================================
776 Last packages.list is ready to use. Note that next time you recharge the list,
777 a list of differencies will be displayed to show new and upgradable packages.\n"
778 fi
779 ;;
780 upgrade)
781 # Upgrade all installed packages with the new version from the mirror.
782 #
783 check_root
784 check_for_packages_list
785 cd $LOCALSTATE
786 # Touch the blocked pkgs list to avoid errors and remove any old
787 # upgrade list.
788 touch blocked-packages.list
789 rm -f upradable-packages.list
790 echo ""
791 echo -e "\033[1mAvalaible upgrade\033[0m"
792 echo "================================================================================"
793 for pkg in $INSTALLED/*
794 do
795 . $pkg/receipt
796 # Skip specified pkgs listed in $LOCALSTATE/blocked-packages.list
797 if grep -q "^$PACKAGE" $BLOCKED; then
798 blocked=$(($blocked+1))
799 else
800 # Check if the installed package is in the current list (other
801 # mirror or local).
802 if grep -q "^$PACKAGE-[0-9]" packages.list; then
803 # Set new kg and version for futur comparaison
804 NEW_PACKAGE=`grep ^$PACKAGE-[0-9] packages.list`
805 NEW_VERSION=`echo $NEW_PACKAGE | sed s/$PACKAGE-/''/`
806 # Compare version. Upgrade are only avalaible for official
807 # packages, so we control de mirror and it should be ok if
808 # we just check for egality.
809 if [ "$VERSION" != "$NEW_VERSION" ]; then
810 # Version seems different. Check for major, minor or
811 # revision
812 PKG_MAJOR=`echo $VERSION | cut -f1 -d"."`
813 NEW_MAJOR=`echo $NEW_VERSION | cut -f1 -d"."`
814 PKG_MINOR=`echo $VERSION | cut -f2 -d"."`
815 NEW_MINOR=`echo $NEW_VERSION | cut -f2 -d"."`
816 # Major
817 if [ "$NEW_MAJOR" -gt "$PKG_MAJOR" ]; then
818 RELEASE=major
819 fi
820 if [ "$NEW_MAJOR" -lt "$PKG_MAJOR" ]; then
821 RELEASE=$WARNING
822 FIXE=yes
823 fi
824 # Minor
825 if [ "$NEW_MINOR" -gt "$PKG_MINOR" ]; then
826 RELEASE=minor
827 fi
828 if [ "$NEW_MINOR" -lt "$PKG_MINOR" ]; then
829 RELEASE=$WARNING
830 FIXE=yes
831 fi
832 # Default to revision.
833 if [ -z $RELEASE ]; then
834 RELEASE=revision
835 fi
836 echo -n "$PACKAGE"
837 echo -en "\033[24G $VERSION"
838 echo -en "\033[38G --->"
839 echo -en "\033[48G $NEW_VERSION"
840 echo -en "\033[60G $CATEGORY"
841 echo -e "\033[72G $RELEASE"
842 up=$(($up+1))
843 echo "$PACKAGE" >> upradable-packages.list
844 unset RELEASE
845 fi
846 packages=$(($packages+1))
847 fi
848 fi
849 done
850 rm -f $tmpfile
851 if [ ! "$up" = "" ]; then
852 echo "================================================================================"
853 echo "$packages installed and listed packages to consider, $up to upgrade, $blocked blocked."
854 echo ""
855 else
856 echo "$packages installed and listed packages to consider, 0 to upgrade, $blocked blocked."
857 echo ""
858 exit 0
859 fi
860 # What to do if major or minor version is smaller.
861 if [ "$FIXE" == "yes" ]; then
862 echo -e "$WARNING ---> Installed package seems more recent than the mirrored one."
863 echo "You can block packages using the command : 'tazpkg block package'"
864 echo "Or upgrade package at you own risks."
865 echo ""
866 fi
867 # Ask for upgrade, it can be done an other time.
868 echo -n "Upgrade now (y/N) ? "; read anser
869 if [ ! "$anser" = "y" ]; then
870 echo -e "\nExiting. No package upgraded.\n"
871 exit 0
872 fi
873 # If anser is yes (y). Install all new version.
874 for pkg in `cat upradable-packages.list`
875 do
876 tazpkg get-install $pkg --forced
877 done
878 ;;
879 block)
880 # Add a pkg name to the list of blocked packages.
881 #
882 check_root
883 check_for_package_on_cmdline
884 echo ""
885 if grep -q "^$PACKAGE" $BLOCKED; then
886 echo "$PACKAGE is already in the blocked packages list."
887 echo ""
888 exit 0
889 else
890 echo -n "Add $PACKAGE to : $BLOCKED..."
891 echo $PACKAGE >> $BLOCKED
892 status
893 fi
894 echo ""
895 ;;
896 unblock)
897 # Remove a pkg name to the list of blocked packages.
898 #
899 check_root
900 check_for_package_on_cmdline
901 echo ""
902 if grep -q "^$PACKAGE" $BLOCKED; then
903 echo -n "Removing $PACKAGE from : $BLOCKED..."
904 sed -i s/$PACKAGE/''/ $BLOCKED
905 sed -i '/^$/d' $BLOCKED
906 status
907 else
908 echo "$PACKAGE is not in the blocked packages list."
909 echo ""
910 exit 0
911 fi
912 echo ""
913 ;;
914 get)
915 # Downlowd a package with wget.
916 #
917 check_for_package_on_cmdline
918 check_for_packages_list
919 check_for_package_in_list
920 echo ""
921 download $PACKAGE.tazpkg
922 echo ""
923 ;;
924 get-install)
925 # Download and install a package.
926 #
927 check_root
928 check_for_package_on_cmdline
929 check_for_packages_list
930 check_for_package_in_list
931 # Check if forced install.
932 if [ "$3" = "--forced" ]; then
933 rm -f $CACHE_DIR/$PACKAGE.tazpkg
934 else
935 check_for_installed_package
936 fi
937 cd $CACHE_DIR
938 if [ -f "$PACKAGE.tazpkg" ]; then
939 echo "$PACKAGE already in the cache : $CACHE_DIR"
940 else
941 echo ""
942 download $PACKAGE.tazpkg
943 fi
944 PACKAGE_FILE=$CACHE_DIR/$PACKAGE.tazpkg
945 install_package
946 check_for_deps
947 if [ ! "$MISSING_PACKAGE" = "" ]; then
948 install_deps
949 fi
950 ;;
951 clean-cache)
952 # Remove all downloaded packages.
953 #
954 check_root
955 files=`ls -1 $CACHE_DIR | wc -l`
956 echo ""
957 echo -e "\033[1mCleaning cache directory :\033[0m $CACHE_DIR"
958 echo "================================================================================"
959 rm -rf $CACHE_DIR/*
960 echo "$files file(s) removed from cache."
961 echo ""
962 ;;
963 setup-mirror)
964 # Change mirror URL.
965 #
966 check_root
967 # Backup old list.
968 if [ -f "$LOCALSTATE/mirror" ]; then
969 mv -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
970 fi
971 echo ""
972 echo -e "\033[1mCurrent mirror(s)\033[0m"
973 echo "================================================================================"
974 echo " `cat $MIRROR`"
975 echo "
976 Please enter URL of the new mirror (http or ftp). You must specify the complet
977 address to the directory of the packages and packages.list file."
978 echo ""
979 echo -n "New mirror URL : "
980 read NEW_MIRROR_URL
981 if [ "$NEW_MIRROR_URL" = "" ]; then
982 echo "Nothing as been change."
983 else
984 echo "Setting mirror(s) to : $NEW_MIRROR_URL"
985 echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
986 fi
987 echo ""
988 ;;
989 usage|*)
990 # Print a short help or give usage for an unknow or empty command.
991 #
992 usage
993 ;;
994 esac
996 exit 0