#!/bin/ksh -
#
# @(#)mk-afs-srv	1.32 (hursley) 11/1/96
# /afs/hursley.ibm.com/common/src/afs/@cell/rs_aix32/usr/local/sbin/mk-afs-srv/SCCS/s.mk-afs-srv
#
# NAME		mk-afs-srv
# AUTHOR	Paul Blackburn <mpb@acm.org>
# PURPOSE	Install first AFS fileserver
#		(based on hints in Transarc's AFS Installation Guide!)
# USAGE		Normally invoked as part of system installation.
# ASSUMPTIONS   Make sure you have correctly defined AFS installation
#               parameters for your system. The file containing these
#               ($AFSICF) is defined in:
#			${afs_install_base}/usr/local/sbin/mk-afs-cf

X=${afs_install_base}/usr/local/sbin/mk-afs-cf
if [[ ! -f ${X} ]]; then
	echo "${X} not found - fatal error" >&2
	exit 1
fi

# source global config for AFS installation

. ${X}

tstamp "version 1.32 commenced on `date '+%a %d %h %y'`"

# If we are not running on an AFS server then error exit

if [ -z "${afsserver}" ]; then
	warning "Check: ${AFSICF}"
	fatal "${HOST} is not defined as an AFS server"
fi

# Check we have initial AFS passwords. If either is NULL then prompt for both.

if [ -z "${afspasswd}" -o -z "${adminpasswd}" ]; then

# Switch stdout and stderr back to tty to prompt for data:
	exec 1>&3
	exec 2>&4

	getpass "AFS password for afs:"
	afspasswd=${PASSWORD}
	export afspasswd

	if [ -z "${afspasswd}" ]; then
		fatal "null afspasswd"
	fi

	getpass "AFS password for admin:"
	adminpasswd=${PASSWORD}
	export adminpasswd

	if [ -z "${adminpasswd}" ]; then
		fatal "null adminpasswd"
	fi

	echo "stdout and stderr now being written to ${LOG}"

	exec 4>&2
	exec 3>&1
	exec 1>>${LOG}
	exec 2>&1
fi

# Check AFS installation parameters (already obtained from ${AFSICF})

if [ -z "${afslicense}" ]; then
	fatal "afslicense not defined for ${HOST}"
fi

if [ -z "${afscachevg}" ]; then
	warning "afscachevg not defined for ${HOST}"
	afscachevg="rootvg"
	warning "defaulting to: ${afscachevg}"
fi

if [ -z "${afscachename}" ]; then
	warning "afscachename not defined for ${HOST}"
	afscachename="/usr/vice/cache"
	warning "defaulting to: ${afscachename}"
fi

if [ -z "${afscachesize}" ]; then
	warning "afscachesize not defined for ${HOST}"
	afscache="12"
	warning "defaulting to: ${afscache} (physical partitions)"
fi

if [ -z "${afsdoptions}" ]; then
	warning "afsdoptions not defined for ${HOST}"
	afsdoptions="-stat 2000 -dcache 800 -daemons 3 -volumes 70 -nosettime"
	warning "defaulting to: ${afsdoptions}"
fi

if [ -z "${afscellname}" ]; then
	warning "afscellname not defined for ${HOST}."
	X=`echo ${HOSTNAME} | cut -d. -f2-`
	if [ -z "${X}" ]; then
		fatal "failed to compute default afscellname"
	fi
	warning "defaulting to: ${X}"
	afscellname=${X}
fi

if [ -z "${afspartitions}" ]; then
	warning "afspartitions not defined for ${HOST}"
	afspartitions="rootvg:/vicepa:20"
	warning "defaulting to: ${afspartitions}"
fi

if [ -z "${afsimageserver}" ]; then
	warning "afsimageserver not defined for ${HOST}"
	afsimageserver="afsimageserver.aixssc.uk.ibm.com"
	warning "defaulting to: ${afsimageserver}"
fi

tstamp "Check we can reach afsimageserver=${afsimageserver}"
doit "ping ${afsimageserver} 56 1"
if [ ${retcode} != 0 ]; then
	fatal "Unable to ping ${afsimageserver}"
fi

if [ -z "${afsusrbumpsize}" ]; then
	warning "afsusrbumpsize not defined for ${HOST}"
	afsusrbumpsize="10"
	warning "defaulting to: ${afsusrbumpsize}"
fi

if [ -z "${afsimagedir}" ]; then
	warning "afsimagedir not defined for ${HOST}"
	afsimagedir="/vol/afs34/tapeimages/$sysname"
	warning "defaulting to: ${afsimagedir}"
fi

if [ -z "${afsimagefs}" ]; then
	warning "afsimagefs not defined for ${HOST}"
	afsimagefs="/vol/afs34"
	warning "defaulting to: ${afsimagefs}"
fi

if [ -z "${afsimagefssize}" ]; then
	warning "afsimagefssize not defined for ${HOST}"
	afsimagefssize="4"
	warning "defaulting to: ${afsimagefssize}"
fi

if [ -z "${afsimagevg}" ]; then
	warning "afsimagevg not defined for ${HOST}"
	afsimagevg="rootvg"
	warning "defaulting to: ${afsimagevg}"
fi

if [ -z "${afswsfs}" ]; then
	warning "afswsfs not defined for ${HOST}"
	afswsfs="/vol/afsws"
	warning "defaulting to: ${afswsfs}"
fi

if [ -z "${afswsfssize}" ]; then
	warning "afswsfssize not defined for ${HOST}"
	afswsfssize="4"
	warning "defaulting to: ${afswsfssize}"
fi

if [ -z "${afswsvg}" ]; then
	warning "afswsvg not defined for ${HOST}"
	afswsvg="rootvg"
	warning "defaulting to: ${afswsvg}"
fi

# Phew! Are we ready to start now? :-)

tstamp "AFS Installation Guide page 1-5, section 1.2.4"
tstamp "Make sure we have enough space in /usr for AFS files"

FREE=`df -k /usr | tail -1 | awk '{print $3}'`

# let's work in 512 byte blocks (because chfs size attribute likes this)

# WANTMB is the number of megabytes we want for AFS in /usr
# and afsusrbumpsize is expressed in Physical Partions (1pp=4mb)

let WANTMB=${afsusrbumpsize}\*4

let FREE=${FREE}\*1024/512
let WANT=\(${WANTMB}\*1024\*1024\)/512

if [ ${WANT} -lt ${FREE} ]; then
	tstamp "OK: we have ${WANTMB} in /usr for AFS files"
else
	tstamp "Increasing /usr to get ${WANTMB}MB free for AFS files"
	TOTAL=`df -k /usr | tail -1 | awk '{print $2}'`
	let TOTAL=${TOTAL}\*1024/512
	let SIZE=${TOTAL}+${WANT}-${FREE}
	doit "df -k /usr"
	doit "chfs -a size=${SIZE} /usr"
	if [ ${retcode} != 0 ]; then
		fatal "Unable to increase /usr by ${WANTMB}MB"
	fi
	doit "df -k /usr"
fi

if [ "${afsimageserver}" != "${HOSTNAME}" ]; then

# Create filesystem for AFS install tape compressed tar images

	let sizeblocks=${afsimagefssize}\*8192

	doit "crfs -v jfs -grootvg -a size=${sizeblocks} \
		-m${afsimagefs} -Ayes -prw"
	if [ ${retcode} != 0 ]; then
		fatal "Unable to create afsimagefs=${afsimagefs}"
	fi
	doit "chfs -a mount=true ${afsimagefs}"
	doit "chfs -ulocalfs ${afsimagefs}"
	doit "mount ${afsimagefs}"

	doit "mkdir -p ${afsimagedir}"
fi

tstamp "Check we have enough freespace for AFS cache and partitions"

VGS=`lsvg -o`

for vg in ${VGS}; do
	FREE=`lsvg ${vg} | awk '{if ($4 == "FREE") print $6}'`
	WANT=0
	if [ ${afscachevg} = ${vg} ]; then
		let WANT=${WANT}+${afscachesize}
	fi
	if [ ${afswsvg} = ${vg} ]; then
		let WANT=${WANT}+${afswsfssize}
	fi
	for i in ${afspartitions}
	do
		pvg=`echo ${i} | awk -F: '{print $1}'`
		size=`echo ${i} | awk -F: '{print $3}'`
		if [ ${pvg} = ${vg} ]; then
			let WANT=${WANT}+${size}
		fi
	done
	if [ ${WANT} -gt ${FREE} ]; then
		error "Not enough freespace in volume group: ${vg}"
		error "We have ${FREE} PPs free but need ${WANT}."
		error "Change ${HOST} AFS install parameters or buy more disk!"
		fatal "need more disk space"
	else
		tstamp "OK: Adequate freespace in volume group:${vg}"
		tstamp "We have ${FREE} PPs free and need ${WANT}"
	fi
done

tstamp "AFS Installation Guide, page 1-9"

# Create a separate filesystem for that /usr/afsws will symblink to
# Later, when the contents of afsws have been copied into /afs, we can
# delete this filesystem and recover the space.
# (otherwise /usr gets grown to accomodate afsws and we can't easily shrink it!)

tstamp "Create ${afswsfs} filesystem"
let sizeblocks=${afswsfssize}\*8192
doit "crfs -v jfs -g${afswsvg} -asize=${sizeblocks} -m${afswsfs} -Ayes -prw"
if [ ${retcode} != 0 ]; then
	fatal "Unable to create afswsfs=${afswsfs}"
fi
doit "chfs -a mount=true ${afswsfs}"
doit "chfs -ulocalfs ${afswsfs}"
doit "mount ${afswsfs}"

doit "ln -s /vol/afsws /usr/afsws"

tstamp "afsws files: bin etc include lib man root.client root.server"
# Get the fifth tar set from server (see AFS Installation Guide, page 1-10)

TAPESET=set5.tar.Z
LOCAL=${afsimagedir}/${TAPESET}
REMOTE=${afsimagedir}/${TAPESET}
if [ "${afsimageserver}" != "${HOSTNAME}" ]; then
	doit "tftp -g ${LOCAL} ${afsimageserver} ${REMOTE} image"
fi

cd /usr/afsws
doit "pwd"
doit "compress -d <${LOCAL} | tar xvf -"
if [ ${retcode} != 0 ]; then
	fatal "problem un-tar-ing tapeset ${TAPESET}"
fi

tstamp "dynamic kernel loader files (get the first tar set from server)"

TAPESET=set1.tar.Z
LOCAL=${afsimagedir}/${TAPESET}
REMOTE=${afsimagedir}/${TAPESET}
if [ "${afsimageserver}" != "${HOSTNAME}" ]; then
	doit "tftp -g ${LOCAL} ${afsimageserver} ${REMOTE} image"
fi

tstamp "AFS Installation Guide page 2-6"
doit "mkdir -p /usr/afs/bin"

cd /usr/afs/bin
doit "pwd"
doit "compress -d <${LOCAL} | tar xvf -"

if [ ${retcode} != 0 ]; then
	fatal "problem un-tar-ing tapeset ${TAPESET}"
fi

tstamp "AFS Installation Guide, page 2-10"
for i in afs.ext cfgafs cfgexport export.ext export.ext.nonfs
do
	FILE=/usr/afs/bin/dkload/${i}
	if [ ! -f ${FILE} ]; then
		warning "${FILE} not found"
	fi
done

tstamp "cd /usr/afs/bin/dkload"
cd /usr/afs/bin/dkload

if [ "${sysname}" = "rs_aix32" ]; then
	tstamp "Installing NFS kernel extensions (for AFS+NFS)"
	doit "/etc/gfsinstall -a /usr/lib/drivers/nfs.ext"
fi

tstamp "Installing AFS kernel extensions..."
doit "./cfgexport -a export.ext"
doit "./cfgafs -a afs.ext"

tstamp "AFS Installation Guide page 2-15"
tstamp "file server process binaries (get the third tar set from server)"

TAPESET=set3.tar.Z
LOCAL=${afsimagedir}/${TAPESET}
REMOTE=${afsimagedir}/${TAPESET}
if [ "${afsimageserver}" != "${HOSTNAME}" ]; then
	doit "tftp -g ${LOCAL} ${afsimageserver} ${REMOTE} image"
fi

cd /usr/afs
doit "pwd"
doit "compress -d <${LOCAL} | tar xvf -"

if [ ${retcode} != 0 ]; then
	fatal "problem un-tar-ing tapeset ${TAPESET}"
fi

tstamp "AFS Installation Guide page 2-17"
tstamp "Set up AFS partitions"

for i in ${afspartitions}
do
	vg=`echo ${i} | awk -F: '{print $1}'`
	name=`echo ${i} | awk -F: '{print $2}'`
	size=`echo ${i} | awk -F: '{print $3}'`
	let sizeblocks=${size}\*8192
	doit "crfs -v jfs -g${vg} -a size=${sizeblocks} -m${name} -Ayes -prw"
	doit "chfs -a mount=true ${name}"
	doit "chfs -ulocalfs ${name}"
	doit "mount ${name}"
done

tstamp "AFS Installation Guide page 2-19"
tstamp "Virtual file system entry for AFS /etc/vfs?"
fgrep afs /etc/vfs > /dev/null
if [ $? = 0 ]; then
	tstamp "We already have AFS entry in /etc/vfs"
else
	  tstamp "Adding AFS entry to /etc/vfs..."
	  echo \
"afs     4       none                    none                    remote"\
	  >> /etc/vfs
fi

tstamp "AFS Installation Guide page 2-20"
tstamp "Replacing AIX fsck with AFS fsck"
echo "NB NEVER run standard fsck on an AFS fileserver. It discards AFS volumes."
doit "cd /sbin/helpers; mv v3fshelper v3fshelper.noafs"
doit "cp /usr/afs/bin/v3fshelper /sbin/helpers/v3fshelper"

tstamp "AFS Installation Guide page 5-16"
tstamp "Setup /etc/rc.afs"
doit "mk-afs-rc"

tstamp "Add a call to /etc/rc.afs in /etc/inittab unless it's already there"

egrep "^rcafs:" /etc/inittab > /dev/null
if [ $? != 0 ]; then
	tstamp "Changing /etc/inittab to start AFS..."
	sed '/rctcpip/a\
rcafs:2:wait:/etc/rc.afs > /dev/console 2>&1  \# Start AFS Daemons' \
	/etc/inittab > /etc/inittab.new
	doit "mv /etc/inittab /etc/inittab.bak"
	doit "mv /etc/inittab.new /etc/inittab"
	doit "chmod 600 /etc/inittab"
	doit "fgrep rcafs /etc/inittab"
fi

tstamp "AFS Installation Guide page 2-24"

doit "echo ${afslicense} >/usr/afs/etc/License"
doit "/usr/afs/bin/bosserver -noauth &"
doit "sleep 60; # wait for bosserver to startup"
doit "/usr/afsws/bin/bos status ${HOST}"

if [ -L /usr/vice ]; then
	doit "ls -ld /usr/vice"
else
	doit "ln -s /usr/afs /usr/vice"
fi

doit "ls -ltr /usr/vice/etc"
doit "cat /usr/vice/etc/License"
doit "cat /usr/vice/etc/ThisCell; echo; # echo throws newline"
doit "cat /usr/vice/etc/CellServDB"

tstamp "define AFS cell name and cell membership"

cd /usr/afs/bin
doit "bos setcellname -server ${HOSTNAME} -name ${afscellname}"
if [ ${retcode} != 0 ]; then
	fatal "failed to setcellname"
fi
doit "bos listhosts ${HOSTNAME}"

doit "cat /usr/vice/etc/ThisCell; echo; # echo throws newline"
doit "cat /usr/vice/etc/CellServDB"

tstamp "AFS Installation Guide page 2-26"
tstamp "Starting Authentication Server"
doit "bos create ${HOSTNAME} kaserver simple /usr/afs/bin/kaserver -cell ${afscellname}"

kas create afs ${afspasswd} -cell ${afscellname} <<eeooff
 
eeooff

kas create admin ${adminpasswd} -cell ${afscellname} <<eeooff
 
eeooff

tstamp "AFS Installation Guide page 2-28"
tstamp "kas setfields admin -flags admin -cell ${afscellname}"
kas setfields admin -flags admin -cell ${afscellname} <<eeooff
 
eeooff

tstamp "kas examine admin -cell ${afscellname}"
kas examine admin -cell ${afscellname} <<eeooff
 
eeooff

doit "bos adduser ${HOSTNAME} admin -cell ${afscellname}"
tstamp "bos addkey ${HOSTNAME} -key \${afspasswd} -kvno 0 -cell ${afscellname}"
bos addkey ${HOSTNAME} -key ${afspasswd} -kvno 0 -cell ${afscellname}

tstamp "kas examine afs"
kas examine afs <<eeooff
 
eeooff

doit "bos listkeys ${HOSTNAME} -cell ${afscellname}"

tstamp "AFS Installation guide page 2-30, section 2.11"

tstamp "Starting the Protection Server"
doit "bos create ${HOSTNAME} ptserver simple /usr/afs/bin/ptserver -cell ${afscellname}"

cat <<eeooff
From Transarc's AFS Installation Guide page 2-30:
" Messages may appear periodically on your console, indicating that AFS's
distributed database technology, Ubik, is electing a quorum (quorum election
is necessary even with a single server). Wait a few minutes after the last
message, to guarantee that the Protection Server is ready to execute requests."

eeooff

doit "${afs_install_base}/usr/local/sbin/mk-afs-boswait \
	-v \"7002 Protection Server\" \"7004 Kerberos Server\""

doit "/usr/afsws/bin/bos status ${HOST}"

doit "pts createuser -name admin -cell ${afscellname}"
doit "pts add admin system:administrators -cell ${afscellname}"
doit "pts membership system:administrators -cell ${afscellname}"

tstamp "AFS Installation Guide page 2-32"
tstamp "Starting the Volume Location Server"
doit "bos create ${HOSTNAME} vlserver simple /usr/afs/bin/vlserver \
	-cell ${afscellname}"

tstamp "AFS Installation Guide page 2-33"
tstamp "Starting the Backup Server"
doit "bos create ${HOSTNAME} buserver simple /usr/afs/bin/buserver \
	-cell ${afscellname}"

tstamp "AFS Installation Guide page 2-34"
tstamp "Starting the File Server, Volume Server, and Salvager"

doit "bos create ${HOSTNAME} fs fs /usr/afs/bin/fileserver \
	/usr/afs/bin/volserver /usr/afs/bin/salvager -cell ${afscellname}"

cat <<eeooff
From Transarc's AFS Installation Guide page 2-34:
"You may see a message regarding the initialization of the VLDB and a few
error messages of the form:

fsync_clientinit failed (will sleep and retry): connection refused

These messages appear because volserver process cannot start operation
until the fileserver process initializes. Initialization can take a while,
especially if you already have a large number of existing AFS files. Wait a
few minutes after the last such message, to guarantee that both component
processes have started successfully."

eeooff

doit "${afs_install_base}/usr/local/sbin/mk-afs-boswait -v"

doit "bos status ${HOSTNAME} -long"

doit "vos create ${HOSTNAME} /vicepa root.afs -cell ${afscellname}"

tstamp "Starting the Server Portion of the Update Server"
doit "bos create ${HOSTNAME} upserver simple \
	\"/usr/afs/bin/upserver clear /usr/afs/bin\" -cell ${afscellname}"

tstamp "Starting the Controller for NTPD"
tstamp "bos create ${HOSTNAME} runntp simple \
	\"/usr/afs/bin/runntp -localclock ${afstimeservers}\""
bos create ${HOSTNAME} runntp simple \
	"/usr/afs/bin/runntp -localclock ${afstimeservers}"

cd /usr/afs/bin
doit "pwd"

tstamp "AFS Installation Guide page 2-40"

tstamp "Instead of rebooting the system, merely restart bosserver"
doit "bos restart ${HOST} -bosserver"
doit "${afs_install_base}/usr/local/sbin/mk-afs-boswait -v; #wait for quorum etc"

tstamp "AFS Installation Guide. page 2-41"
cd /usr/afs/bin
doit "pwd"
doit "/usr/afsws/bin/bos status ${HOST}"
doit "echo \"\" >/usr/afs/local/NoAuth"

tstamp "Loading Client Files on the First AFS Machine"

doit "rm /usr/vice"
doit "mkdir -p /usr/vice/etc"

# Get the fourth tar set from server

tstamp "AFS Installation Guide, page 2-43"

TAPESET=set4.tar.Z
LOCAL=${afsimagedir}/${TAPESET}
REMOTE=${afsimagedir}/${TAPESET}
if [ "${afsimageserver}" != "${HOSTNAME}" ]; then
	doit "tftp -g ${LOCAL} ${afsimageserver} ${REMOTE} image"
fi

cd /usr/vice/etc
doit "pwd"
doit "compress -d <${LOCAL} | tar xvf -"
if [ ${retcode} != 0 ]; then
	fatal "problem un-tar-ing tapeset ${TAPESET}"
fi

doit "rm -rf /usr/vice/etc/dkload"
doit "ln -s /usr/afs/bin/dkload /usr/vice/etc/dkload"

tstamp "AFS Installation Guide, page 2-46"

doit "echo ${afscellname} >/usr/vice/etc/ThisCell"

tstamp "setup /usr/vice/etc/CellServDB"
LOCAL=${afsimagefs}/CellServDB.export
REMOTE=${afsimagefs}/CellServDB.export
if [ "${afsimageserver}" != "${HOSTNAME}" ]; then
	doit "tftp -g ${LOCAL} ${afsimageserver} ${REMOTE} image"
fi

IPADDR=`host ${HOSTNAME} | awk '{print $3}'`
cat <<eeooff >/usr/vice/etc/CellServDB
>${afscellname}		#${afscellcomment}
${IPADDR}		#${HOSTNAME}
eeooff

doit "cat ${LOCAL} >>/usr/vice/etc/CellServDB"

tstamp "Setting Up the Cache"

if [ -z "${afsmemcache}" ]; then	# using disk memory cache
	let cacheblocks=${afscachesize}\*8192

doit "crfs -v jfs -grootvg -a size=${cacheblocks} -m${afscachename} -Ayes -prw"
	doit "chfs -a mount=true ${afscachename}"
	doit "chfs -ulocalfs ${afscachename}"
	doit "mount ${afscachename}"
	doit "df ${afscachename}"
fi

tstamp "AFS Installation Guide, page 2-49"

# Compute a value for the cache size to save in /usr/vice/etc/cacheinfo
# For AIX 3.2 the size should be 80% of the filesystem size.
#
# In /usr/vice/cacheinfo, the cachesize is expressed in kilobytes.
# From qhost, afscachesize is in PP, there are 4096 KB in a PP:

let cachesize=\(\(${afscachesize}\*4096\)\*80\)/100

doit "echo /afs:${afscachename}:${cachesize} >/usr/vice/etc/cacheinfo"

tstamp "Creating /afs and Starting the Cache Manager"

doit "mkdir /afs"
doit "ls /afs"

tstamp "AFS Installation Guide, page 2-52"

doit "/usr/vice/etc/afsd ${afsdoptions}"

doit "/usr/afsws/bin/bos status ${HOST} -long"

tstamp "/usr/afs/bin/klog -principal admin -password \${adminpasswd}"

/usr/afs/bin/klog -principal admin -password ${adminpasswd}

if [ $? != 0 ]; then
	fatal "failed to klog"
fi

doit "/usr/afs/bin/tokens"
doit "/usr/afs/bin/fs checkvolumes"

tstamp "Setting Up the Top levels of the AFS tree"
tstamp "AFS Installation Guide, page 2-57"

doit "fs sa /afs system:anyuser rl"
if [ ${retcode} != 0 ]; then
	fatal "failed to set ACL on /afs"
fi

doit "vos create ${HOSTNAME} ${partition} root.cell -cell ${afscellname}"
doit "fs mkm /afs/${afscellname} root.cell"
doit "fs sa /afs/${afscellname} system:anyuser rl"

# Compute short form name in /afs/${afscellname}
# Eg: afscellname of "aixssc.uk.ibm.com" => short form name of "aixssc"

X=`echo ${afscellname} | awk -F. '{print $1}'`
if [ ! -z "${X}" ]; then
	tstamp "Create short form name, ${X}, for ${afscellname} in /afs"
	doit "cd /afs && ln -s ${afscellname} ${X}"
	doit "ls /afs"
else
	warning "Unable to compute short form name from: ${afscellname}"
fi

doit "fs mkm /afs/.${afscellname} root.cell -rw"

tstamp "AFS Installation Guide page 2-59"
doit "vos addsite ${HOSTNAME} ${partition} root.afs"
doit "vos addsite ${HOSTNAME} ${partition} root.cell"

doit "fs examine /afs"
doit "fs examine /afs/${afscellname}"

doit "vos release root.afs"
doit "vos release root.cell"

doit "fs checkvolumes"
doit "fs examine /afs"
doit "fs examine /afs/${afscellname}"

tstamp "Turn on Authorization Checking"
tstamp "AFS Installation Guide, page 2-61"

doit "tokens"
doit "bos setauth ${HOSTNAME} on -cell ${afscellname}"
doit "bos restart ${HOSTNAME} -bosserver -cell ${afscellname}"

doit "${afs_install_base}/usr/local/sbin/mk-afs-boswait -v"
doit "bos status ${HOSTNAME}"

tstamp "AFS Installation Guide page 2-62"
tstamp "Setting up Volumes to House AFS Binaries"

cd /usr/afs/bin

doit "vos create ${HOSTNAME} ${partition} ${sysname}"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr.afsws"

doit "fs mkmount /afs/.${afscellname}/${sysname} ${sysname}"
doit "fs mkmount /afs/.${afscellname}/${sysname}/usr ${sysname}.usr"
doit "fs mkmount /afs/.${afscellname}/${sysname}/usr/afsws ${sysname}.usr.afsws"
doit "vos release root.cell"
doit "fs checkvolumes"

doit "fs sa -dir /afs/${afscellname}/${sysname} -acl system:anyuser rl"

let size=${afswsfssize}*4096
doit "fs setquota /afs/${afscellname}/${sysname}/usr/afsws ${size}"

tstamp "Load AFS Binaries into a Volume and Create a Link to the Local Disk"
tstamp "AFS Installation Guide, page 2-64"

doit "cp -r /usr/afsws/* /afs/${afscellname}/${sysname}/usr/afsws"

tstamp "AFS Installation Guide page 2-65"

X=/afs/${afscellname}/${sysname}/usr/afsws
doit "fs sa -dir ${X} -acl system:anyuser rl"
doit "fs sa -dir ${X}/* -acl system:authuser rl system:anyuser none"
doit "fs sa -dir ${X}/bin -acl system:anyuser rl"
doit "fs sa -dir ${X}/etc -acl system:anyuser rl"
doit "fs sa -dir /afs/${afscellname}/${sysname}/usr -acl system:anyuser rl"

doit "rm /usr/afsws"
doit "ln -s /afs/${afscellname}/@sys/usr/afsws /usr/afsws"

doit "lsvg ${afswsvg}"
doit "umount ${afswsfs} && rmfs ${afswsfs}"
doit "lsvg ${afswsvg}"

tstamp "AFS Installation Guide page 2-67"

doit "vos create ${HOSTNAME} ${partition} ${sysname}.bin"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.etc"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr.bin"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr.etc"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr.inc"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr.lib"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr.loc"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr.man"
doit "vos create ${HOSTNAME} ${partition} ${sysname}.usr.sys"

X=/afs/.${afscellname}/${sysname}

doit "fs mkmount ${X}/bin ${sysname}.bin"
doit "fs mkmount ${X}/etc ${sysname}.etc"
doit "fs mkmount ${X}/usr/bin ${sysname}.usr.bin"
doit "fs mkmount ${X}/usr/etc ${sysname}.usr.etc"
doit "fs mkmount ${X}/usr/include ${sysname}.usr.inc"
doit "fs mkmount ${X}/usr/lib ${sysname}.usr.lib"
doit "fs mkmount ${X}/usr/local ${sysname}.usr.loc"
doit "fs mkmount ${X}/usr/man ${sysname}.usr.man"
doit "fs mkmount ${X}/usr/sys ${sysname}.usr.sys"

doit "vos release root.cell"
doit "fs checkvolumes"

tstamp "Protecting Sensitive AFS Directories"
tstamp "AFS Installation Guide, page 2-74"

doit "chmod 755 /usr/afs"
doit "chmod 755 /usr/afs/bin"
doit "chmod 700 /usr/afs/db"
doit "chmod 755 /usr/afs/etc"
doit "chmod 600 /usr/afs/etc/KeyFile"
doit "chmod 600 /usr/afs/etc/UserList"
doit "chmod 700 /usr/afs/local"
doit "chmod 755 /usr/afs/logs"

case ${sysname} in
	rs_aix32 | rs_aix41)
		if [ -x /usr/afsws/bin/login.afs ]; then

# We only attempt this if we can access the AFS version of login (ouch!)

			tstamp "Replacing Login"
			tstamp "AFS Installation Guide, page 2-76"
			doit "mv /bin/login /bin/login.orig"
			doit "cp /usr/afsws/bin/login.noafs /bin/login"
			doit "mv /etc/getty /etc/getty.orig"
			doit "mv /etc/tsm /etc/tsm.orig"
			doit "ln -s /bin/login /etc/getty"
			doit "ln -s /bin/login /etc/tsm"
			doit "cp /usr/afsws/bin/login.afs /bin/login.afs"
			doit "ln -s /bin/login.afs /etc/afsok"
		fi
		;;
esac

X=${FCELLS}

if [ -x "${X}" ]; then
	tstamp "Enable Access to other Cells"
	tstamp "AFS Installation Guide, page 2-68"
	doit "${X}"
fi

# Any further local AFS setup is done in mk-afs-postinstall

if [ ! -z "${afspostinstall}" ]; then
	if [ -s "${afspostinstall}" ]; then
		tstamp "commenced ${afspostinstall}"
		. ${afspostinstall}
		tstamp "completed ${afspostinstall}"
	else
		warning "empty file: ${afspostinstall}"
	fi
fi

T=/tmp/${CMD}.mail.$$
cat <<eeooff >${T}
Greetings,
The initial AFS fileserver installation has completed on ${HOST}.
You will find a log of this process in:

        ${LOG}
--
Sincerely,
${CMD} program
eeooff
doit "mail -s \"${HOST}: ${CMD} completed\" ${NOTIFY} <${T}"
cat ${T}
rm ${T}

doit "/usr/afsws/bin/unlog; # Do not leave tokens hanging around!"
tstamp "completed"
