#!/bin/sh
# http://www.berklix.com/~jhs/bin/.sh/customise_more_links
# NAME
#	~/bin/.sh/customise_more_links
# SEE ALSO
#	~/bin/.csh/customise
# PURPOSE
#	I run this just once per new release, to generate a new set
#	of symbolic links to per-release patches. After that I hand
#	trim the patch sets, if necessary breaking links, copying
#	& editing.

cd ~/public_html/src/bsd/fixes/FreeBSD || echo "cd failed, Aborting."
#	Fails to exit:	|| ( echo "cd failed" ; exit 1 )
cd ~/public_html/src/bsd/fixes/FreeBSD || exit 1

# Done:
#	customise_more_links current		10.0-RELEASE
#	customise_more_links 8.3-RELEASE	8.4-RELEASE
#	customise_more_links 9.2-RELEASE	9.3-RELEASE
#	customise_more_links 10.0-RELEASE	10.1-RELEASE
#	customise_more_links 10.2-RELEASE	10.3-RELEASE
#	customise_more_links 10.3-RELEASE	10.3-STABLE
#	customise_more_links 10.3-RELEASE	10.4-RELEASE
#	customise_more_links 11.2-RELEASE	12.1-RELEASE.3
#	customise_more_links 12.0-CURRENT	11.2-RELEASE
#	customise_more_links 12.0-RELEASE	12.0-STABLE
#	customise_more_links 12.0-RELEASE	12.1-RELEASE.2
#	customise_more_links 12.0-STABLE	12.1-RELEASE
#	customise_more_links 12.1-RELEASE	12.2-STABLE
#	.... next
#	customise_more_links 14.0-RELEASE	14.3-RELEASE

# Number of .REL= diffs that exist @ 2024-01-07 :
#	REL=4.11-RELEASE.diff	40
#	REL=4.8-RELEASE		 1
#	REL=5.5-RELEASE		 9
#	REL=6.4-RELEASE		44
#	REL=7.0-RELEASE.diff	 1
#	REL=7.1-RELEASE.diff	 1
#	REL=7.4-RELEASE		23
#	REL=8.4-RELEASE		67
#	REL=9.0-RELEASE.diff	 1
#	REL=9.1-RELEASE.diff	 1
#	REL=9.2-RELEASE.diff	30
#	REL=9.3-RELEASE.diff	21
#	REL=10.3-RELEASE.diff	35
#	REL=10.3-STABLE.diff	 2
#	REL=11.1-RELEASE.diff	 1
#	REL=11.2-RELEASE.diff	 7
#	REL=11.4-RELEASE.diff	 1
#	REL=12.1-RELEASE.diff	18
#	REL=12.2-RELEASE.diff	 3	dell @ 2024-01-07
#	REL=12.2-STABLE		 3
#	REL=12.3-RELEASE.diff	 2
#	REL=12.4-RELEASE.diff	 1
#	REL=13.0-RELEASE.diff	 8
#	REL=13.2-RELEASE.diff	 1	slim @ 2024-01-07
#	REL=14.0-RELEASE	 98	
#	REL=14.3-RELEASE	 98	find . -type l -name \*REL=14.3-RELEASE\* | wc -l
#	REL=ALL			46
#	REL=CURRENT		59

VEROLD=$1
VERNEW=$2

# Checking for 2 release names.
if [ "x$#" != "x2" ] ; then	#{
	echo "Error, Bad Syntax. Example Of Good Syntax:"
	echo "	`basename $0` 10.2-RELEASE 10.3-RELEASE"
	exit 1
fi				#}

# Avoid same names: would be pointless, & maybe damage some links.
if [ "x$1" == "x$2" ] ; then	#{
	echo "$0: Error: Do not specify same name for old & new release."
	exit 1
fi				#}

# No check that names look plausible, so easy to create a load of bad
# unintentioned mis-named links if you make a typo.
# however it does allow flexibility for names such as 10.3-STABLE 12.0-CURRENT

echo "Proceeding with $VEROLD $VERNEW"

TMPFILE=$HOME/tmp/customise_more_links.tmp
echo "TMPFILE is: $TMPFILE"

find . -name \*\.REL=$VEROLD\.diff | sort > $TMPFILE
# If theres any files with spaces in, or quotes or similar evil rubbish
# this script will crash. Dont bother to check, this is for clean
# Unix programmers, about the only paths tainted by such filth that I recall
# have been data paths imported from MS users & programs, & once or twice on
# mega packages like maybe openoffice or firefox that may also be tainted by
# too close a proximity to MS programmers.

for i in `cat $TMPFILE`
	do
	(
	# Do not need to do:	 cd ~/public_html/src/bsd/fixes/FreeBSD
	# As shell resets CWD, each time round the 'do' loop.
	cd `dirname $i`
	source=`basename $i`
	target=`echo $source | sed -e s/$VEROLD.diff/$VERNEW.diff/`
	echo "Doing: cd `pwd` ; ln -s $source $target"
	ln -s $source $target
	)
	done
rm $TMPFILE

echo "Now doing .cust_rel hand in `pwd` :"
find . -name \*\.REL=$VEROLD\.cust_rel | sort > $TMPFILE
#	ports/gen/sysutils/ezjail/files/patch-ja.REL=*.cust_rel"
#	ports/gen/sysutils/ezjail/files/patch-jb.REL=*.cust_rel"
#	ports/gen/www/chimera/files/patch-ja.2002.11.16.chimera2.main.REL=*.cust_rel"
#	ports/gen/www/chimera/files/patch-ja.2002.11.16.chimera2.manual.REL=*.cust_rel"
#	ports/gen/www/httrack/files/patch-ja.REL=*.cust_rel"
#	ports/gen/www/httrack/files/patch-jc.httrack-3.47.27.REL=*.cust_rel"
echo "Caution: Link contents of thse:"
cat $TMPFILE
echo "will need to be manually read, then links moved. contents copied,"
echo "links deleted, & contents edited as: eg for \*.REL=9.2-RELEASE.no_customise"
echo "they would typically be a comment that something was needed in 9.1"
echo "but seems to have been fixed & not needed in 9.2."
for i in `cat $TMPFILE`
	do
	(
	# Do not need to do:	 cd ~/public_html/src/bsd/fixes/FreeBSD
	# As shell resets CWD, each time round the 'do' loop.
	cd `dirname $i`
	source=`basename $i`
	target=`echo $source | sed -e s/$VEROLD.cust_rel/$VERNEW.cust_rel/`
	echo "Doing: cd `pwd` ; ln -s $source $target"
	ln -s $source $target
	)
	done
rm $TMPFILE
