#!/bin/ksh

# Written by Niclas Sodergard <nickus@aspiringsysadmin.com>
# Public Domain - do whatever you like

#
# this is the directory where we want to install zones
# change it to reflect your own standard
#
ZONEDIR=/zones

if [ "x$3" = "x" ]; then
	echo "Usage: create_zone.sh <name> <interface> <ipaddress>"
	exit 1
fi

if [ ! -d $ZONEDIR ]; then
	echo "Creating $ZONEDIR."
	chown root:root $ZONEDIR
fi

#
# create the zone directory and set the correct permissions
#
if [ ! -d $ZONEDIR/$1 ]; then
	mkdir $ZONEDIR/$1
fi
chown root:root $ZONEDIR/$1
chmod 0700 $ZONEDIR/$1

#
# generate the basic zone configuration
#
cat << EOF | zonecfg -z $1
	create
	set autoboot=true
	set zonepath=$ZONEDIR/$1
	add net
		set physical=$2
		set address=$3
	end
	commit
	exit
EOF

zoneadm -z $1 install

#
# create the sysidcfg file that will answer all the necessary questions
# the default root password is abc123
#
cat << EOF >$ZONEDIR/$1/root/etc/sysidcfg
system_locale=C
terminal=xterm
network_interface=primary {
	hostname=$1
}
security_policy=NONE
name_service=NONE
timezone=UTC
root_password=fto/dU8MKwQRI
nfs4_domain=dynamic
EOF

#
# this is needed to supress the nfsv4 question for solaris 10
# prior to u3
#
touch $ZONEDIR/$1/root/etc/.NFS4inst_state.domain

zoneadm -z $1 boot

