#!/bin/sh

echo "This is script does a brute force install of the package manager."
echo

ans=
while [ "$ans" != "y" -a "$ans" != "Y" -a "$ans" != "n" -a "$ans" != "N" ]
do
	echo -n "Are you sure you want to do this? (y/n) "
	read ans
done

if [ "$ans" = "n" -o "$ans" = "N" ]; then
	exit 0
fi

if [ ! -d /etc/default ]; then
	mkdir /etc/default
fi
cp	default/package		/etc/default/package

ln	bin/initialise		/bin/initialise || \
	ln -s	bin/initialise		/bin/initialise
ln	bin/makeinit		/bin/makeinit || \
	ln -s	bin/makeinit		/bin/makeinit
ln	bin/pkg			/bin/pkg || \
	ln -s	bin/pkg			/bin/pkg

ln	man/pkg.1		/usr/man/man1/pkg.1 || \
	ln -s	man/pkg.1		/usr/man/man1/pkg.1

ln	usr.lib/pipe-inst	/usr/lib/pkg/pipe-inst || \
	ln -s	usr.lib/pipe-inst	/usr/lib/pkg/pipe-inst
ln	usr.lib/pipe-rm		/usr/lib/pkg/pipe-rm || \
	ln -s	usr.lib/pipe-rm		/usr/lib/pkg/pipe-rm
ln	usr.lib/prepare		/usr/lib/pkg/prepare || \
	ln -s	usr.lib/prepare		/usr/lib/pkg/prepare

# Now the package manager is installed we can reinstall it with itself
# so it appears in the necessary lists etc.
locn=`cd ..; pwd`
pkg -q --target / --add $locn/package* --rebuild
