#!/bin/sh -e
# See http://jdebp.uk./FGA/slashpackage.html
if [ \! -d package ] || [ \! -d source ]
then
	echo "You are not in the right directory." 1>&2
	exit 100
fi
case "`uname`" in
Linux)		extended_regexp="-r -e" ; no_target_dir=-T ;;
OpenBSD)	extended_regexp=-E ; no_target_dir="" ;;
*BSD)		extended_regexp=-E ; no_target_dir=-h ;;
esac
cwd="`/bin/pwd`"
base_plus_version="`basename \"${cwd}\"`"
base="`echo "${base_plus_version}" | sed ${extended_regexp} 's/-[[:digit:]][[:alnum:].]*$//'`"
if [ "${base}" != "${base_plus_version}" ]
then
	for target in ptyget publicfile daemontools djbdns ucspi-tcp clockspeed libtai taitools "${base}"
	do
		echo "Creating symlink ${target} -> ${base_plus_version}."
		case "`uname`" in
		OpenBSD)
			ln -s -f -- "${base_plus_version}" "${target}"
			mv -f -- "${target}" ../
			;;
		*)
			ln -s -f -- "${base_plus_version}" ../"${target}"{new}
			mv -f ${no_target_dir} -- ../"${target}"{new} ../"${target}"
			;;
		esac
	done
else
	echo 1>&2 "This is not a versioned package."
fi
exit 0
