All pastes #2072632 Raw Edit

pierce.jason

public shellscript v1 · immutable
#2072632 ·published 2011-05-31 06:19 UTC
rendered paste body
#!/bin/bash# Version: 0.4alpha# Author: Ken# Author: Jason Pierce <echo moc tod liamg ta nosaj tod ecreip | rev>########### Configure default settings.#########find_deps="./findNtesting.txt";logfile_errors="./errors.txt";from_dir="./testing";to_dir="./extra";#debug="false";# If global or local configs are readable, possibly over-ride the previous settings.# TODO invert conf settings to first check ENV, then local, then global, then default.# Cascade to more generic if a variable is unset.if [ -r "/etc/mv-testing.conf" ]; then	. "/etc/mv-testing.conf";fi;if [ -r "${HOME}/.config/mv-testing" ]; then	. "${HOME}/.config/mv-testing" ];fi;# If debugging is enabled, send some output to stderr. Otherwise null it.if [ "$debug" = "true" ]; then	dbg="/dev/stderr";else	dbg="/dev/null";fi;# On all exit conditions, run the cleanup function.#trap "cleanup; exit;" EXIT SIGHUP SIGINT SIGQUIT SIGTERM;start_dir=$( pwd );########### Support functions.###########Some rm's to clean up the current working directory.cleanup() {	cd "$start_dir";	rm "$find_deps" 2>$dbg;}# Record all dependencies of Package to $find_deps.# First arguement is the Package of which to investigate dependencies.# Outputs directly to stdout, not captured by a parent function.getDeps() {	local pkg_pattern="$1";	local pkg_path status;	##if package is found the install file is extracted to current working directory.	echo "Finding Package and extracting dependency list.";	pkg_path=$( findPkg "$pkg_pattern" ); status="$?";	# Error out if findPkg is unsuccessfull. Errors already logged	# in findPkg, so no reason to log here.	if [ "$status" != 0 ]; then		return "$status";	fi;	echo "Found ${pkg_path}.";	echo "Now extracting slack-required to find deps.";	##Slack-required is piped to sed and the >= is replaced by - to look like a proper package name.	tar -f "$pkg_path" --xz -xO install/slack-required | sed 's/ >= /-/' >> $find_deps 2>$dbg; status="$?";	# Error out if slack-required extraction is unsuccessfull.	if [ "$status" != 0 ]; then		return "$status";	fi;	##list of searchable names for deps is saved as text file.	echo $NAMEPKG >> $find_deps;	return 0;}# Outputs directly to stdout, not captured by a parent function.processDeps() {	##deps list is compared against each of the directories in testing if package is found	##it is moved to the same directory in testing.	##meta, txt, and txz packages are all moved. It may be better to delete meta and txt will have to find out.	while read pkgname	do		local pkg_path category from_files status;		pkg_path=$( findPkg "$pkgname*vl70" ); status="$?";		# Error out if findPkg is unsuccessfull. Errors already logged		# in findPkg, so no reason to log here.		if [ "$status" != 0 ]; then			return "$status";		fi;		category=$( echo "$pkg_path" | cut -d / -f 2 );		from_files="${from_dir}/${category}/${pkgname}.{txz,txt,meta}";		cp $from_files ${to_dir}/${category}/; status="$?";		# Error out if copy is unsuccessfull.		if [ "$status" != 0 ]; then			echo "Problem copying \"$from_files\" to \"${to_dir}/${category}/\"				cp exited with status \"${status}\"" | tee "$logfile_errors" 1>&2;			return "$status";		fi;		echo "Coppied $line to ${to_dir}/${category}."	done < $find_deps 1>$dbg;	return 0;}# Make sure we can find 1 and ONLY 1 package to use.# First arguement is a list of paths, such as output by `find`.needJustOne() {	local pathnames="$1";	local num_files;	num_files=$( echo "$pathnames" | wc -l );	echo "TRACE-line:${LINENO}> pathnames = $pathnames	num_files = $num_files" 1>$dbg;	if [ "$num_files" -ne "1" ]; then		echo "Can't decide which package to use. Expecting 1 match. Found ${num_files}.";		for file in $pathnames; do			echo "Matching package: \"${file}\".";		done;		return 1;	fi;	return 0;}# Find a file and make sure it is exactly 1 result. Logging any errors# to $logfile_errors. Outputs the path to the file.findPkg() {	local find_pkg="$1";	local pkg_match pkg_error status;	# Escape any odd characters with octal formatting. Must remain unquoted	# to expand category directories on wildcard. Redirect errors to $dbg.	pkg_match=$( ls --escape ${from_dir}/*/${find_pkg}.txz 2>$dbg); status="$?";	echo "TRACE-line:${LINENO}> pkg_match = $pkg_match" 1>$dbg;	# Return error and log if there is no match.	if [ "$status" != 0 ]; then		echo "No packages found to match \"${find_pkg}\"." | tee "$logfile_errors" 1>&2;		return "$status";	fi;	# Ensure that there is _only_ one package matching our search.	pkg_error=$( needJustOne "$pkg_match" ); status="$?";	echo "TRACE-line:${LINENO}> pkg_match = $pkg_match		pkg_error = $pkg_error" 1>$dbg;	# FIX needJustOne not throwing errors on multiple, or 0 here. needJustOne throws errors fine when called standalone.	if [ "$status" != 0 ]; then	# Send needJustOne output to logfile and to stderr.		echo -e "$pkg_error" | tee "$logfile_errors" 1>&2;		return "$status";	fi;	echo "$pkg_matches"; # Just one! Path and filename to the package that we want.	return 0;}########### Main routine.#########if [ "$1" != "libmode" ]; then	## This script should be ran from the ~/Repo/veclinux-7.0/ directory	##user enters the package-version-vl70-build of what they wish to move.	echo "please enter the name of the package you wish to move"	read NAMEPKG	getDeps "$NAMEPKG";	# Create a list of all deps.	processDeps; # Insure that each listed dep is coppied from testing.	echo "...Done"	# Only do makenew/trigger if no errors have been logged.	if [ -f $logfile_errors ]; then		echo "Errors detected. Not running makenew and trigger. See $logfile_errors";		exit 1;	else		## Navigate to both testing and then extra and run ./makenew		echo "Running makenew on $to_dir and $from_dir please wait."		cd ${start_dir}/${from_dir}/		./makenew		cd ${start_dir}/${to_dir}/		./makenew		## Change directory to home and trigger changes.		cd ~/		./trigger-vectorlinux		exit 0;	fi;fi;