#! /bin/sh
#
# nbinstall - no brain install - install FreeBSD 8.x using zfs with little
# human interaction needed. -bw- 2011-02-23
#
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/root/bin
#
# set the name of the program
#
MYNAME=`basename $0`
#
# our domain name - should come from config file at some point -bw-
#
DOMAIN="isprime.com"
#
# how many cpus do we have so we can run parallel make later
#
CPUNUM=`sysctl kern.smp.cpus | cut -f 2 -d\ `
#
# the on CD core os image is missing man pages. Grab them from
# a local web server
#
MANURL="http://sabre.tekhq.com/fbsd82/manpages.tgz"
#
# url to grab tarball of packages we want on a base install
PKGURL="http://sabre.tekhq.com/fbsd82/i-packages.tar"
PKGTAR="i-packages.tar"
#
# make sure everyone can see it
#
export PATH MYNAME DOMAIN
#
# find what disks we have attached and set up arguments to zfsinstall for disks
#
DISKARG=`sysctl kern.disks | cut -d: -f2 | sed -e 's/ / -d /g'`
#
# how many disks do we have - this is how we decide between mirror and raidz
#
DCOUNT=`echo ${DISKARG} | wc -w `
#
# strip out the count of -d arguments so we know exactly how many disks we have
#
DCOUNT=`expr $DCOUNT / 2`
if [ $DCOUNT -lt 3 ]
then
RAID="mirror"
else
RAID="raidz"
fi
#
# check for mounted cdrom - mount if needed
#
mount | grep /cdrom 2>&1 >/dev/null
if [ $? -ne 0 ]
then
mount -t cd9660 /dev/acd0 /cdrom
if [ $? -ne 0 ]
then
echo
echo "$MYNAME: can not mount install media - nothing done!"
echo
exit 1
fi
fi
#
# get our hostname
#
while [ x$RAWHOST = x ]
do
echo
echo -n "Please enter the short hostname (no domain part): "
read RAWHOST
done
#
# make sure to strip off domain if the operator included it
# we need to do this because we will use this as our zfs pool name
#
COOKEDHOST=`echo $RAWHOST | cut -f1 -d.`
while [ x$DOIT != xyes ]
do
echo
echo "I am about to create a new FreeBSD 8.2 system with"
echo "the hostname ${COOKEDHOST}.${DOMAIN} and ZFS ${RAID} on pool ${COOKEDHOST}."
echo
echo -n "Shall I continue? (yes/no) "
read DOIT
if [ x$DOIT = xno ]
then
echo
echo "$MYNAME: Install aborted by user. Nothing done!"
echo
exit 1
fi
done
hostname ${COOKEDHOST}.${DOMAIN}
POOL=${COOKEDHOST}
export POOL
zfsinstall ${DISKARG} -r ${RAID} -p ${POOL} -t /cdrom/8.2-RELEASE-amd64.tar.xz
#
# we do not want the messages from zfsinstall showing....need to
# modify zfsinstall at some point
#
clear
echo "Setting up additional ZetaByte Filesystems."
echo "Please stand by."
#
# now create other zfs file systems we need
#
# we might have to put some of this into zfsinstall.....need to check
# -bw- 2011-04-27
#
zfs create -p ${POOL}/other/home
zfs set mountpoint=/home ${POOL}/other/home
zfs create -p ${POOL}/other/ports
zfs set mountpoint=/usr/ports ${POOL}/other/ports
zfs create -p ${POOL}/other/local
zfs set mountpoint=/usr/local ${POOL}/other/local
zfs create -p ${POOL}/other/local/isp
zfs set mountpoint=/usr/local/isp ${POOL}/other/local/isp
zfs create -p ${POOL}/root/var/tmp
#zfs create -p ${POOL}/root/var/db
zfs create -p ${POOL}/root/var/mail
#zfs create -p ${POOL}/root/var/spool
zfs create -p ${POOL}/other/www
zfs set mountpoint=/www ${POOL}/other/www
#
# make some things noexec and nosuid
#
for DIR in /var/mail
do
zfs set exec=off ${POOL}/root${DIR}
zfs set setuid=off ${POOL}/root${DIR}
done
for DIR in /tmp /var /var/tmp
do
zfs set setuid=off ${POOL}/root${DIR}
done
chroot /mnt sysinstall tcpMenuSelect
echo
echo "Setting up /etc/rc.conf"
echo
#
# now put other important stuff into /etc/rc.conf
#
cat << EOF >> /mnt/etc/rc.conf
accounting_enable="YES"
sendmail_enable="NO"
ntpdate_flags="tick.isprime.com"
ntpdate_enable="YES"
ntpd_enable="YES"
sshd_enable="YES"
tcp_extensions="YES"
collectd_enable="YES"
EOF
echo
echo "Installing man pages"
echo
cd /mnt/tmp
fetch -o - $MANURL | tar xpvf -
#
# now install the manpages we just grabbed
#
chroot /mnt /bin/sh -c "cd /tmp/manpages ; /bin/sh -x install.sh"
#
# now get the most current ports tree
#
chroot /mnt portsnap fetch
chroot /mnt portsnap extract
#
#
# grab prebuilt packages from web server and install them.
#
cd /mnt/tmp
fetch $PKGURL
cd /mnt/usr/ports
tar xpvf /mnt/tmp/$PKGTAR
for PKG in `ls /mnt/usr/ports/packages/All`
do
chroot /mnt /bin/sh -c "cd /usr/ports/packages/All ; pkg_add -v $PKG"
done
echo
echo "Setting up sudoers....."
echo
cp /mnt/usr/local/etc/sudoers /mnt/usr/local/etc/sudoers.DIST
sed -e 's/^# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/g' /mnt/usr/local/etc/sudoers.DIST > /mnt/usr/local/etc/sudoers
#
# set up collectd config file
#
if [ -f /mnt/usr/local/etc/collectd.conf ]
then
mv /mnt/usr/local/etc/collectd.conf /mnt/usr/local/etc/collectd.conf-dist
fi
cat << EOF > /mnt/usr/local/etc/collectd.conf
BaseDir "/var/db/collectd"
PIDFile "/var/run/collectd.pid"
FQDNLookup true
ReadThreads 8
LoadPlugin apache
LoadPlugin cpu
LoadPlugin df
LoadPlugin disk
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin network
URL "http://localhost/isp-status?auto"
SecurityLevel Sign
Username "isprime"
Password "TredLokhi"
MaxPacketSize 1024
ReportStats true
CacheFlush 1800
EOF
echo "Setting up /etc/sysctl.conf"
cat << EOF >> /mnt/etc/sysctl.conf
#
# big webserver tweeks below
#
net.inet.icmp.icmplim=2000
net.inet.tcp.syncookies=0
net.inet.tcp.keepinit=10000
kern.ipc.shmmax=409600000
kern.ipc.maxsockbuf=1048576
kern.ipc.somaxconn=65535
net.inet.tcp.sendspace=65535
net.inet.tcp.recvspace=65535
net.inet.udp.recvspace=65535
net.inet.tcp.mssdflt=1460
net.inet.tcp.mssdflt=1460
net.inet.tcp.slowstart_flightsize=4
net.inet.tcp.inflight.enable=0
vm.pmap.shpgperproc=800
net.inet.tcp.sendbuf_max=16777216
net.inet.tcp.recvbuf_max=16777216
kern.ipc.maxsockbuf=4000000
#
# not in fbsd 8.2 generic
#
kern.polling.burst_max=1000
kern.polling.idle_poll=0
kern.polling.each_burst=50
#
# end not in fbsd 8.2 generic
#
net.inet.tcp.sendbuf_inc=32768
net.inet.tcp.recvbuf_inc=524288
net.inet.ip.portrange.first=2048
#
# this helps nfs clients
#
vfs.nfs.iodmax=64
EOF
echo "Settingup /boot/loader.conf"
cat << EOF >> /boot/loader.conf
#
# network tunables below
net.inet.tcp.syncache.bucketlimit=900
net.inet.tcp.syncache.hashsize=1024
net.inet.tcp.syncache.cachelimit=184320
net.inet.tcp.tcbhashsize=16384
EOF
echo "Setting up cvsupfile"
cat << EOF > /mnt/etc/cvsupfile
#
# minimal cvsup file for world - use portsnap for ports
# -bw- 2011-04-27
#
*default host=cvsup5.freebsd.org
*default base=/var/db
*default prefix=/usr
*default release=cvs tag=RELENG_8_2
*default delete-rel-suffix
src-all
EOF
echo "Grabbing kernel and world sources"
chroot /mnt /usr/bin/csup -L2 -g /etc/cvsupfile
#
# set up /etc/hosts
#
mv /mnt/etc/hosts /mnt/etc/hosts.sample
cat << EOF > /mnt/etc/hosts
127.0.0.1 localhost.${DOMAIN} localhost
127.0.0.1 ${COOKEDHOST}.${DOMAIN} ${COOKEDHOST}
EOF
umount /cdrom
#
echo
echo "Initial install complete. Please remove the CDrom and reboot"
echo
exit 0