tazpkg rev 6 1.3

Add tazpkg using version 1.3
author Christophe Lincoln <pankso@slitaz.org>
date Mon Nov 26 17:02:19 2007 +0100 (2007-11-26)
parents cc891ba68475
children 94ae98f2771f
files tazpkg
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tazpkg	Mon Nov 26 17:02:19 2007 +0100
     1.3 @@ -0,0 +1,793 @@
     1.4 +#!/bin/sh
     1.5 +# Tazpkg - Tiny autonomus zone packages manager.
     1.6 +#
     1.7 +# This is a lightwight packages manager for *.tazpkg files, all written in
     1.8 +# SHell script. It works well with Busybox ash shell and bash. Tazpkg let you
     1.9 +# list, install, remove, download or get information about a package, you can
    1.10 +# use 'tazpkg usage' to get a list of commands with a short description. Tazpkg
    1.11 +# also relolv dependencies and can upgrade packages from a mirror.
    1.12 +#
    1.13 +# (C) 2007 SliTaz - GNU General Public License v3.
    1.14 +# Author : <pankso@slitaz.org>
    1.15 +#
    1.16 +VERSION=1.3
    1.17 +
    1.18 +####################
    1.19 +# Script variables #
    1.20 +####################
    1.21 +
    1.22 +# Packages categories.
    1.23 +CATEGORIES="base-system base-apps x-window extra"
    1.24 +
    1.25 +# Initialize some variables to use words
    1.26 +# rater than numbers for functions and actions.
    1.27 +COMMAND=$1
    1.28 +PACKAGE=${2%.tazpkg}
    1.29 +TARGET_DIR=$3
    1.30 +TOP_DIR=`pwd`
    1.31 +TMP_DIR=/tmp/tazpkg-$$-$RANDOM
    1.32 +
    1.33 +# Path to tazpkg used dir and configuration files
    1.34 +LOCALSTATE=/var/lib/tazpkg
    1.35 +INSTALLED=$LOCALSTATE/installed
    1.36 +CACHE_DIR=/var/cache/tazpkg
    1.37 +MIRROR=$LOCALSTATE/mirror
    1.38 +PACKAGES_LIST=$LOCALSTATE/packages.list
    1.39 +
    1.40 +
    1.41 +# Check if the directories and files used by Tazpkg
    1.42 +# exists. If not and user is root we creat them.
    1.43 +if test $(id -u) = 0 ; then
    1.44 +	if [ ! -d "$CACHE_DIR" ]; then
    1.45 +		mkdir -p $CACHE_DIR
    1.46 +	fi
    1.47 +	if [ ! -d "$INSTALLED" ]; then
    1.48 +	  mkdir -p $INSTALLED
    1.49 +	fi
    1.50 +	if [ ! -f "$LOCALSTATE/mirror" ]; then
    1.51 +	  echo "$DEFAULT_MIRROR" > $LOCALSTATE/mirror
    1.52 +	fi
    1.53 +fi
    1.54 +
    1.55 +####################
    1.56 +# Script functions #
    1.57 +####################
    1.58 +
    1.59 +# Print the usage.
    1.60 +usage ()
    1.61 +{
    1.62 +	echo -e "SliTaz packages manager - Version: $VERSION\n
    1.63 +\033[1mUsage: \033[0m tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]
    1.64 +\033[1mCommands: \033[0m
    1.65 +  usage         Print this short usage.
    1.66 +  list          List installed packages on the system by category or all.
    1.67 +  list-mirror   List all available packages on the mirror (--diff for new).
    1.68 +  info          Print informations about the package.
    1.69 +  desc          Print description of a package (if it exist).
    1.70 +  list-files    List of files installed with the package.
    1.71 +  search        Search for a package by pattern or name.
    1.72 +  install       Install a local (*.tazpkg) package (--forced to force).
    1.73 +  install-list  Install all packages from a list of packages.
    1.74 +  remove        Remove the specified package and all installed files.
    1.75 +  extract       Extract a (*.tazpkg) package into a directory.
    1.76 +  pack          Pack an unpacked or prepared package tree.
    1.77 +  recharge      Recharge your packages.list from the mirror.
    1.78 +  upgrade       Upgrade all installed and listed packages on the mirror.
    1.79 +  get           Download a package into the current directory.
    1.80 +  get-install   Download and install a package from the mirror.
    1.81 +  clean-cache   Clean all packages downloaded in cache directory.
    1.82 +  setup-mirror  Change the mirror url configuration.\n"
    1.83 +}
    1.84 +
    1.85 +# Status function with color (supported by Ash).
    1.86 +status()
    1.87 +{
    1.88 +	local CHECK=$?
    1.89 +	echo -en "\\033[70G[ "
    1.90 +	if [ $CHECK = 0 ]; then
    1.91 +		echo -en "\\033[1;33mOK"
    1.92 +	else
    1.93 +		echo -en "\\033[1;31mFailed"
    1.94 +	fi
    1.95 +	echo -e "\\033[0;39m ]"
    1.96 +}
    1.97 +
    1.98 +# Check if user is root to install, or remove packages.
    1.99 +check_root()
   1.100 +{
   1.101 +	if test $(id -u) != 0 ; then
   1.102 +		echo -e "\nYou must be root to run `basename $0` with this option."
   1.103 +		echo -e "Please type 'su' and root password to become super-user.\n"
   1.104 +		exit 0
   1.105 +	fi
   1.106 +}
   1.107 +
   1.108 +# Check for a package name on cmdline.
   1.109 +check_for_package_on_cmdline()
   1.110 +{
   1.111 +	if [ -z "$PACKAGE" ]; then
   1.112 +		echo -e "\nPlease specify a package name on the command line.\n"
   1.113 +		exit 0
   1.114 +	fi
   1.115 +}
   1.116 +
   1.117 +# Check if the package (*.tazpkg) is in current dir.
   1.118 +check_for_package_file()
   1.119 +{
   1.120 +	if [ ! -f "$TOP_DIR/$PACKAGE.tazpkg" ]; then
   1.121 +		echo -e "
   1.122 +Unable to find : $TOP_DIR/$PACKAGE.tazpkg
   1.123 +You must be in the package directory to install, extract or pack.\n"
   1.124 +		exit 0
   1.125 +	fi
   1.126 +}
   1.127 +
   1.128 +# Check for the receipt of an installed package.
   1.129 +check_for_receipt()
   1.130 +{
   1.131 +	if [ ! -f "$INSTALLED/$PACKAGE/receipt" ]; then
   1.132 +		echo -e "\nUnable to find the receipt : $INSTALLED/$PACKAGE/receipt\n"
   1.133 +		exit 0
   1.134 +	fi
   1.135 +}
   1.136 +
   1.137 +# Check if a package is already installed.
   1.138 +check_for_installed_package()
   1.139 +{
   1.140 +	if [ -d "$INSTALLED/${PACKAGE%-[0-9]*}" ]; then
   1.141 +		echo -e "
   1.142 +$PACKAGE is already installed. You can use the --forced option to force
   1.143 +installation or remove it and reinstall.\n"
   1.144 +		exit 0
   1.145 +	fi
   1.146 +}
   1.147 +
   1.148 +# Check for packages.list to download and install packages.
   1.149 +check_for_packages_list()
   1.150 +{
   1.151 +	if [ ! -f "$LOCALSTATE/packages.list" ]; then
   1.152 +		echo -e "
   1.153 +Unable to find the list : $LOCALSTATE/packages.list\n
   1.154 +You must probably run 'tazpkg recharge' as root to get the last list of 
   1.155 +packages avalaible on the mirror.\n"
   1.156 +		exit 0
   1.157 +	fi
   1.158 +}
   1.159 +
   1.160 +# Check for a package in packages.list. Used by get and get-install to grep
   1.161 +# package basename.
   1.162 +check_for_package_in_list()
   1.163 +{
   1.164 +	if grep -q "^$PACKAGE-[0-9]" $LOCALSTATE/packages.list; then
   1.165 +		PACKAGE=`grep ^$PACKAGE-[0-9] $LOCALSTATE/packages.list`
   1.166 +	else
   1.167 +		echo -e "\nUnable to find : $PACKAGE in the mirrored packages list.\n"
   1.168 +		exit 0
   1.169 +	fi
   1.170 +}
   1.171 +
   1.172 +# Extract a package with cpio and gzip.
   1.173 +extract_package()
   1.174 +{
   1.175 +	echo -n "Extracting $PACKAGE..."
   1.176 +	cpio -id < $PACKAGE.tazpkg && rm -f $PACKAGE.tazpkg
   1.177 +	gzip -d fs.cpio.gz
   1.178 +	echo -n "Extracting the pseudo fs... "
   1.179 +	cpio -id < fs.cpio && rm fs.cpio
   1.180 +}
   1.181 +
   1.182 +# This function install a package in the rootfs.
   1.183 +install_package()
   1.184 +{
   1.185 +	mkdir -p $TMP_DIR
   1.186 +	echo ""
   1.187 +	echo -e "\033[1mInstallation of :\033[0m $PACKAGE"
   1.188 +	echo "================================================================================"
   1.189 +	echo -n "Copying $PACKAGE... "
   1.190 +	cp $PACKAGE.tazpkg $TMP_DIR
   1.191 +	status
   1.192 +	cd $TMP_DIR
   1.193 +	extract_package
   1.194 +	# Include temporary receipt to get the right variables.
   1.195 +	. $PWD/receipt
   1.196 +	# Make the installed package data dir to store
   1.197 +	# the receipt and the files list.
   1.198 +	mkdir -p $INSTALLED/$PACKAGE
   1.199 +	cp receipt $INSTALLED/$PACKAGE
   1.200 +	# Include installed receipt.
   1.201 +	. $INSTALLED/$PACKAGE/receipt
   1.202 +	# Copy the list of files and the description if found.
   1.203 +	cp files.list $INSTALLED/$PACKAGE
   1.204 +	if [ -f "description.txt" ]; then
   1.205 +		cp description.txt $INSTALLED/$PACKAGE
   1.206 +	fi
   1.207 +	if [ `cat $INSTALLED/$PACKAGE/receipt | grep pre_install` ]; then
   1.208 +		# Execute post install commands.
   1.209 +		pre_install
   1.210 +	fi
   1.211 +	echo -n "Installing $PACKAGE... "
   1.212 +	cp -a fs/* /
   1.213 +	status
   1.214 +	# Remove the temporary random directory.
   1.215 +	echo -n "Removing all tmp files... "
   1.216 +	cd .. && rm -rf $TMP_DIR
   1.217 +	status
   1.218 +	if [ `cat $INSTALLED/$PACKAGE/receipt | grep post_install` ]; then
   1.219 +		# Execute post install commands.
   1.220 +		post_install
   1.221 +	fi
   1.222 +	cd $TOP_DIR
   1.223 +	echo "================================================================================"
   1.224 +	echo "$PACKAGE ($VERSION) is installed."
   1.225 +	echo ""
   1.226 +}
   1.227 +
   1.228 +# Check for missing deps listed in a receipt packages.
   1.229 +check_for_deps()
   1.230 +{
   1.231 +	for i in $DEPENDS
   1.232 +	do
   1.233 +		if [ ! -d "$INSTALLED/$i" ]; then
   1.234 +			MISSING_PACKAGE=$i
   1.235 +			deps=$(($deps+1))
   1.236 +		fi
   1.237 +	done
   1.238 +	if [ ! "$MISSING_PACKAGE" = "" ]; then
   1.239 +		echo -e "\033[1mTracking dependencies for :\033[0m $PACKAGE"
   1.240 +		echo "================================================================================"
   1.241 +		for i in $DEPENDS
   1.242 +		do
   1.243 +			if [ ! -d "$INSTALLED/$i" ]; then
   1.244 +				MISSING_PACKAGE=$i
   1.245 +				echo "Missing : $MISSING_PACKAGE"
   1.246 +			fi
   1.247 +		done
   1.248 +		echo "================================================================================"
   1.249 +		echo "$deps missing package(s) to install."
   1.250 +	fi
   1.251 +}
   1.252 +
   1.253 +# Install all missing deps. First ask user then install all missing deps
   1.254 +# from local dir, cdrom, media or from the mirror. In case we want to
   1.255 +# install packages from local, we need a packages.list to find the version.
   1.256 +install_deps()
   1.257 +{
   1.258 +	echo ""
   1.259 +	echo -n "Install all missing dependencies(y/N) ? "; read anser
   1.260 +	if [ "$anser" = "y" ]; then
   1.261 +		for pkg in $DEPENDS
   1.262 +		do
   1.263 +			if [ ! -d "$INSTALLED/$pkg" ]; then
   1.264 +				# We can install packages from a local dir by greping
   1.265 +				# the TAZPKG_BASENAME in the local packages.list.
   1.266 +				if [ -f "$TOP_DIR/packages.list" ]; then
   1.267 +					echo "Checking if $pkg exist in local list... "
   1.268 +					TAZPKG_BASENAME=`grep -e ^$pkg-[0-9] $TOP_DIR/packages.list`
   1.269 +					if [ -f "$TAZPKG_BASENAME.tazpkg" ]; then
   1.270 +						tazpkg install $TAZPKG_BASENAME.tazpkg
   1.271 +					fi
   1.272 +				# Install deps from the mirror.
   1.273 +				else
   1.274 +					if [ ! -f "$LOCALSTATE/packages.list" ]; then
   1.275 +						tazpkg recharge
   1.276 +					fi
   1.277 +					tazpkg get-install $pkg
   1.278 +				fi
   1.279 +			fi
   1.280 +		done
   1.281 +	else
   1.282 +		echo -e "\nLeaving dependencies for $PACKAGE unsolved."
   1.283 +		echo -e "The package is installed but will probably not work.\n"
   1.284 +	fi
   1.285 +}
   1.286 +
   1.287 +# Sed package version temp file.  we need 123 not 1.2.3 to use -gt. Few
   1.288 +# pacakges also use letters, so a is 1, b is 2, c is 3, etc.
   1.289 +#
   1.290 +sed_tmpfile()
   1.291 +{
   1.292 +	sed -i s/"$PACKAGE-"/''/ $tmpfile
   1.293 +	sed -i s/'\.'//g $tmpfile
   1.294 +	sed -i s/'-'//g $tmpfile
   1.295 +	sed -i s/'pre'// $tmpfile
   1.296 +	sed -i s/'a'/'1'/ $tmpfile
   1.297 +	sed -i s/'b'/'2'/ $tmpfile
   1.298 +	sed -i s/'c'/'3'/ $tmpfile
   1.299 +	sed -i s/'d'/'4'/ $tmpfile
   1.300 +	sed -i s/'e'/'5'/ $tmpfile
   1.301 +}
   1.302 +
   1.303 +###################
   1.304 +# Tazpkg commands #
   1.305 +###################
   1.306 +
   1.307 +case "$COMMAND" in
   1.308 +	list)
   1.309 +		# List all installed packages or a specific category.
   1.310 +		#
   1.311 +		if [ "$2" = "category" ]; then
   1.312 +			echo -e "\033[1m\nPackages categories :\033[0m $CATEGORIES\n"
   1.313 +			exit 0
   1.314 +		fi
   1.315 +		# Check for an asked category.
   1.316 +		if [ -n "$2" ]; then
   1.317 +			ASKED_CATEGORY=$2
   1.318 +			echo ""
   1.319 +			echo -e "\033[1mInstalled packages of category :\033[0m $ASKED_CATEGORY"
   1.320 +			echo "================================================================================"
   1.321 +			for pkg in $INSTALLED/*
   1.322 +			do
   1.323 +				. $pkg/receipt
   1.324 +				if [ "$CATEGORY" == "$ASKED_CATEGORY" ]; then
   1.325 +					echo -n "$PACKAGE"
   1.326 +					echo -e "\033[24G $VERSION"
   1.327 +					packages=$(($packages+1))
   1.328 +				fi
   1.329 +			done
   1.330 +			echo "================================================================================"
   1.331 +			echo -e "$packages packages installed of category $ASKED_CATEGORY."
   1.332 +			echo ""
   1.333 +		else
   1.334 +			# By default list all packages and version.
   1.335 +			echo ""
   1.336 +			echo -e "\033[1mList of all installed packages\033[0m"
   1.337 +			echo "================================================================================"
   1.338 +			for pkg in $INSTALLED/*
   1.339 +			do
   1.340 +				. $pkg/receipt
   1.341 +				echo -n "$PACKAGE"
   1.342 +				echo -en "\033[24G $VERSION"
   1.343 +				echo -e "\033[42G $CATEGORY"
   1.344 +				packages=$(($packages+1))
   1.345 +			done
   1.346 +			echo "================================================================================"
   1.347 +			echo "$packages packages installed."
   1.348 +			echo ""
   1.349 +		fi
   1.350 +		;;
   1.351 +	list-mirror)
   1.352 +		# List all available packages on the mirror. Option --diff display
   1.353 +		# last mirrored packages diff (see recharge).
   1.354 +		check_for_packages_list
   1.355 +		if [ "$2" = "--diff" ]; then
   1.356 +			if [ -f "$LOCALSTATE/packages.diff" ]; then
   1.357 +				echo ""
   1.358 +				echo -e "\033[1mMirrored packages diff\033[0m"
   1.359 +				echo "================================================================================"
   1.360 +				cat $LOCALSTATE/packages.diff
   1.361 +				echo "================================================================================"
   1.362 +				pkgs=`cat $LOCALSTATE/packages.diff | wc -l`
   1.363 +				echo "$pkgs new packages listed on the mirror."
   1.364 +				echo ""
   1.365 +			else
   1.366 +				 echo -e "\nUnable to list anything, no packages.diff found."
   1.367 +				 echo -e "Recharge your current list to creat a first diff.\n"
   1.368 +			fi	
   1.369 +		else
   1.370 +			echo ""
   1.371 +			echo -e "\033[1mList of available packages on the mirror\033[0m"
   1.372 +			echo "================================================================================"
   1.373 +			cat $LOCALSTATE/packages.list
   1.374 +			echo "================================================================================"
   1.375 +			pkgs=`cat $LOCALSTATE/packages.list | wc -l`
   1.376 +			echo "$pkgs packages in the last recharged list."
   1.377 +			echo ""
   1.378 +		fi
   1.379 +		;;
   1.380 +	list-files)
   1.381 +		# List files installed with the package.
   1.382 +		#
   1.383 +		check_for_package_on_cmdline
   1.384 +		check_for_receipt
   1.385 +		echo ""
   1.386 +		echo -e "\033[1mInstalled files with :\033[0m $PACKAGE"
   1.387 +		echo "================================================================================"
   1.388 +		cat $INSTALLED/$PACKAGE/files.list | sort
   1.389 +		echo "================================================================================"
   1.390 +		files=`cat $INSTALLED/$PACKAGE/files.list | wc -l`
   1.391 +		echo "$files files installed with $PACKAGE."
   1.392 +		echo ""
   1.393 +		;;
   1.394 +	info)
   1.395 +		# Informations about package.
   1.396 +		#
   1.397 +		check_for_package_on_cmdline
   1.398 +		check_for_receipt
   1.399 +		. $INSTALLED/$PACKAGE/receipt
   1.400 +		echo ""
   1.401 +		echo -e "\033[1mTazpkg informations\033[0m
   1.402 +================================================================================
   1.403 +Package    : $PACKAGE
   1.404 +Version    : $VERSION
   1.405 +Category   : $CATEGORY
   1.406 +Short desc : $SHORT_DESC
   1.407 +Maintainer : $MAINTAINER"
   1.408 +		if [ ! "$DEPENDS" = "" ]; then
   1.409 +			echo -e "Depends    : $DEPENDS"
   1.410 +		fi
   1.411 +		if [ ! "$WANTED" = "" ]; then
   1.412 +			echo -e "Wanted src : $WANTED"
   1.413 +		fi
   1.414 +		if [ ! "$WEB_SITE" = "" ]; then
   1.415 +			echo -e "Web site   : $WEB_SITE"
   1.416 +		fi
   1.417 +		echo "================================================================================"
   1.418 +		echo ""
   1.419 +		;;
   1.420 +	desc)
   1.421 +		# Display package description.txt if available.
   1.422 +		if [ -f "$INSTALLED/$PACKAGE/description.txt" ]; then
   1.423 +			echo ""
   1.424 +			echo -e "\033[1mDescription of :\033[0m $PACKAGE"
   1.425 +			echo "================================================================================"
   1.426 +			cat $INSTALLED/$PACKAGE/description.txt
   1.427 +			echo "================================================================================"
   1.428 +			echo ""
   1.429 +		else
   1.430 +			echo -e "\nSorry, no description available for this package.\n"
   1.431 +		fi
   1.432 +		;;
   1.433 +	search)
   1.434 +		# Search for a package by pattern or name.
   1.435 +		#
   1.436 +		if [ -z "$2" ]; then
   1.437 +			echo -e "\nPlease specify a pattern or a package name to search."
   1.438 +			echo -e "Example : 'tazpkg search paint'. \n"
   1.439 +			exit 0
   1.440 +		fi
   1.441 +		echo ""
   1.442 +		echo -e "\033[1mSearch result for :\033[0m $2"
   1.443 +		echo ""
   1.444 +		echo "Installed packages"
   1.445 +		echo "================================================================================"
   1.446 +		list=`ls -1 $INSTALLED | grep $2`
   1.447 +		for pkg in $list
   1.448 +		do
   1.449 +			. $INSTALLED/$pkg/receipt
   1.450 +			echo -n "$PACKAGE "
   1.451 +			echo -en "\033[24G $VERSION"
   1.452 +			echo -e "\033[42G $CATEGORY"
   1.453 +			packages=$(($packages+1))
   1.454 +		done
   1.455 +		if [ "$packages" = "" ]; then
   1.456 +			echo "0 installed packages found for : $2"
   1.457 +			echo ""
   1.458 +		else
   1.459 +			echo "================================================================================"
   1.460 +			echo "$packages installed packages found for : $2"
   1.461 +			echo ""
   1.462 +		fi
   1.463 +		echo "Available packages"
   1.464 +		echo "================================================================================"
   1.465 +		if [ -f "$LOCALSTATE/packages.list" ]; then
   1.466 +			cat $LOCALSTATE/packages.list | grep $2
   1.467 +		else
   1.468 +			echo -e "
   1.469 +No 'packages.list' found to check for mirrored packages. For more results,
   1.470 +please run once 'tazpkg recharge' as root before searching.\n"
   1.471 +		fi
   1.472 +		echo "================================================================================"
   1.473 +		packages=`cat $LOCALSTATE/packages.list | grep $2 | wc -l`
   1.474 +		echo "$packages avalaible on the mirror."
   1.475 +		echo ""
   1.476 +		;;
   1.477 +	install)
   1.478 +		# Install .tazpkg packages.
   1.479 +		#
   1.480 +		check_root
   1.481 +		check_for_package_on_cmdline
   1.482 +		check_for_package_file
   1.483 +		# Check if forced install.
   1.484 +		if [ "$3" = "--forced" ]; then
   1.485 +			continue
   1.486 +		else
   1.487 +			check_for_installed_package
   1.488 +		fi
   1.489 +		install_package
   1.490 +		# Resolv package deps.
   1.491 +		check_for_deps
   1.492 +		if [ ! "$MISSING_PACKAGE" = "" ]; then
   1.493 +			install_deps
   1.494 +		fi
   1.495 +		;;
   1.496 +	install-list)
   1.497 +		# Install a set of packages from a list.
   1.498 +		#
   1.499 +		check_root
   1.500 +		if [ -z "$2" ]; then
   1.501 +			echo -e "
   1.502 +Please change directory (cd) to the packages repository, and specify the
   1.503 +list of packages to install. Example : tazpkg install-list packages.list\n"
   1.504 +			exit 0
   1.505 +		fi
   1.506 +		# Check if the packages list exist.
   1.507 +		if [ ! -f "$2" ]; then
   1.508 +			echo "Unable to find : $2"
   1.509 +			exit 0
   1.510 +		else
   1.511 +			LIST=`cat $2`
   1.512 +		fi
   1.513 +		# Install all packages.
   1.514 +		for pkg in $LIST
   1.515 +		do
   1.516 +			if [ "$3" = "--forced" ]; then
   1.517 +				tazpkg install $pkg --forced
   1.518 +			else
   1.519 +				tazpkg install $pkg
   1.520 +			fi
   1.521 +		done
   1.522 +		;;
   1.523 +	remove)
   1.524 +		# Remove packages.
   1.525 +		#
   1.526 +		check_root
   1.527 +		check_for_package_on_cmdline
   1.528 +		if [ ! -d "$INSTALLED/$PACKAGE" ]; then
   1.529 +			echo -e "\n$PACKAGE is not installed.\n"
   1.530 +			exit 0
   1.531 +		else
   1.532 +			. $INSTALLED/$PACKAGE/receipt
   1.533 +		fi
   1.534 +		echo ""
   1.535 +		echo "Remove $PACKAGE ($VERSION) ?"
   1.536 +		echo -n "Please confirm uninstallation (y/N) : "; read anser
   1.537 +		if [ "$anser" = "y" ]; then
   1.538 +			echo ""
   1.539 +			echo -e "\033[1mRemoving :\033[0m $PACKAGE"
   1.540 +			echo "================================================================================"
   1.541 +			echo -n "Removing all files installed..."
   1.542 +			for file in `cat $INSTALLED/$PACKAGE/files.list`
   1.543 +			do
   1.544 +				rm -f $file
   1.545 +			done
   1.546 +			status
   1.547 +			# Remove package receipt.
   1.548 +			echo -n "Removing package receipt..."
   1.549 +			rm -rf $INSTALLED/$PACKAGE
   1.550 +			status
   1.551 +		else
   1.552 +			echo ""
   1.553 +			echo "Uninstallation of $PACKAGE cancelled."
   1.554 +		fi
   1.555 +		echo ""
   1.556 +		;;
   1.557 +	extract)
   1.558 +		# Extract .tazpkg cpio archive into a directory.
   1.559 +		#
   1.560 +		check_for_package_on_cmdline
   1.561 +		check_for_package_file
   1.562 +		echo ""
   1.563 +		echo -e "\033[1mExtracting :\033[0m $PACKAGE"
   1.564 +		echo "================================================================================"
   1.565 +		# If any directory destination is found on the cmdline
   1.566 +		# we creat one in the current dir using the package name.
   1.567 +		if [ -n "$TARGET_DIR" ]; then
   1.568 +			DESTDIR=$TARGET_DIR/$PACKAGE
   1.569 +		else
   1.570 +			DESTDIR=$PACKAGE
   1.571 +		fi
   1.572 +		mkdir -p $DESTDIR
   1.573 +		echo -n "Copying original package..."
   1.574 +		cp $PACKAGE.tazpkg $DESTDIR
   1.575 +		status
   1.576 +		cd $DESTDIR
   1.577 +		extract_package
   1.578 +		echo "================================================================================"
   1.579 +		echo "$PACKAGE is extracted to : $DESTDIR"
   1.580 +		echo ""
   1.581 +		;;
   1.582 +	pack)
   1.583 +		# Creat SliTaz package archive using cpio and gzip.
   1.584 +		#
   1.585 +		check_for_package_on_cmdline
   1.586 +		cd $PACKAGE
   1.587 +		if [ ! -f "receipt" ]; then
   1.588 +			echo "Receipt is missing. Please read the documentation."
   1.589 +			exit 0
   1.590 +		else
   1.591 +			echo ""
   1.592 +			echo -e "\033[1mPacking :\033[0m $PACKAGE"
   1.593 +			echo "================================================================================"
   1.594 +			# Creat files.list with redirecting find outpout.
   1.595 +			echo -n "Creating the list of files..." && cd fs
   1.596 +			find . -type f -print > ../files.list
   1.597 +			find . -type l -print >> ../files.list
   1.598 +			cd .. && sed -i s/'^.'/''/ files.list
   1.599 +			status
   1.600 +			# Build cpio archives.
   1.601 +			echo -n "Compressing the fs... "
   1.602 +			find fs -print | cpio -o -H newc > fs.cpio
   1.603 +			gzip fs.cpio && rm -rf fs
   1.604 +			echo -n "Creating full cpio archive... "
   1.605 +			find . -print | cpio -o -H newc > ../$PACKAGE.tazpkg
   1.606 +			echo -n "Restoring original package tree... "
   1.607 +			gzip -d fs.cpio.gz && cpio -id < fs.cpio
   1.608 +			rm fs.cpio && cd ..
   1.609 +			echo "================================================================================"
   1.610 +			echo "Package $PACKAGE compressed succefully."
   1.611 +			echo "Size : `du -sh $PACKAGE.tazpkg`"
   1.612 +			echo ""
   1.613 +		fi
   1.614 +		;;
   1.615 +	recharge)
   1.616 +		# Recharge packages.list from a mirror.
   1.617 +		#
   1.618 +		check_root
   1.619 +		cd $LOCALSTATE
   1.620 +		echo ""
   1.621 +		if [ -f "$LOCALSTATE/packages.list" ]; then
   1.622 +			echo -n "Creating backup of the last packages list..."
   1.623 +			mv -f packages.list packages.list.bak
   1.624 +			status
   1.625 +		fi
   1.626 +		wget `cat $MIRROR`/packages.list
   1.627 +		if [ -f "$LOCALSTATE/packages.list.bak" ]; then
   1.628 +			diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
   1.629 +			sed -i s/+// packages.diff
   1.630 +			echo ""
   1.631 +			echo -e "\033[1mMirrored packages diff\033[0m"
   1.632 +			echo "================================================================================"
   1.633 +			cat packages.diff
   1.634 +			if [ ! "`cat packages.diff | wc -l`" = 0 ]; then
   1.635 +				echo "================================================================================"
   1.636 +				echo "`cat packages.diff | wc -l` new packages on the mirror."
   1.637 +				echo ""
   1.638 +			else
   1.639 +				echo "`cat packages.diff | wc -l` new packages on the mirror."
   1.640 +				echo ""
   1.641 +			fi
   1.642 +		else
   1.643 +			echo -e "
   1.644 +================================================================================
   1.645 +Last packages.list is ready to use. Note that next time you recharge the list,
   1.646 +a list of differencies will be displayed to show new and upgradable packages.\n"
   1.647 +		fi
   1.648 +		;;
   1.649 +	upgrade)
   1.650 +		# Upgrade all installed packages with the new version from the mirror.
   1.651 +		#
   1.652 +		check_root
   1.653 +		check_for_packages_list
   1.654 +		cd $LOCALSTATE
   1.655 +		rm -f upradable-packages.list
   1.656 +		echo ""
   1.657 +		echo -e "\033[1mAvalaible upgrade\033[0m"
   1.658 +		echo "================================================================================"
   1.659 +		for pkg in $INSTALLED/*
   1.660 +		do
   1.661 +			. $pkg/receipt
   1.662 +			# We need a temp file to sed the package version.
   1.663 +			tmpfile=/tmp/pkg.version
   1.664 +			# Check if the installed package is in the current list (other
   1.665 +			# mirror or local).
   1.666 +			if grep -q "^$PACKAGE-[0-9]" packages.list; then
   1.667 +				newpkg=`grep ^$PACKAGE-[0-9] packages.list`
   1.668 +				# Get last and current version without points using 
   1.669 +				# function sed_tmpfile().
   1.670 +				echo $newpkg > $tmpfile
   1.671 +				sed_tmpfile
   1.672 +				NEW_VERSION=`cat $tmpfile`
   1.673 +				echo $VERSION > $tmpfile
   1.674 +				sed_tmpfile
   1.675 +				CURRENT_VERSION=`cat $tmpfile`
   1.676 +				# Compare version.
   1.677 +				if [ "$NEW_VERSION" -gt "$CURRENT_VERSION" ]; then
   1.678 +					echo $newpkg > $tmpfile
   1.679 +					sed -i s/"$PACKAGE-"/''/ $tmpfile
   1.680 +					newversion=`cat $tmpfile`
   1.681 +					rm -f $tmpfile
   1.682 +					echo -n "$PACKAGE"
   1.683 +					echo -en "\033[24G $VERSION"
   1.684 +					echo -en "\033[38G --->"
   1.685 +					echo -en "\033[48G $newversion"
   1.686 +					echo -e "\033[68G $CATEGORY"
   1.687 +					up=$(($up+1))
   1.688 +					echo "$PACKAGE" >> upradable-packages.list
   1.689 +				fi
   1.690 +				packages=$(($packages+1))
   1.691 +			fi	
   1.692 +		done
   1.693 +		rm -f $tmpfile
   1.694 +		if [ ! "$up" = "" ]; then
   1.695 +			echo "================================================================================"
   1.696 +			echo "$packages installed and listed packages to consider, $up to upgrade."
   1.697 +			echo ""
   1.698 +		else
   1.699 +			echo "$packages installed and listed packages to consider, 0 to upgrade."
   1.700 +			echo ""
   1.701 +			exit 0
   1.702 +		fi
   1.703 +		# Ask for upgrade, it can be done an other time.
   1.704 +		echo -n "Upgrade now (y/N) ? "; read anser
   1.705 +		if [ ! "$anser" = "y" ]; then
   1.706 +			echo -e "\nExiting. No package upgraded.\n"
   1.707 +			exit 0
   1.708 +		fi
   1.709 +		# If anser is yes (y). Install all new version.
   1.710 +		for pkg in `cat upradable-packages.list`
   1.711 +		do
   1.712 +			tazpkg get-install $pkg --forced
   1.713 +		done
   1.714 +		;;
   1.715 +	get)
   1.716 +		# Downlowd a package with wget.
   1.717 +		#
   1.718 +		check_for_package_on_cmdline
   1.719 +		check_for_packages_list
   1.720 +		check_for_package_in_list
   1.721 +		echo ""
   1.722 +		wget `cat $MIRROR`/$PACKAGE.tazpkg
   1.723 +		echo ""
   1.724 +		;;
   1.725 +	get-install)
   1.726 +		# Download and install a package.
   1.727 +		#
   1.728 +		check_root
   1.729 +		check_for_package_on_cmdline
   1.730 +		check_for_packages_list
   1.731 +		check_for_package_in_list
   1.732 +		# Check if forced install.
   1.733 +		if [ "$3" = "--forced" ]; then
   1.734 +			rm -f $CACHE_DIR/$PACKAGE.tazpkg
   1.735 +		else
   1.736 +			check_for_installed_package
   1.737 +		fi
   1.738 +		cd $CACHE_DIR
   1.739 +		if [ -f "$PACKAGE.tazpkg" ]; then
   1.740 +			echo "$PACKAGE already in the cache : $CACHE_DIR"
   1.741 +		else
   1.742 +			echo ""
   1.743 +			wget `cat $MIRROR`/$PACKAGE.tazpkg
   1.744 +		fi
   1.745 +		install_package
   1.746 +		check_for_deps
   1.747 +		if [ ! "$MISSING_PACKAGE" = "" ]; then
   1.748 +			install_deps
   1.749 +		fi
   1.750 +		;;
   1.751 +	clean-cache)
   1.752 +		# Remove all downloaded packages.
   1.753 +		#
   1.754 +		check_root
   1.755 +		files=`ls -1 $CACHE_DIR | wc -l`
   1.756 +		echo ""
   1.757 +		echo -e "\033[1mCleaning cache directory :\033[0m $CACHE_DIR"
   1.758 +		echo "================================================================================"
   1.759 +		rm -rf $CACHE_DIR/*
   1.760 +		echo "$files file(s) removed from cache."
   1.761 +		echo ""
   1.762 +		;;
   1.763 +	setup-mirror)
   1.764 +		# Change mirror URL.
   1.765 +		#
   1.766 +		check_root
   1.767 +		# Backup old list.
   1.768 +		if [ -f "$LOCALSTATE/mirror" ]; then
   1.769 +			mv -f $LOCALSTATE/mirror $LOCALSTATE/mirror.bak
   1.770 +		fi
   1.771 +		echo ""
   1.772 +		echo -e "\033[1mCurrent mirror\033[0m"
   1.773 +		echo "================================================================================"
   1.774 +		echo "  `cat $MIRROR`"
   1.775 +		echo "
   1.776 +Please enter URL of the new mirror (http or ftp). You must specify the complet
   1.777 +address to the directory of the packages and packages.list file."
   1.778 +		echo ""
   1.779 +		echo -n "New mirror URL : "
   1.780 +		read NEW_MIRROR_URL
   1.781 +		if [ "$NEW_MIRROR_URL" = "" ]; then
   1.782 +			echo "Nothing as been change."
   1.783 +		else
   1.784 +			echo "Setting mirror to : $NEW_MIRROR_URL"
   1.785 +			echo "$NEW_MIRROR_URL" > $LOCALSTATE/mirror
   1.786 +		fi
   1.787 +		echo ""
   1.788 +		;;
   1.789 +	usage|*)
   1.790 +		# Print a short help or give usage for an unknow or empty command.
   1.791 +		#
   1.792 +		usage
   1.793 +		;;
   1.794 +esac
   1.795 +
   1.796 +exit 0