Source

packaging / Bootstrap-pkg.sh

Full commit
#!/bin/bash
#
# This bootstrap script is designed to initlaly populate, and later update
# from the global skeleton, for a build of any package.
#
# It should be manually fetched and run by any programmer creating a package,
# it should be able to run on CentOS and Debian platforms and should be
# non-destructive.
#
#----------------------------------------------------------------------------
function copy_skeleton
{
	echo 'Copying skeleton packaging tree from within build-scripts'
	if [ -d '../shared/packaging' ]; then
		/usr/bin/rsync --exclude=Bootstrap-pkg.sh --exclude=.svn -r -a -u -v -p ../shared/packaging/ .
	else
		echo 'Sorry, ../shared/packaging is not available'
		exit 1;
	fi
}
#----------------------------------------------------------------------------
function download_skeleton
{
	echo "Since you're not building within the build-scripts tree, we need to access"
	echo "sub-version, and perform an update from /tmp/, please enter your credentials"
	echo "when prompted"
	echo -e "\n"

	old_dir=`pwd`

	mkdir -p -m 0700 /tmp/`whoami`/Build.$$/ && \
	cd /tmp/`whoami`/Build.$$/ && \
	svn export https://svn.daybologic.co.uk/svn/packaging/trunk

	cd $old_dir && \
	/usr/bin/rsync --exclude=Bootstrap-pkg.sh -r -a -u -v -p /tmp/`whoami`/Build.$$/packaging/ . && \
	rm -rv /tmp/`whoami`/Build.$$/packaging/ && \
	rmdir -v /tmp/`whoami`/Build.$$/
}
#----------------------------------------------------------------------------
function copy_skeleton_wrapper
{
	if [ -d '../shared/packaging' ]; then
		copy_skeleton
	else
		download_skeleton
	fi
}
#----------------------------------------------------------------------------
function deps
{
	# You'll need Subversion for the skeleton package directory
	if ! [ -x /usr/bin/svn ]; then
		if [ -x /usr/bin/yum ]; then
			sudo yum install subversion
		else
			sudo apt-get install subversion
		fi
	fi

	# You'll need RSync for updating the skeleton
	if ! [ -x /usr/bin/rsync ]; then
		if [ -x /usr/bin/yum ]; then
			sudo yum install rsync
		else
			sudo apt-get install rsync
		fi
	fi
}
#----------------------------------------------------------------------------
function fixups
{
	# It's OK to refer to dl-generic's configure here, since that's part
	# of the bootstrap distribution set.
	base_path=./rpmbuild/SOURCES/dl-generic-0.1.0
	x_script=("$base_path/configure" "dl-get_from_spec" "dl-rpm_to_deb" "dl-rules_hack")

	for xscr in ${x_script[*]}
	do
		if [ -f "$xscr" ]; then
			if ! [ -x "$xscr" ]; then
				echo "Marking $xscr executable"
				chmod +x "$xscr"
			fi
		else
			echo "Error: Script not found - $xscr"
			exit 1;
		fi
	done
}
#----------------------------------------------------------------------------
# Die on unbound (uninitialised) varaible use.
set -u

deps -f 0
copy_skeleton_wrapper -f 0
fixups -f 0

echo ''
echo '*** INSTRUCTIONS ***'
echo 'Please review the package skeleton, write the .spec or Debian rules, and then run ./Build'
echo ''

exit 0;