spk rev 11

Add: spk-add, spk-archive (both in working condition, but still need lots of cleaning and testing)
author Christian Mesh <meshca@clarkson.edu>
date Fri May 11 21:23:22 2012 -0500 (2012-05-11)
parents 592af8baf056
children 8517989e8588
files doc/libspk.txt lib/libspk.sh spk-add spk-archive
line diff
     1.1 --- a/doc/libspk.txt	Sat May 12 02:38:21 2012 +0200
     1.2 +++ b/doc/libspk.txt	Fri May 11 21:23:22 2012 -0500
     1.3 @@ -15,6 +15,7 @@
     1.4  	count_mirrored
     1.5  	equivalent_pkg
     1.6  	missing_deps
     1.7 +	grepesc
     1.8  OPTIONS
     1.9  
    1.10  AUTHOR
     2.1 --- a/lib/libspk.sh	Sat May 12 02:38:21 2012 +0200
     2.2 +++ b/lib/libspk.sh	Fri May 11 21:23:22 2012 -0500
     2.3 @@ -15,12 +15,13 @@
     2.4  installed="$PKGS_DB/installed"
     2.5  pkgsdesc="$PKGS_DB/packages.desc"
     2.6  pkgsmd5="$PKGS_DB/packages.md5"
     2.7 -blocked="$PKGS_DB/blocked.list"
     2.8 +# ????do we need packages.equiv????
     2.9 +blocked="$PKGS_DB/blocked-packages.list"
    2.10  activity="$PKGS_DB/activity"
    2.11  
    2.12  #
    2.13  # Functions
    2.14 -#
    2.15 +
    2.16  
    2.17  # Display receipt information.
    2.18  # Expects a reciept to be sourced
    2.19 @@ -38,9 +39,9 @@
    2.20  	local dir="$1"
    2.21  	local file="$2"
    2.22  
    2.23 -	pushd "$dir"
    2.24 +	pushd "$dir" > /dev/null
    2.25  	{ cpio --quiet -i receipt > /dev/null 2>&1; } < $file
    2.26 -	popd
    2.27 +	popd > /dev/null
    2.28  }
    2.29  
    2.30  # Used by: list
    2.31 @@ -55,7 +56,52 @@
    2.32  	gettext "Mirrored packages"; echo ": $count"
    2.33  }
    2.34  
    2.35 -# get an already installed package from packages.equiv
    2.36 +is_package_mirrored() {
    2.37 +	local package_name=$1
    2.38 +	local occurance=$(cat $pkgsdesc | grep "$package_name ")
    2.39 +	[ -n "$occurance" ]
    2.40 +}
    2.41 +
    2.42 +# Download a file trying all mirrors
    2.43 +# Parameters: package/file
    2.44 +download() {
    2.45 +	local package=$1
    2.46 +	local mirror="$(cat $mirrorurl)"
    2.47 +	case "$package" in
    2.48 +		*.tazpkg)
    2.49 +			echo "${mirror%/}/$package"
    2.50 +			wget -c ${mirror%/}/$package ;; 
    2.51 +	esac
    2.52 +}
    2.53 +
    2.54 +# Assume package_name is valid
    2.55 +# There may be a more efficient way to do this...
    2.56 +full_package() {
    2.57 +	local package_name=$1
    2.58 +	local occurance=$(cat $pkgsdesc | grep "$package_name ")
    2.59 +	local count=0
    2.60 +	for i in $(echo $occurance | tr "|" "\n"); do
    2.61 +		if [ $count -eq 1 ]; then
    2.62 +			echo $package_name-$i
    2.63 +			return
    2.64 +		fi
    2.65 +		count=$(($count+1))
    2.66 +	done
    2.67 +}
    2.68 +
    2.69 +# Check if a package is already installed.
    2.70 +# Parameters: package
    2.71 +check_for_installed_package() {
    2.72 +	local package_name="$1"
    2.73 +	
    2.74 +	if [ -d "$installed/$package_name" ]; then
    2.75 +		newline
    2.76 +		echo $package_name $(gettext "package is already installed.")
    2.77 +		exit 0
    2.78 +	fi
    2.79 +}
    2.80 +
    2.81 +# get an already installed package from packages.equiv  TODO REDO!
    2.82  equivalent_pkg() {
    2.83  	for i in $(grep -hs "^$1=" $PKGS_DB/packages.equiv \
    2.84  		   $PKGS_DB/undigest/*/packages.equiv | sed "s/^$1=//")
    2.85 @@ -101,9 +147,17 @@
    2.86  			gettext "WARNING Dependency loop between \$package and \$pkg."; newline
    2.87  		fi
    2.88  	done
    2.89 -
    2.90 +	if [ $deps -gt 0 ]; then
    2.91 +		echo $deps $(gettext "missing package(s) to install.")
    2.92 +	fi
    2.93 +	
    2.94  	gettext "\$deps missing package(s) to install."; newline
    2.95  
    2.96  	# Return true if missing deps
    2.97  	[ "$deps" != "0" ]
    2.98  }
    2.99 +
   2.100 +grepesc() {
   2.101 +	sed 's/\[/\\[/g'
   2.102 +}
   2.103 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/spk-add	Fri May 11 21:23:22 2012 -0500
     3.3 @@ -0,0 +1,346 @@
     3.4 +#!/bin/sh
     3.5 +#
     3.6 +# Authors : See the AUTHORS files
     3.7 +
     3.8 +# Set to / for now untill we add installing to chroot support
     3.9 +# Could we update tools so they do not need this?
    3.10 +ROOT=""
    3.11 +TMP_DIR="/tmp/$RANDOM"
    3.12 +
    3.13 +source /usr/lib/slitaz/libspk.sh
    3.14 +
    3.15 +# This function installs a package in the rootfs.
    3.16 +# Parameters: package_name package_file
    3.17 +install_package() {	
    3.18 +	local package_file=$1
    3.19 +	
    3.20 +	# Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
    3.21 +		
    3.22 +	# Create package path early to avoid dependencies loop
    3.23 +	mkdir -p $TMP_DIR
    3.24 +	extract_receipt $TMP_DIR $package_file
    3.25 +	source $TMP_DIR/receipt
    3.26 +	
    3.27 +	local package_name=$PACKAGE
    3.28 +	local package_dir="$installed/$package_name"
    3.29 +	mkdir -p $package_dir
    3.30 +
    3.31 +	# Run pre_depends from receipt if it exists
    3.32 +	if grep -q ^pre_depends $TMP_DIR/receipt; then
    3.33 +		pre_depends $ROOT
    3.34 +	fi
    3.35 +
    3.36 +	# Create modifiers and files.list if they do not exist
    3.37 +#	touch $package_dir/modifiers
    3.38 +#	touch $package_dir/files.list
    3.39 +
    3.40 +	# add package checksum to pkgsmd5
    3.41 +	sed -i "/ $(basename $package_dir)$/d" $pkgsmd5 2> /dev/null
    3.42 +	pushd $(dirname $package_file) > /dev/null
    3.43 +		$CHECKSUM $(basename $package_file) >> $pkgsmd5
    3.44 +	popd > /dev/null
    3.45 +	
    3.46 +	# Resolve package deps.
    3.47 +	if missing_deps $package_name $DEPENDS; then
    3.48 +		install_deps $package_name $DEPENDS
    3.49 +	fi
    3.50 +	
    3.51 +	newline	
    3.52 +	boldify $(gettext "Installation of :") $package_name
    3.53 +	separator
    3.54 +	eval_gettext "Copying \$package_name... "
    3.55 +	cp $package_file $TMP_DIR
    3.56 +	status
    3.57 +	
    3.58 +	# Extract Package
    3.59 +	pushd $TMP_DIR > /dev/null
    3.60 +		rm receipt
    3.61 +		spk-archive extract $package_file
    3.62 +	popd > /dev/null
    3.63 +	
    3.64 +	# Get files to remove if upgrading
    3.65 +	local files_to_remove
    3.66 +	if [ -f $package_dir/files.list ]; then
    3.67 +		for file in $($package_dir/files.list); do
    3.68 +			grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
    3.69 +			local modifiers=$(cat $package_dir/modifiers 2> /dev/null;\
    3.70 +							  fgrep -sl $package_dir */modifiers | cut -d/ -f1)
    3.71 +			for i in modifiers; do
    3.72 +				grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
    3.73 +			done
    3.74 +			files_to_remove="$files_to_remove $file"
    3.75 +		done
    3.76 +	fi
    3.77 +	
    3.78 +	local check=false
    3.79 +	local file_list
    3.80 +	# Create list of all possibly modified files
    3.81 +	for i in $(fgrep -v [ $TMP_DIR/files.list); do
    3.82 +		[ -e "$ROOT$i" ] || continue
    3.83 +		[ -d "$ROOT$i" ] && continue
    3.84 +		file_list="$file_list $i"
    3.85 +		check=true
    3.86 +	done
    3.87 +	
    3.88 +	# Check possibly modified files against other packages file.list
    3.89 +	if $check; then
    3.90 +		for pkg in $INSTALLED/*; do 
    3.91 +		  	[ "$pkg" == "$package_name" ] && continue
    3.92 +		  	[ -s $pkg/files.list ] || continue
    3.93 +		  	
    3.94 +		  	for file in $file_list; do
    3.95 +		  		# $package_name wants to install $file which is already
    3.96 +		  		# Installed from $pkg
    3.97 +				if grep -q ^$file$ $pkg/files.list; then
    3.98 +					# Tell $pkg that $package_name is going to overwrite some of it's files
    3.99 +					if [ -s "$pkg/volatile.cpio.gz" ]; then
   3.100 +						# We can modify backed up files without notice
   3.101 +						zcat $pkg/volatile.cpio.gz | cpio -t --quiet | \
   3.102 +						grep -q "^${file#/}$" && continue
   3.103 +					fi
   3.104 +					echo "$package_name" >> $pkg/modifiers
   3.105 +				fi
   3.106 +			done
   3.107 +		done
   3.108 +	fi
   3.109 +	
   3.110 +	pushd $TMP_DIR > /dev/null
   3.111 +		cp receipt files.list $package_dir
   3.112 +		# Copy the description if found.
   3.113 +		[ -f "description.txt" ] && cp description.txt $package_dir
   3.114 +		
   3.115 +		# Pre install commands.
   3.116 +		if grep -q ^pre_install $package_dir/receipt; then
   3.117 +			pre_install $ROOT
   3.118 +		fi
   3.119 +		
   3.120 +		# Handle Config Files from reciept
   3.121 +		if [ -n "$CONFIG_FILES" ]; then
   3.122 +			pushd $fs > /dev/null
   3.123 +				# save 'official' configuration files
   3.124 +				eval_gettext "Saving configuration files for \$package_name... "
   3.125 +				
   3.126 +				local confs
   3.127 +				for i in $CONFIG_FILES; do
   3.128 +					confs="$confs $(find ${i#/} -type f 2> /dev/null)"
   3.129 +				done
   3.130 +				
   3.131 +				echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz
   3.132 +		
   3.133 +				# keep user configuration files
   3.134 +				for conf_file in $confs; do
   3.135 +					[ -e $conf_file ] || continue
   3.136 +					cp -a $conf_file fs/$conf_file
   3.137 +				done
   3.138 +				status
   3.139 +			popd > /dev/null
   3.140 +		fi
   3.141 +		
   3.142 +		# Merge ROOT_FS with Package FS
   3.143 +		eval_gettext "Installing \$package_name... "
   3.144 +		cp -a fs/* $ROOT/
   3.145 +		status
   3.146 +		
   3.147 +		# Remove old config files
   3.148 +		if [ -n $files_to_remove ]; then
   3.149 +			eval_gettext "Removing old \$package_name... "
   3.150 +			for file in $files_to_remove; do
   3.151 +				remove_with_path $ROOT$file
   3.152 +			done
   3.153 +			status
   3.154 +		fi
   3.155 +	popd > /dev/null
   3.156 +	
   3.157 +	# Remove the temporary directory.
   3.158 +	gettext "Removing all tmp files... "
   3.159 +	rm -rf $TMP_DIR
   3.160 +	status
   3.161 +	
   3.162 +	# Post install commands.
   3.163 +	if grep -q ^post_install $package_dir/receipt; then
   3.164 +		post_install $ROOT
   3.165 +	fi
   3.166 +	
   3.167 + 	# Update-desktop-database if needed.
   3.168 +	if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
   3.169 +		updatedesktopdb=yes
   3.170 +	fi
   3.171 +	# Update-mime-database if needed.
   3.172 +	if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
   3.173 +		updatemimedb=yes
   3.174 +	fi
   3.175 +	# Update-icon-database
   3.176 +	if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
   3.177 +		updateicondb=yes
   3.178 +	fi
   3.179 +	# Compile glib schemas if needed.
   3.180 +	if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
   3.181 +		compile_schemas=yes
   3.182 +	fi
   3.183 +	# Update depmod list
   3.184 +	if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
   3.185 +		updatedepmod=yes
   3.186 +	fi
   3.187 +	
   3.188 +	separator
   3.189 +	eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
   3.190 +	newline
   3.191 +}
   3.192 +
   3.193 +
   3.194 +# Install .tazpkg packages.
   3.195 +# Parameters: package_file
   3.196 +install_pkg() {
   3.197 +	package_file="$1"
   3.198 +	
   3.199 +	check_root
   3.200 +	check_valid_tazpkg $package_file
   3.201 +	
   3.202 +	# Check if forced install.
   3.203 +	if ! [ "$forced" ]; then
   3.204 +		check_for_installed_package $(package_name $package_file)
   3.205 +	fi
   3.206 +	
   3.207 +	install_package $package_file
   3.208 +	
   3.209 +	update_desktop_database
   3.210 +	update_mime_database
   3.211 +	update_icon_database 
   3.212 +	compile_glib_schemas
   3.213 +}
   3.214 +
   3.215 +# Download and install a package. TODO: Handle Undigest Mirrors
   3.216 +# Parameters: package_name
   3.217 +get_install() {
   3.218 +	local package_name="$1"
   3.219 +
   3.220 +	check_root
   3.221 +	
   3.222 +	# Check if get-Package
   3.223 +	if ! is_package_mirrored $package_name; then
   3.224 +		package_name="get-$package_name"
   3.225 +		AUTOEXEC=true
   3.226 +	fi
   3.227 +
   3.228 +	# Check if package is mirrored
   3.229 +	if ! is_package_mirrored $package_name; then
   3.230 +		gettext "Could not find \$package_name in repositories"; newline
   3.231 +		exit 1
   3.232 +	fi
   3.233 +
   3.234 +	# package_full=Package-Version
   3.235 +	local package_full=$(full_package $package_name)
   3.236 +	
   3.237 +	# Check if forced install.
   3.238 +	if ! [ "$forced" ]; then
   3.239 +		check_for_installed_package $package_name
   3.240 +	fi
   3.241 +	
   3.242 +	pushd $CACHE_DIR > /dev/null
   3.243 +		if [ -f "$package_full.tazpkg" ]; then
   3.244 +			eval_gettext "\$package_full is already in the cache : \$CACHE_DIR"; newline
   3.245 +			# Check package download was finished
   3.246 +			if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
   3.247 +				eval_gettext "Continuing \$package_name download"; newline
   3.248 +				download "$package_full.tazpkg"
   3.249 +			fi
   3.250 +			
   3.251 +			# Check that the package has the correct checksum
   3.252 +#			if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \"  $package_full.tazpkg\" $pkgsmd5)" ]; then
   3.253 +#				rm -f $package.tazpkg
   3.254 +#				download "$package_full.tazpkg"
   3.255 +#			fi
   3.256 +		else
   3.257 +			newline 
   3.258 +			download "$package_full.tazpkg"
   3.259 +		fi
   3.260 +	popd > /dev/null
   3.261 +	
   3.262 +	install_package "$CACHE_DIR/$package_full.tazpkg"
   3.263 +	
   3.264 +	[ -n "$AUTOEXEC" ] && $package_name $ROOT 
   3.265 +	update_desktop_database
   3.266 +	update_mime_database
   3.267 +}
   3.268 +
   3.269 +# Install all missing deps. Auto install or ask user then install all missing 
   3.270 +# deps from local dir, cdrom, media or from the mirror. In case we want to
   3.271 +# install packages from local, we need a packages.list to find the version.
   3.272 +# Parameters: package List of deps to install
   3.273 +install_deps() {
   3.274 +	local package=$1
   3.275 +	shift
   3.276 +	local deps="$@"
   3.277 +	
   3.278 +	gettext "Install all missing dependencies? "
   3.279 +	
   3.280 +	# Print Yes/No and get result
   3.281 +	if $AUTO_INSTALL_DEPS || confirm; then
   3.282 +		for pkgorg in $deps; do
   3.283 +			local pkg=$(equivalent_pkg $pkgorg)
   3.284 +			# Check if package is not installed
   3.285 +			if [ ! -d "$installed/$pkg" ]; then
   3.286 +				if [ ! -f "$PKGS_DB/packages.list" ]; then
   3.287 +					tazpkg recharge
   3.288 +				fi
   3.289 +				get-install $pkg
   3.290 +			fi
   3.291 +		done
   3.292 +	else
   3.293 +		newline
   3.294 +		eval_gettext \
   3.295 +"Leaving dependencies for \$package unresolved. The package is installed but
   3.296 +will probably not work."; newline
   3.297 +		newline
   3.298 +	fi
   3.299 +}
   3.300 +
   3.301 +# Check for ELF file
   3.302 +is_elf() {
   3.303 +	[ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
   3.304 +}
   3.305 +
   3.306 +# Print shared library dependencies
   3.307 +ldd() {
   3.308 +	LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
   3.309 +}
   3.310 +
   3.311 +
   3.312 +update_desktop_database() {
   3.313 +	if [ -f $ROOT/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
   3.314 +		chroot "$ROOT/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
   3.315 +	fi
   3.316 +}
   3.317 +
   3.318 +update_mime_database() {
   3.319 +	if [ -f $ROOT/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
   3.320 +		chroot "$ROOT/" /usr/bin/update-mime-database /usr/share/mime
   3.321 +	fi
   3.322 +}
   3.323 +
   3.324 +update_icon_database() {
   3.325 +	if [ -f $ROOT/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
   3.326 +		chroot "$ROOT/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
   3.327 +	fi
   3.328 +}
   3.329 +
   3.330 +compile_glib_schemas() {
   3.331 +	if [ -f $ROOT/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
   3.332 +		chroot "$ROOT/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
   3.333 +	fi
   3.334 +}
   3.335 +
   3.336 +update_kernel_modules() {
   3.337 +	if [ -f $ROOT/sbin/depmod ] && [ -n "$updatedepmod" ]; then
   3.338 +		chroot "$ROOT/" /sbin/depmod -a
   3.339 +	fi
   3.340 +}
   3.341 +
   3.342 +case $1 in
   3.343 +	install|-i)
   3.344 +		install_pkg $2 $3 ;;
   3.345 +	get-install|-gi)
   3.346 +		get_install $2 ;;
   3.347 +	*)
   3.348 +		usage ;;
   3.349 +esac
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/spk-archive	Fri May 11 21:23:22 2012 -0500
     4.3 @@ -0,0 +1,296 @@
     4.4 +#!/bin/sh
     4.5 +#
     4.6 +# Spk-Archive - SliTaz Package Archive Manager
     4.7 +#
     4.8 +#	NOT COMPLETE: Still need to re-write (just what was grabbed from tazpkg)
     4.9 +#	UNSURE: Should Pack and Repack be here?
    4.10 +#
    4.11 +# Authors : See the AUTHORS files
    4.12 +
    4.13 +source /usr/lib/slitaz/libspk.sh
    4.14 +
    4.15 +usage() {
    4.16 +	name=$(basename $0)
    4.17 +	cat << EOT 
    4.18 +
    4.19 +$(boldify $(gettext "Usage:")) $name [command] package
    4.20 +
    4.21 +$(boldify $(gettext "Commands:"))
    4.22 +	pack
    4.23 +	repack [--config]
    4.24 +	extract
    4.25 +	recompress
    4.26 +
    4.27 +$(boldify "$(gettext "Example:")")
    4.28 +  $name extract clex
    4.29 +
    4.30 +EOT
    4.31 +	exit 0
    4.32 +}
    4.33 +
    4.34 +# Extract a package with cpio and gzip/lzma to the current directory.
    4.35 +# Parameters: package_file
    4.36 +extract_package() {
    4.37 +	local package_file=$1
    4.38 +	local package_name=$(package_name $package_file)
    4.39 +	
    4.40 +	eval_gettext "Extracting \$package_name... "
    4.41 +	cpio -idm --quiet < ${package_file##*/} && rm -f ${package_file##*/}
    4.42 +	status
    4.43 +	
    4.44 +	gettext "Extracting the pseudo fs... "
    4.45 +	if [ -f fs.cpio.lzma ]; then
    4.46 +		echo -n "(lzma) "
    4.47 +		unlzma -c fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
    4.48 +	elif [ -f fs.cpio.gz ]; then
    4.49 +		zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
    4.50 +	fi
    4.51 +	status
    4.52 +}
    4.53 +
    4.54 +# Extract .tazpkg cpio archive into a directory.
    4.55 +# Parameters: package_file results_directory
    4.56 +extract() {
    4.57 +	local package_file=$1
    4.58 +	local target_dir=$2
    4.59 +	
    4.60 +	# validate the file
    4.61 +	check_valid_tazpkg $package_file
    4.62 +	
    4.63 +	# find the package name
    4.64 +	local package_name=$(package_name $package_file)
    4.65 +
    4.66 +	# Create destination directory
    4.67 +	local dest_dir=$(pwd)/$package_name
    4.68 +	[ -n "$target_dir" ] && dest_dir=$target_dir/$package_name
    4.69 +	mkdir -p $dest_dir
    4.70 +	
    4.71 +	newline
    4.72 +	echo $(boldify $(gettext "Extracting:")) $package_name
    4.73 +	separator
    4.74 +	
    4.75 +	gettext "Copying original package..."
    4.76 +	cp $package_file $dest_dir
    4.77 +	status
    4.78 +	pushd $dest_dir > /dev/null
    4.79 +		extract_package $package $package_file
    4.80 +	popd > /dev/null
    4.81 +	separator
    4.82 +	eval_gettext "\$package_name is extracted to: \$dest_dir"; newline
    4.83 +	newline
    4.84 +}
    4.85 +
    4.86 +# Recompress .tazpkg cpio archive with lzma.
    4.87 +# Parameters: package_file
    4.88 +recompress() {
    4.89 +	local package_file=$1	
    4.90 +	valid_tazpkg $package_file
    4.91 +	
    4.92 +	local package_name=$(package_name $package_file)
    4.93 +	
    4.94 +	newline
    4.95 +	echo $(boldify $(gettext "Recompressing:")) $package_name
    4.96 +	separator
    4.97 +	
    4.98 +	mkdir -p $TMP_DIR
    4.99 +	
   4.100 +	gettext "Copying original package..."
   4.101 +	cp $package_file $TMP_DIR
   4.102 +	status
   4.103 +	
   4.104 +	pushd $TMP_DIR > /dev/null
   4.105 +		extract_package $package_file
   4.106 +	
   4.107 +		gettext "Recompressing the fs... "
   4.108 +		find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
   4.109 +		rm -rf fs
   4.110 +		status
   4.111 +	popd > /dev/null
   4.112 +	
   4.113 +	gettext "Creating new package... "
   4.114 +	find $TMP_DIR -print | cpio -o -H newc --quiet > \
   4.115 +		$(basename $package_file).$$ && mv -f \
   4.116 +		$(basename $package_file).$$ \
   4.117 +		$(basename $package_file)
   4.118 +	status
   4.119 +	
   4.120 +	rm -rf $TMP_DIR
   4.121 +}
   4.122 +
   4.123 +# Create SliTaz package archive from an installed package.
   4.124 +# Parameters: package
   4.125 +repack() {
   4.126 +	local package=$1
   4.127 +	unset EXTRAVERSION
   4.128 +	source $INSTALLED/$package/receipt
   4.129 +	newline
   4.130 +	echo -e "$(bold Repacking :) $PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
   4.131 +	separator
   4.132 +	if grep -qs ^NO_REPACK= $INSTALLED/$PACKAGE/receipt; then
   4.133 +		eval_gettext "Can't repack \$PACKAGE"; newline
   4.134 +		exit 1
   4.135 +	fi
   4.136 +	if [ -s $INSTALLED/$PACKAGE/modifiers ]; then
   4.137 +		eval_gettext "Can't repack, \$PACKAGE files have been modified by:"; newline
   4.138 +		for i in $(cat $INSTALLED/$PACKAGE/modifiers); do
   4.139 +			echo "  $i"
   4.140 +		done
   4.141 +		exit 1
   4.142 +	fi
   4.143 +	unset MISSING
   4.144 +	while read i; do
   4.145 +		[ -e "$i" ] && continue
   4.146 +		[ -L "$i" ] || MISSING="$MISSING\n  $i"
   4.147 +	done < $INSTALLED/$PACKAGE/files.list
   4.148 +	if [ -n "$MISSING" ]; then
   4.149 +		gettext "Can't repack, the following files are lost:"
   4.150 +		echo -e "$MISSING"
   4.151 +		exit 1
   4.152 +	fi
   4.153 +	mkdir -p $TMP_DIR 
   4.154 +	pushd $TMP_DIR > /dev/null
   4.155 +	FILES="fs.cpio.lzma\n"
   4.156 +	for i in $(ls $INSTALLED/$PACKAGE) ; do
   4.157 +		[ "$i" = "volatile.cpio.gz" ] && continue
   4.158 +		[ "$i" = "modifiers" ] && continue
   4.159 +		cp $INSTALLED/$PACKAGE/$i . && FILES="$FILES$i\n"
   4.160 +	done
   4.161 +	ln -s / rootfs
   4.162 +	mkdir tmp
   4.163 +	sed 's/^/rootfs/' < files.list | cpio -o -H newc --quiet |\
   4.164 +	      { cd tmp ; cpio -idm --quiet >/dev/null; cd ..; }
   4.165 +	mv tmp/rootfs fs
   4.166 +	if [ -f $INSTALLED/$PACKAGE/volatile.cpio.gz ]; then
   4.167 +		zcat $INSTALLED/$PACKAGE/volatile.cpio.gz | \
   4.168 +			{ cd fs; cpio -idm --quiet; cd ..; }
   4.169 +	fi
   4.170 +	if fgrep -q repack_cleanup $INSTALLED/$PACKAGE/receipt; then
   4.171 +		. $INSTALLED/$PACKAGE/receipt
   4.172 +		repack_cleanup fs
   4.173 +	fi
   4.174 +	if [ -f $INSTALLED/$PACKAGE/$CHECKSUM ]; then
   4.175 +		sed 's,  ,  fs,' < $INSTALLED/$PACKAGE/$CHECKSUM | \
   4.176 +		$CHECKSUM -s -c || {
   4.177 +			gettext "Can't repack, $CHECKSUM error."; newline
   4.178 +			popd
   4.179 +			rm -rf $TMP_DIR
   4.180 +			exit 1
   4.181 +		}
   4.182 +	fi
   4.183 +	find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
   4.184 +	echo -e "$FILES" | cpio -o -H newc --quiet > $PACKAGE-$VERSION$EXTRAVERSION.tazpkg
   4.185 +	popd > /dev/null
   4.186 +	mv $TMP_DIR/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg .
   4.187 +	rm -R $TMP_DIR
   4.188 +	eval_gettext "Package \$PACKAGE repacked successfully."; newline
   4.189 +	echo $(gettext "Size") : $(du -sh $PACKAGE-$VERSION$EXTRAVERSION.tazpkg)
   4.190 +	newline
   4.191 +}
   4.192 +
   4.193 +# Create SliTaz package archive from configuration files.
   4.194 +repack_config() {
   4.195 +	mkdir -p $TMP_DIR
   4.196 +	pushd $TMP_DIR > /dev/null
   4.197 +	CONFIG_VERSION=1.0
   4.198 +	mkdir config-$CONFIG_VERSION
   4.199 +	pushd config-$CONFIG_VERSION
   4.200 +	for i in $INSTALLED/*/volatile.cpio.gz; do
   4.201 +		zcat $i | cpio -t --quiet
   4.202 +	done > files.list
   4.203 +	mkdir fs
   4.204 +	pushd fs
   4.205 +	( cd / ; cpio -o -H newc --quiet ) < ../files.list | cpio -idm --quiet > /dev/null
   4.206 +	mkdir -p etc/tazlito
   4.207 +	for i in $INSTALLED/*/receipt; do
   4.208 +		unset EXTRAVERSION
   4.209 +		source $i
   4.210 +		echo "$PACKAGE-$VERSION$EXTRAVERSION"
   4.211 +	done > etc/tazlito/config-packages.list
   4.212 +	popd > /dev/null
   4.213 +	echo "etc/tazlito/config-packages.list" >> files.list
   4.214 +	cat > receipt <<EOT
   4.215 +# SliTaz package receipt.
   4.216 +
   4.217 +PACKAGE="config"
   4.218 +VERSION="$CONFIG_VERSION"
   4.219 +CATEGORY="base-system"
   4.220 +SHORT_DESC="$(gettext "User configuration backup on ")$(date)"
   4.221 +DEPENDS="$(ls $INSTALLED)"
   4.222 +EOT
   4.223 +	popd
   4.224 +	tazpkg pack config-$CONFIG_VERSION
   4.225 +	popd
   4.226 +	cp $TMP_DIR/config-$CONFIG_VERSION.tazpkg .
   4.227 +	rm -rf $TMP_DIR
   4.228 +}
   4.229 +
   4.230 +# Create SliTaz package archive using cpio and gzip.
   4.231 +# Parameters: package
   4.232 +pack() {
   4.233 +	local package="$1"
   4.234 +	cd $PACKAGE
   4.235 +	if [ ! -f "receipt" ]; then
   4.236 +		gettext "Receipt is missing. Please read the documentation."; newline
   4.237 +		exit 0
   4.238 +	else
   4.239 +		newline
   4.240 +		echo "$(bold Packing :) $PACKAGE"
   4.241 +		separator
   4.242 +		# Create files.list with redirecting find outpout.
   4.243 +		gettext "Creating the list of files..." 
   4.244 +		pushd fs
   4.245 +		find . -type f -print > ../files.list
   4.246 +		find . -type l -print >> ../files.list
   4.247 +		popd
   4.248 +		sed -i s/'^.'/''/ files.list
   4.249 +		status
   4.250 +		gettext "Creating $CHECKSUM of files..."
   4.251 +		while read file; do
   4.252 +			[ -L "fs$file" ] && continue
   4.253 +			[ -f "fs$file" ] || continue
   4.254 +			case "$file" in
   4.255 +			/lib/modules/*/modules.*|*.pyc) continue;;
   4.256 +			esac
   4.257 +			$CHECKSUM "fs$file" | sed 's/  fs/  /'
   4.258 +		done < files.list > $CHECKSUM
   4.259 +		status
   4.260 +		UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
   4.261 +			description.txt 2> /dev/null | awk \
   4.262 +			'{ sz=$1 } END { print sz }')
   4.263 +		# Build cpio archives.
   4.264 +		gettext "Compressing the fs... "
   4.265 +		find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
   4.266 +		rm -rf fs
   4.267 +		status
   4.268 +		PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
   4.269 +			$CHECKSUM description.txt 2> /dev/null | awk \
   4.270 +			'{ sz=$1 } END { print sz }')
   4.271 +		gettext "Updating receipt sizes..."
   4.272 +		sed -i s/^PACKED_SIZE.*$// receipt
   4.273 +		sed -i s/^UNPACKED_SIZE.*$// receipt
   4.274 +		sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
   4.275 +		status
   4.276 +		gettext "Creating full cpio archive... "
   4.277 +		find . -print | cpio -o -H newc --quiet > ../$PACKAGE.tazpkg
   4.278 +		status
   4.279 +		gettext "Restoring original package tree... "
   4.280 +		unlzma -c fs.cpio.lzma | cpio -idm --quiet
   4.281 +		status
   4.282 +		rm fs.cpio.lzma && cd ..
   4.283 +		separator
   4.284 +		eval_gettext "Package \$PACKAGE compressed successfully."; newline
   4.285 +		echo $(gettext "Size") : $(du -sh $PACKAGE.tazpkg)
   4.286 +		newline
   4.287 +	fi
   4.288 +}
   4.289 +
   4.290 +case $1 in
   4.291 +	pack|-p)
   4.292 +		pack $2 ;;
   4.293 +	extract|-e)
   4.294 +		extract_package $2 $3 ;;
   4.295 +	recompress|-r)
   4.296 +		recompress $2 ;;
   4.297 +	*)
   4.298 +		usage ;;
   4.299 +esac