#!/bin/ksh -
#
# @(#)mk-afs-bundle	1.10 (hursley) 11/6/96
# /afs/hursley.ibm.com/common/src/afs/@cell/rs_aix32/usr/local/sbin/mk-afs-bundle/SCCS/s.mk-afs-bundle
#
# NAME		mk-afs-bundle
# AUTHOR	Paul Blackburn                http://acm.org/~mpb
# PURPOSE	Create compressed tar archives from /usr/afsws ready for
#		other afs_install scripts (eg mk-afs-cli, mk-afs-srv).
#               These compressed tar archives are used to do network
#		installs of AFS servers and clients.
#
# USAGE		Find a temporary directory with lots of freespace (~20MB)
#		cd /usr/afsws; mk-afs-bundle /tmp/lots_of_freespace
#
# HISTORY	Now uses $afs_install_base so that install scripts
#		can be executed from arbitary directory
# SOURCE
#		ftp://ftp.transarc.com/pub/afs-contrib/tools/afs_install/

X=${afs_install_base}/usr/local/sbin/mk-afs-cf

if [[ ! -f ${X} ]]; then
	echo "${X} not found - fatal error" >&2
	exit 1
fi

# We don't need to check for the AFSCF file
export nocfcheck="true"

# We don't need to check we are root
export norootcheck="true"

# source global config for AFS installation

. ${X}

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

if [[ -z "${1}" ]]; then
	warning "You failed to specify a directory. Here is a hint:"
	echo
	echo "\tcrfs -v jfs -g rootvg -a size=49152 -m /vol/afs34 -A yes -p rw"
	echo "\tmount /vol/afs34"
	echo "\tcp /usr/vice/etc/CellServDB /vol/afs34/CellServDB.export"
	echo "\tmkdir -p /vol/afs34/tapeimages/${sysname}"
	echo
	echo "\tcd /usr/afsws"
	echo "\t${CMD} /vol/afs34/tapeimages/${sysname}"
	echo
	fatal "aborted"
fi

dir="${1}"
if [[ ! -d "${dir}" ]]; then
	fatal "not a directory: ${dir}"
fi

need=20480
fs=${dir}
tstamp "Check we have enough (${need} kbytes) free space in /${fs}"
need_freespace ${fs} ${need}
if [[ $? -eq 0 ]]; then
	tstamp "Yes! we have enough room in ${fs} to proceed."
else
	warning "There is not enough free space in ${fs}."
	fatal "Unable to proceed. We need ${need} kbytes free in ${fs}"
fi

base=$(pwd)

dirsneeded="
root.client/usr/vice/etc
root.server/usr/afs
root.client/usr/vice/etc
"

for i in ${dirsneeded}; do
	if [[ ! -d ${i} ]]; then
		fatal "missing directory: ${base}/${i}"
	fi
done

# probably OK to proceed...

cd root.client/usr/vice/etc
tstamp "cd root.client/usr/vice/etc"
doit "tar cvf - dkload | compress > ${dir}/set1.tar.Z"
cd ${base}
tstamp "cd ${base}"

cd root.server/usr/afs
tstamp "cd root.server/usr/afs"
doit "tar cvf - bin local | compress > ${dir}/set3.tar.Z"
cd ${base}
tstamp "cd ${base}"

cd root.client/usr/vice/etc
tstamp "cd root.client/usr/vice/etc"
doit "tar cvf - * | compress > ${dir}/set4.tar.Z"
cd ${base}
tstamp "cd ${base}"

doit "tar cvf - * | compress > ${dir}/set5.tar.Z"
cd ${base}
tstamp "cd ${base}"

doit "du -ks ${dir}"
doit "ls -s ${dir}/*"

T=/tmp/${CMD}.mail.$$
cat <<eeooff >${T}
Greetings,
The AFS network install images have been created in:
    ${dir}

These files are used by the afs_install scripts (mk-afs-srv, mk-afs-cli).

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}

tstamp "completed"
