Jump to: navigation, search

CVS Source From Mapfile

Revision as of 16:17, 5 December 2006 by Codeslave.ca.ibm.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Situation

For legal purposes, you want to scan your CVS sources, but you want to scan the sources for a given build, not a branch or HEAD. How do you ensure that the source you get from CVS matches what was used for a given build?

Solution

You use the script copied below to extract the source from CVS into a folder, then you can either zip those files and sent them where they need to go or scan them in place. Script requires a linux system with cvs, grep, and gawk installed, or an equivalent cygwin install running on Windows. Note that long pathnames may be a problem if run on Windows.

Script

#!/bin/bash
#
# File: getCVSBuildSource.sh
# Author: millertb@us.ibm.com, codeslave@ca.ibm.com (renamed from automation.sh to getCVSBuildSource.sh)
# Version: Developer Edition 1.3
#
# Script takes a mapfiles as input and downloads via cvs the directory structure for a given
# build of eclipse. 
#
# Windows users require cygwin with grep, cvs, and gawk installed
# 
# Usage:  ./getCVSBuildSource.sh mapfile.map

if [ -z "$1" ]; then
	echo Usage:
	echo "  ./getCVSBuildSource.sh directory.txt"
	echo "    - or - "
	echo "  ./getCVSBuildSource.sh mapfile.map"
	echo
	echo For help type:  ./getCVSBuildSource.sh -h
	echo
elif [ "$1" == "-h" ]; then
	echo The getCVSBuildSource.sh script takes a single mapfile as an argument
	echo and downloads the associated files from the eclipse.org cvs repository.
	echo If you are a Windows user, type $0 --help-windows for how to run.
	echo 
	echo Usage:  ./getCVSBuildSource.sh mapfile.map
	echo
elif [ "$1" == "--help-windows" ]; then
	echo Windows users must download a program called Cygwin from http://www.cygwin.com/setup.exe 
	echo which will give you an emulated UNIX environment on the Windows platform.  The standard 
	echo install should be fine, but you must make sure that "install" is selected on the following 
	echo packages and if it is not, you must select "install" manually:
	echo "  base -> grep"
	echo "  Devel -> cvs"
	echo "  interpreters -> gawk"
	echo
	echo Usage: ./getCVSBuildSource.sh mapfile.map
	echo
elif [ ! -f "$1" ]; then
	echo Error: mapfile "$1" not found!
	echo 
	echo Usage:  ./getCVSBuildSource.sh mapfile.map
	echo
	echo For help type:  ./getCVSBuildSource.sh -h
	echo
else
	# Download the contents of the cvs repository into a dir where we've replaced ".map" and ".txt" with ".src" or if that failed, appended ".src" instead
	dirname=${1/\.map/\.src}; dirname=${dirname/\.txt/\.src}; if [[ $dirname = $1 ]]; then dirname=$dirname".src"; fi
	mapfile=tempmapfile.map

	mkdir -p $dirname;
	grep ^[a-z] $1 > $dirname/$mapfile
	cd $dirname;

	gawk 'BEGIN {
		FS=","
	}
	{
	if (NF <  4) {

		split($1, version, "=");
		split(version[1], directory, "@");
		cvsdir=split($2, dirName, ":");
		printf("%s %s %s%s %s %s %s %s %s %s %s\n", "cvs", "-d", ":pserver:anonymous@dev.eclipse.org:", dirName[cvsdir], "-q", "export", "-r", version[2], "-d", directory[2], directory[2]) | "/bin/bash";
	} 
	else {
	
		split($1, version, "=");
		total=split($4, directory, "/");
		cvsdir=split($2, dirName, ":");
		printf("%s %s %s%s %s %s %s %s %s %s %s\n", "cvs", "-d", ":pserver:anonymous@dev.eclipse.org:", dirName[cvsdir], "-q", "export", "-r", version[2], "-d", directory[total], $4) | "/bin/bash";
	}


	}' $mapfile

	rm $mapfile

	echo "Sources extracted to folder $dirname.";
fi