spk diff spk-add @ 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
children 8517989e8588
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/spk-add	Fri May 11 21:23:22 2012 -0500
     1.3 @@ -0,0 +1,346 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Authors : See the AUTHORS files
     1.7 +
     1.8 +# Set to / for now untill we add installing to chroot support
     1.9 +# Could we update tools so they do not need this?
    1.10 +ROOT=""
    1.11 +TMP_DIR="/tmp/$RANDOM"
    1.12 +
    1.13 +source /usr/lib/slitaz/libspk.sh
    1.14 +
    1.15 +# This function installs a package in the rootfs.
    1.16 +# Parameters: package_name package_file
    1.17 +install_package() {	
    1.18 +	local package_file=$1
    1.19 +	
    1.20 +	# Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
    1.21 +		
    1.22 +	# Create package path early to avoid dependencies loop
    1.23 +	mkdir -p $TMP_DIR
    1.24 +	extract_receipt $TMP_DIR $package_file
    1.25 +	source $TMP_DIR/receipt
    1.26 +	
    1.27 +	local package_name=$PACKAGE
    1.28 +	local package_dir="$installed/$package_name"
    1.29 +	mkdir -p $package_dir
    1.30 +
    1.31 +	# Run pre_depends from receipt if it exists
    1.32 +	if grep -q ^pre_depends $TMP_DIR/receipt; then
    1.33 +		pre_depends $ROOT
    1.34 +	fi
    1.35 +
    1.36 +	# Create modifiers and files.list if they do not exist
    1.37 +#	touch $package_dir/modifiers
    1.38 +#	touch $package_dir/files.list
    1.39 +
    1.40 +	# add package checksum to pkgsmd5
    1.41 +	sed -i "/ $(basename $package_dir)$/d" $pkgsmd5 2> /dev/null
    1.42 +	pushd $(dirname $package_file) > /dev/null
    1.43 +		$CHECKSUM $(basename $package_file) >> $pkgsmd5
    1.44 +	popd > /dev/null
    1.45 +	
    1.46 +	# Resolve package deps.
    1.47 +	if missing_deps $package_name $DEPENDS; then
    1.48 +		install_deps $package_name $DEPENDS
    1.49 +	fi
    1.50 +	
    1.51 +	newline	
    1.52 +	boldify $(gettext "Installation of :") $package_name
    1.53 +	separator
    1.54 +	eval_gettext "Copying \$package_name... "
    1.55 +	cp $package_file $TMP_DIR
    1.56 +	status
    1.57 +	
    1.58 +	# Extract Package
    1.59 +	pushd $TMP_DIR > /dev/null
    1.60 +		rm receipt
    1.61 +		spk-archive extract $package_file
    1.62 +	popd > /dev/null
    1.63 +	
    1.64 +	# Get files to remove if upgrading
    1.65 +	local files_to_remove
    1.66 +	if [ -f $package_dir/files.list ]; then
    1.67 +		for file in $($package_dir/files.list); do
    1.68 +			grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
    1.69 +			local modifiers=$(cat $package_dir/modifiers 2> /dev/null;\
    1.70 +							  fgrep -sl $package_dir */modifiers | cut -d/ -f1)
    1.71 +			for i in modifiers; do
    1.72 +				grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
    1.73 +			done
    1.74 +			files_to_remove="$files_to_remove $file"
    1.75 +		done
    1.76 +	fi
    1.77 +	
    1.78 +	local check=false
    1.79 +	local file_list
    1.80 +	# Create list of all possibly modified files
    1.81 +	for i in $(fgrep -v [ $TMP_DIR/files.list); do
    1.82 +		[ -e "$ROOT$i" ] || continue
    1.83 +		[ -d "$ROOT$i" ] && continue
    1.84 +		file_list="$file_list $i"
    1.85 +		check=true
    1.86 +	done
    1.87 +	
    1.88 +	# Check possibly modified files against other packages file.list
    1.89 +	if $check; then
    1.90 +		for pkg in $INSTALLED/*; do 
    1.91 +		  	[ "$pkg" == "$package_name" ] && continue
    1.92 +		  	[ -s $pkg/files.list ] || continue
    1.93 +		  	
    1.94 +		  	for file in $file_list; do
    1.95 +		  		# $package_name wants to install $file which is already
    1.96 +		  		# Installed from $pkg
    1.97 +				if grep -q ^$file$ $pkg/files.list; then
    1.98 +					# Tell $pkg that $package_name is going to overwrite some of it's files
    1.99 +					if [ -s "$pkg/volatile.cpio.gz" ]; then
   1.100 +						# We can modify backed up files without notice
   1.101 +						zcat $pkg/volatile.cpio.gz | cpio -t --quiet | \
   1.102 +						grep -q "^${file#/}$" && continue
   1.103 +					fi
   1.104 +					echo "$package_name" >> $pkg/modifiers
   1.105 +				fi
   1.106 +			done
   1.107 +		done
   1.108 +	fi
   1.109 +	
   1.110 +	pushd $TMP_DIR > /dev/null
   1.111 +		cp receipt files.list $package_dir
   1.112 +		# Copy the description if found.
   1.113 +		[ -f "description.txt" ] && cp description.txt $package_dir
   1.114 +		
   1.115 +		# Pre install commands.
   1.116 +		if grep -q ^pre_install $package_dir/receipt; then
   1.117 +			pre_install $ROOT
   1.118 +		fi
   1.119 +		
   1.120 +		# Handle Config Files from reciept
   1.121 +		if [ -n "$CONFIG_FILES" ]; then
   1.122 +			pushd $fs > /dev/null
   1.123 +				# save 'official' configuration files
   1.124 +				eval_gettext "Saving configuration files for \$package_name... "
   1.125 +				
   1.126 +				local confs
   1.127 +				for i in $CONFIG_FILES; do
   1.128 +					confs="$confs $(find ${i#/} -type f 2> /dev/null)"
   1.129 +				done
   1.130 +				
   1.131 +				echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz
   1.132 +		
   1.133 +				# keep user configuration files
   1.134 +				for conf_file in $confs; do
   1.135 +					[ -e $conf_file ] || continue
   1.136 +					cp -a $conf_file fs/$conf_file
   1.137 +				done
   1.138 +				status
   1.139 +			popd > /dev/null
   1.140 +		fi
   1.141 +		
   1.142 +		# Merge ROOT_FS with Package FS
   1.143 +		eval_gettext "Installing \$package_name... "
   1.144 +		cp -a fs/* $ROOT/
   1.145 +		status
   1.146 +		
   1.147 +		# Remove old config files
   1.148 +		if [ -n $files_to_remove ]; then
   1.149 +			eval_gettext "Removing old \$package_name... "
   1.150 +			for file in $files_to_remove; do
   1.151 +				remove_with_path $ROOT$file
   1.152 +			done
   1.153 +			status
   1.154 +		fi
   1.155 +	popd > /dev/null
   1.156 +	
   1.157 +	# Remove the temporary directory.
   1.158 +	gettext "Removing all tmp files... "
   1.159 +	rm -rf $TMP_DIR
   1.160 +	status
   1.161 +	
   1.162 +	# Post install commands.
   1.163 +	if grep -q ^post_install $package_dir/receipt; then
   1.164 +		post_install $ROOT
   1.165 +	fi
   1.166 +	
   1.167 + 	# Update-desktop-database if needed.
   1.168 +	if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
   1.169 +		updatedesktopdb=yes
   1.170 +	fi
   1.171 +	# Update-mime-database if needed.
   1.172 +	if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
   1.173 +		updatemimedb=yes
   1.174 +	fi
   1.175 +	# Update-icon-database
   1.176 +	if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
   1.177 +		updateicondb=yes
   1.178 +	fi
   1.179 +	# Compile glib schemas if needed.
   1.180 +	if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
   1.181 +		compile_schemas=yes
   1.182 +	fi
   1.183 +	# Update depmod list
   1.184 +	if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
   1.185 +		updatedepmod=yes
   1.186 +	fi
   1.187 +	
   1.188 +	separator
   1.189 +	eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
   1.190 +	newline
   1.191 +}
   1.192 +
   1.193 +
   1.194 +# Install .tazpkg packages.
   1.195 +# Parameters: package_file
   1.196 +install_pkg() {
   1.197 +	package_file="$1"
   1.198 +	
   1.199 +	check_root
   1.200 +	check_valid_tazpkg $package_file
   1.201 +	
   1.202 +	# Check if forced install.
   1.203 +	if ! [ "$forced" ]; then
   1.204 +		check_for_installed_package $(package_name $package_file)
   1.205 +	fi
   1.206 +	
   1.207 +	install_package $package_file
   1.208 +	
   1.209 +	update_desktop_database
   1.210 +	update_mime_database
   1.211 +	update_icon_database 
   1.212 +	compile_glib_schemas
   1.213 +}
   1.214 +
   1.215 +# Download and install a package. TODO: Handle Undigest Mirrors
   1.216 +# Parameters: package_name
   1.217 +get_install() {
   1.218 +	local package_name="$1"
   1.219 +
   1.220 +	check_root
   1.221 +	
   1.222 +	# Check if get-Package
   1.223 +	if ! is_package_mirrored $package_name; then
   1.224 +		package_name="get-$package_name"
   1.225 +		AUTOEXEC=true
   1.226 +	fi
   1.227 +
   1.228 +	# Check if package is mirrored
   1.229 +	if ! is_package_mirrored $package_name; then
   1.230 +		gettext "Could not find \$package_name in repositories"; newline
   1.231 +		exit 1
   1.232 +	fi
   1.233 +
   1.234 +	# package_full=Package-Version
   1.235 +	local package_full=$(full_package $package_name)
   1.236 +	
   1.237 +	# Check if forced install.
   1.238 +	if ! [ "$forced" ]; then
   1.239 +		check_for_installed_package $package_name
   1.240 +	fi
   1.241 +	
   1.242 +	pushd $CACHE_DIR > /dev/null
   1.243 +		if [ -f "$package_full.tazpkg" ]; then
   1.244 +			eval_gettext "\$package_full is already in the cache : \$CACHE_DIR"; newline
   1.245 +			# Check package download was finished
   1.246 +			if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
   1.247 +				eval_gettext "Continuing \$package_name download"; newline
   1.248 +				download "$package_full.tazpkg"
   1.249 +			fi
   1.250 +			
   1.251 +			# Check that the package has the correct checksum
   1.252 +#			if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \"  $package_full.tazpkg\" $pkgsmd5)" ]; then
   1.253 +#				rm -f $package.tazpkg
   1.254 +#				download "$package_full.tazpkg"
   1.255 +#			fi
   1.256 +		else
   1.257 +			newline 
   1.258 +			download "$package_full.tazpkg"
   1.259 +		fi
   1.260 +	popd > /dev/null
   1.261 +	
   1.262 +	install_package "$CACHE_DIR/$package_full.tazpkg"
   1.263 +	
   1.264 +	[ -n "$AUTOEXEC" ] && $package_name $ROOT 
   1.265 +	update_desktop_database
   1.266 +	update_mime_database
   1.267 +}
   1.268 +
   1.269 +# Install all missing deps. Auto install or ask user then install all missing 
   1.270 +# deps from local dir, cdrom, media or from the mirror. In case we want to
   1.271 +# install packages from local, we need a packages.list to find the version.
   1.272 +# Parameters: package List of deps to install
   1.273 +install_deps() {
   1.274 +	local package=$1
   1.275 +	shift
   1.276 +	local deps="$@"
   1.277 +	
   1.278 +	gettext "Install all missing dependencies? "
   1.279 +	
   1.280 +	# Print Yes/No and get result
   1.281 +	if $AUTO_INSTALL_DEPS || confirm; then
   1.282 +		for pkgorg in $deps; do
   1.283 +			local pkg=$(equivalent_pkg $pkgorg)
   1.284 +			# Check if package is not installed
   1.285 +			if [ ! -d "$installed/$pkg" ]; then
   1.286 +				if [ ! -f "$PKGS_DB/packages.list" ]; then
   1.287 +					tazpkg recharge
   1.288 +				fi
   1.289 +				get-install $pkg
   1.290 +			fi
   1.291 +		done
   1.292 +	else
   1.293 +		newline
   1.294 +		eval_gettext \
   1.295 +"Leaving dependencies for \$package unresolved. The package is installed but
   1.296 +will probably not work."; newline
   1.297 +		newline
   1.298 +	fi
   1.299 +}
   1.300 +
   1.301 +# Check for ELF file
   1.302 +is_elf() {
   1.303 +	[ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
   1.304 +}
   1.305 +
   1.306 +# Print shared library dependencies
   1.307 +ldd() {
   1.308 +	LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
   1.309 +}
   1.310 +
   1.311 +
   1.312 +update_desktop_database() {
   1.313 +	if [ -f $ROOT/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
   1.314 +		chroot "$ROOT/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
   1.315 +	fi
   1.316 +}
   1.317 +
   1.318 +update_mime_database() {
   1.319 +	if [ -f $ROOT/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
   1.320 +		chroot "$ROOT/" /usr/bin/update-mime-database /usr/share/mime
   1.321 +	fi
   1.322 +}
   1.323 +
   1.324 +update_icon_database() {
   1.325 +	if [ -f $ROOT/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
   1.326 +		chroot "$ROOT/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
   1.327 +	fi
   1.328 +}
   1.329 +
   1.330 +compile_glib_schemas() {
   1.331 +	if [ -f $ROOT/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
   1.332 +		chroot "$ROOT/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
   1.333 +	fi
   1.334 +}
   1.335 +
   1.336 +update_kernel_modules() {
   1.337 +	if [ -f $ROOT/sbin/depmod ] && [ -n "$updatedepmod" ]; then
   1.338 +		chroot "$ROOT/" /sbin/depmod -a
   1.339 +	fi
   1.340 +}
   1.341 +
   1.342 +case $1 in
   1.343 +	install|-i)
   1.344 +		install_pkg $2 $3 ;;
   1.345 +	get-install|-gi)
   1.346 +		get_install $2 ;;
   1.347 +	*)
   1.348 +		usage ;;
   1.349 +esac