#!/bin/ksh

echo "Installing IPsec"

cd /usr/local/pkg
gunzip Sol8_encryption_sparc.tar.gz
tar xvf Sol8_encryption_sparc.tar
cd sparc/Packages
pkgadd -d . SUNWcry SUNWcryrx SUNWcry64 SUNWcrman SUNWcryr 
touch /etc/ipsecinit.conf

echo "Configuring Hosts..."
echo ""
sleep 1
echo "Enter Your Host: \c"
read you
echo "Enter The Other Host: \c"
read other

echo "Creating Keys..."
sleep 1
echo "add ah spi 1 src anotherhost dst thishost authalg md5 authkey 04e1a3bf63d1b80a132def80375a1c26" >> /etc/inet/ipsec.keys.load
echo "add ah spi 2 src thishost dst anotherhost authalg md5 authkey 1234567890abcdef0987654321abcdef" >> /etc/inet/ipsec.keys.load
echo "add esp spi 3 src thishost dst anotherhost encralg des encrkey deadbeefdeadbeef" >> /etc/inet/ipsec.keys.load
echo "add esp spi 4 src anotherhost dst thishost encralg des encrkey b18ace5372decabe" >> /etc/inet/ipsec.keys.load

echo "Configuring Policies..."
sleep 1

echo "{saddr $you daddr $other} apply {auth_algs md5 sa shared}" >> /etc/inet/ipsec.conf.load
echo "{saddr $other daddr $you} permit {auth_algs any}" >> /etc/inet/ipsec.conf.load
echo "{saddr $you daddr $other} apply {encr_algs des sa shared}" >> /etc/inet/ipsec.conf.load
echo "{saddr $other daddr $you} permit {encr_algs any}" >> /etc/inet/ipsec.conf.load

echo "/usr/sbin/ipseckey -f /etc/inet/ipsec.keys.load" >> /etc/init.d/inetsvc
echo "/usr/sbin/ipsecconf -a /etc/inet/ipsec.conf.load" >> /etc/init.d/inetsvc

#echo "The system will REBOOT in 10 seconds"
#sleep 10
#reboot 

