freebsd-nq/usr.sbin/bsdinstall/scripts/auto
2011-05-28 16:15:46 +00:00

224 lines
6.9 KiB
Bash
Executable File

#!/bin/sh
#-
# Copyright (c) 2011 Nathan Whitehorn
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
echo "Begun Installation at $(date)" > $BSDINSTALL_LOG
error() {
test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR
test -f $PATH_FSTAB && bsdinstall umount
dialog --backtitle "FreeBSD Installer" --title "Abort" \
--no-label "Exit" --yes-label "Restart" --yesno \
"An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
if [ $? -ne 0 ]; then
exit
else
exec $0
fi
}
rm -rf $BSDINSTALL_TMPETC
mkdir $BSDINSTALL_TMPETC
trap true SIGINT # This section is optional
bsdinstall keymap
trap error SIGINT # Catch cntrl-C here
bsdinstall hostname || error
export DISTRIBUTIONS="base.txz kernel.txz"
if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base`
exec 3>&1
EXTRA_DISTS=$(echo $DISTMENU | xargs dialog \
--backtitle "FreeBSD Installer" \
--title "Distribution Select" --nocancel --separate-output \
--checklist "Choose optional system components to install:" \
0 0 0 \
2>&1 1>&3)
for dist in $EXTRA_DISTS; do
export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
done
fi
FETCH_DISTRIBUTIONS=""
for dist in $DISTRIBUTIONS; do
if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
fi
done
FETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS` # Trim white space
if [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then
dialog --backtitle "FreeBSD Installer" --title "Network Installation" --msgbox "No installation files were found on the boot volume. The next few screens will allow you to configure networking so that they can be downloaded from the Internet." 0 0
bsdinstall netconfig || error
NETCONFIG_DONE=yes
fi
if [ -n "$FETCH_DISTRIBUTIONS" ]; then
exec 3>&1
BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
MIRROR_BUTTON=$?
exec 3>&-
test $MIRROR_BUTTON -eq 0 || error
export BSDINSTALL_DISTSITE
fi
rm $PATH_FSTAB
touch $PATH_FSTAB
dialog --backtitle "FreeBSD Installer" --title "Partitioning" --extra-button \
--extra-label "Manual" --ok-label "Guided" --cancel-label "Shell" \
--yesno "Would you like to use the guided partitioning tool (recommended for beginners) or to set up partitions manually (experts)? You can also open a shell and set up partitions entirely by hand." 0 0
case $? in
0) # Guided
bsdinstall autopart || error
bsdinstall mount || error
;;
1) # Shell
clear
echo "Use this shell to set up partitions for the new system. When finished, mount the system at $BSDINSTALL_CHROOT and place an fstab file for the new system at $PATH_FSTAB. Then type 'exit'. You can also enter the partition editor at any time by entering 'bsdinstall partedit'."
sh 2>&1
;;
3) # Manual
bsdinstall partedit || error
bsdinstall mount || error
;;
*)
error
;;
esac
if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
ALL_DISTRIBUTIONS="$DISTRIBUTIONS"
# Download to a directory in the new system as scratch space
BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist"
mkdir -p "$BSDINSTALL_FETCHDEST" || error
export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS"
# Try to use any existing distfiles
if [ -d $BSDINSTALL_DISTDIR ]; then
DISTDIR_IS_UNIONFS=1
mount_unionfs "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR"
fi
# Otherwise, fetch everything
if [ $? -ne 0 ]; then
export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST"
fi
bsdinstall distfetch || error
export DISTRIBUTIONS="$ALL_DISTRIBUTIONS"
fi
bsdinstall checksum || error
bsdinstall distextract || error
bsdinstall rootpass || error
trap true SIGINT # This section is optional
if [ "$NETCONFIG_DONE" != yes ]; then
bsdinstall netconfig # Don't check for errors -- the user may cancel
fi
bsdinstall time
bsdinstall services
dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
"Would you like to add users to the installed system now?" 0 0 && \
bsdinstall adduser
finalconfig() {
exec 3>&1
REVISIT=$(dialog --backtitle "FreeBSD Installer" \
--title "Final Configuration" --no-cancel --menu \
"Setup of your FreeBSD system is nearly complete. You can now modify your configuration choices or apply more complex changes using a shell." 0 0 0 \
"Add User" "Add a user to the system" \
"Root Password" "Change root password" \
"Hostname" "Set system hostname" \
"Network" "Networking configuration" \
"Services" "Set daemons to run on startup" \
"Time Zone" "Set system timezone" \
"Shell" "Open a shell in the new system" \
"Exit" "Apply configuration and exit installer" 2>&1 1>&3)
exec 3>&-
case "$REVISIT" in
"Add User")
bsdinstall adduser
finalconfig
;;
"Root Password")
bsdinstall rootpass
finalconfig
;;
"Hostname")
bsdinstall hostname
finalconfig
;;
"Network")
bsdinstall netconfig
finalconfig
;;
"Services")
bsdinstall services
finalconfig
;;
"Time Zone")
bsdinstall time
finalconfig
;;
"Shell")
clear
echo This shell is operating in a chroot in the new system. \
When finished making configuration changes, type \"exit\".
chroot "$BSDINSTALL_CHROOT" /bin/sh
# Don't hose local rc.conf changes
cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual
finalconfig
;;
esac
}
# Allow user to change his mind
finalconfig
trap error SIGINT # SIGINT is bad again
bsdinstall config || error
if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then
[ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \
umount "$BSDINSTALL_DISTDIR"
rm -rf "$BSDINSTALL_FETCHDEST"
fi
echo "Installation Completed at $(date)" >> $BSDINSTALL_LOG