auto revision 271567
1218799Snwhitehorn#!/bin/sh 2218799Snwhitehorn#- 3218799Snwhitehorn# Copyright (c) 2011 Nathan Whitehorn 4257842Sdteske# Copyright (c) 2013 Devin Teske 5218799Snwhitehorn# All rights reserved. 6218799Snwhitehorn# 7218799Snwhitehorn# Redistribution and use in source and binary forms, with or without 8218799Snwhitehorn# modification, are permitted provided that the following conditions 9218799Snwhitehorn# are met: 10218799Snwhitehorn# 1. Redistributions of source code must retain the above copyright 11218799Snwhitehorn# notice, this list of conditions and the following disclaimer. 12218799Snwhitehorn# 2. Redistributions in binary form must reproduce the above copyright 13218799Snwhitehorn# notice, this list of conditions and the following disclaimer in the 14218799Snwhitehorn# documentation and/or other materials provided with the distribution. 15218799Snwhitehorn# 16218799Snwhitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17218799Snwhitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18218799Snwhitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19218799Snwhitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20218799Snwhitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21218799Snwhitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22218799Snwhitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23218799Snwhitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24218799Snwhitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25218799Snwhitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26218799Snwhitehorn# SUCH DAMAGE. 27218799Snwhitehorn# 28218799Snwhitehorn# $FreeBSD: head/usr.sbin/bsdinstall/scripts/auto 271567 2014-09-14 02:31:53Z nwhitehorn $ 29257842Sdteske# 30257842Sdteske############################################################ INCLUDES 31218799Snwhitehorn 32257842SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 33257842Sdteske. $BSDCFG_SHARE/common.subr || exit 1 34218799Snwhitehorn 35257842Sdteske############################################################ FUNCTIONS 36257842Sdteske 37218799Snwhitehornerror() { 38269653Sthompsa local msg 39269653Sthompsa if [ -n "$1" ]; then 40269653Sthompsa msg="$1\n\n" 41269653Sthompsa fi 42220088Snwhitehorn test -n "$DISTDIR_IS_UNIONFS" && umount -f $BSDINSTALL_DISTDIR 43220088Snwhitehorn test -f $PATH_FSTAB && bsdinstall umount 44218799Snwhitehorn dialog --backtitle "FreeBSD Installer" --title "Abort" \ 45218799Snwhitehorn --no-label "Exit" --yes-label "Restart" --yesno \ 46269653Sthompsa "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0 47218799Snwhitehorn if [ $? -ne 0 ]; then 48225637Snwhitehorn exit 1 49218799Snwhitehorn else 50218799Snwhitehorn exec $0 51218799Snwhitehorn fi 52218799Snwhitehorn} 53218799Snwhitehorn 54257842Sdteske############################################################ MAIN 55218799Snwhitehorn 56257842Sdteskef_dprintf "Began Installation at %s" "$( date )" 57257842Sdteske 58218799Snwhitehornrm -rf $BSDINSTALL_TMPETC 59218799Snwhitehornmkdir $BSDINSTALL_TMPETC 60218799Snwhitehorn 61218799Snwhitehorntrap true SIGINT # This section is optional 62218799Snwhitehornbsdinstall keymap 63218799Snwhitehorn 64218799Snwhitehorntrap error SIGINT # Catch cntrl-C here 65269653Sthompsabsdinstall hostname || error "Set hostname failed" 66218799Snwhitehorn 67219615Snwhitehornexport DISTRIBUTIONS="base.txz kernel.txz" 68219615Snwhitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then 69242188Sdteske DISTMENU=`awk -F'\t' '!/^(kernel|base)/{print $4,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST` 70218947Snwhitehorn 71219615Snwhitehorn exec 3>&1 72241902Sdteske EXTRA_DISTS=$( eval dialog \ 73241902Sdteske --backtitle \"FreeBSD Installer\" \ 74241902Sdteske --title \"Distribution Select\" --nocancel --separate-output \ 75241902Sdteske --checklist \"Choose optional system components to install:\" \ 76241902Sdteske 0 0 0 $DISTMENU \ 77241902Sdteske 2>&1 1>&3 ) 78219615Snwhitehorn for dist in $EXTRA_DISTS; do 79219615Snwhitehorn export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" 80219615Snwhitehorn done 81219615Snwhitehornfi 82218947Snwhitehorn 83218799SnwhitehornFETCH_DISTRIBUTIONS="" 84218799Snwhitehornfor dist in $DISTRIBUTIONS; do 85218799Snwhitehorn if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then 86218799Snwhitehorn FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" 87218799Snwhitehorn fi 88218799Snwhitehorndone 89220080SnwhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS` # Trim white space 90218799Snwhitehorn 91220080Snwhitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then 92218799Snwhitehorn 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 93218799Snwhitehorn bsdinstall netconfig || error 94218799Snwhitehorn NETCONFIG_DONE=yes 95218799Snwhitehornfi 96218799Snwhitehorn 97220088Snwhitehornif [ -n "$FETCH_DISTRIBUTIONS" ]; then 98220080Snwhitehorn exec 3>&1 99220834Snwhitehorn BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3) 100220080Snwhitehorn MIRROR_BUTTON=$? 101220080Snwhitehorn exec 3>&- 102269653Sthompsa test $MIRROR_BUTTON -eq 0 || error "No mirror selected" 103220080Snwhitehorn export BSDINSTALL_DISTSITE 104220080Snwhitehornfi 105220080Snwhitehorn 106259572Sdteskerm -f $PATH_FSTAB 107218799Snwhitehorntouch $PATH_FSTAB 108218799Snwhitehorn 109256343SdteskePMODES="\ 110271553Snwhitehorn\"Auto (UFS)\" \"Guided Disk Setup\" \ 111271553SnwhitehornManual \"Manual Disk Setup (experts)\" \ 112256343SdteskeShell \"Open a shell and partition by hand\"" 113218799Snwhitehorn 114256343SdteskeCURARCH=$( uname -m ) 115256343Sdteskecase $CURARCH in 116256343Sdteske amd64|i386) # Booting ZFS Supported 117271567Snwhitehorn PMODES="$PMODES \"Auto (ZFS)\" \"Guided Root-on-ZFS\"" 118256343Sdteske ;; 119256343Sdteske *) # Booting ZFS Unspported 120256343Sdteske ;; 121256343Sdteskeesac 122256343Sdteske 123256343Sdteskeexec 3>&1 124256343SdteskePARTMODE=`echo $PMODES | xargs dialog --backtitle "FreeBSD Installer" \ 125256343Sdteske --title "Partitioning" \ 126256343Sdteske --menu "How would you like to partition your disk?" \ 127259570Sdteske 0 0 0 2>&1 1>&3` || exit 1 128256343Sdteskeexec 3>&- 129256343Sdteske 130256343Sdteskecase "$PARTMODE" in 131271553Snwhitehorn"Auto (UFS)") # Guided 132269653Sthompsa bsdinstall autopart || error "Partitioning error" 133269653Sthompsa bsdinstall mount || error "Failed to mount filesystem" 134218799Snwhitehorn ;; 135256343Sdteske"Shell") # Shell 136218799Snwhitehorn clear 137218799Snwhitehorn 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'." 138222425Snwhitehorn sh 2>&1 139218799Snwhitehorn ;; 140256343Sdteske"Manual") # Manual 141257842Sdteske if f_isset debugFile; then 142257842Sdteske # Give partedit the path to our logfile so it can append 143269653Sthompsa BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error" 144257842Sdteske else 145269653Sthompsa bsdinstall partedit || error "Partitioning error" 146257842Sdteske fi 147269653Sthompsa bsdinstall mount || error "Failed to mount filesystem" 148218799Snwhitehorn ;; 149271553Snwhitehorn"Auto (ZFS)") # ZFS 150269653Sthompsa bsdinstall zfsboot || error "ZFS setup failed" 151269653Sthompsa bsdinstall mount || error "Failed to mount filesystem" 152256343Sdteske ;; 153218799Snwhitehorn*) 154269653Sthompsa error "Unknown partitioning mode" 155218799Snwhitehorn ;; 156218799Snwhitehornesac 157218799Snwhitehorn 158218799Snwhitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then 159218799Snwhitehorn ALL_DISTRIBUTIONS="$DISTRIBUTIONS" 160218799Snwhitehorn 161218799Snwhitehorn # Download to a directory in the new system as scratch space 162219528Snwhitehorn BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist" 163269653Sthompsa mkdir -p "$BSDINSTALL_FETCHDEST" || error "Could not create directory $BSDINSTALL_FETCHDEST" 164218799Snwhitehorn 165218799Snwhitehorn export DISTRIBUTIONS="$FETCH_DISTRIBUTIONS" 166218799Snwhitehorn # Try to use any existing distfiles 167220088Snwhitehorn if [ -d $BSDINSTALL_DISTDIR ]; then 168220080Snwhitehorn DISTDIR_IS_UNIONFS=1 169223897Snwhitehorn mount_nullfs -o union "$BSDINSTALL_FETCHDEST" "$BSDINSTALL_DISTDIR" 170225637Snwhitehorn else 171225637Snwhitehorn export DISTRIBUTIONS="MANIFEST $ALL_DISTRIBUTIONS" 172218799Snwhitehorn export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST" 173218799Snwhitehorn fi 174218799Snwhitehorn 175225637Snwhitehorn export FTP_PASSIVE_MODE=YES 176269653Sthompsa bsdinstall distfetch || error "Failed to fetch distribution" 177218799Snwhitehorn export DISTRIBUTIONS="$ALL_DISTRIBUTIONS" 178218799Snwhitehornfi 179218799Snwhitehorn 180269653Sthompsabsdinstall checksum || error "Distribution checksum failed" 181269653Sthompsabsdinstall distextract || error "Distribution extract failed" 182269653Sthompsabsdinstall rootpass || error "Could not set root password" 183218799Snwhitehorn 184218799Snwhitehorntrap true SIGINT # This section is optional 185218799Snwhitehornif [ "$NETCONFIG_DONE" != yes ]; then 186218799Snwhitehorn bsdinstall netconfig # Don't check for errors -- the user may cancel 187218799Snwhitehornfi 188218799Snwhitehornbsdinstall time 189218799Snwhitehornbsdinstall services 190218799Snwhitehorn 191218799Snwhitehorndialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \ 192218799Snwhitehorn "Would you like to add users to the installed system now?" 0 0 && \ 193218799Snwhitehorn bsdinstall adduser 194218799Snwhitehorn 195218799Snwhitehornfinalconfig() { 196218799Snwhitehorn exec 3>&1 197218799Snwhitehorn REVISIT=$(dialog --backtitle "FreeBSD Installer" \ 198218799Snwhitehorn --title "Final Configuration" --no-cancel --menu \ 199228194Snwhitehorn "Setup of your FreeBSD system is nearly complete. You can now modify your configuration choices. After this screen, you will have an opportunity to make more complex changes using a shell." 0 0 0 \ 200226507Skensmith "Exit" "Apply configuration and exit installer" \ 201218799Snwhitehorn "Add User" "Add a user to the system" \ 202218799Snwhitehorn "Root Password" "Change root password" \ 203218799Snwhitehorn "Hostname" "Set system hostname" \ 204218799Snwhitehorn "Network" "Networking configuration" \ 205218799Snwhitehorn "Services" "Set daemons to run on startup" \ 206218799Snwhitehorn "Time Zone" "Set system timezone" \ 207228194Snwhitehorn "Handbook" "Install FreeBSD Handbook (requires network)" 2>&1 1>&3) 208218799Snwhitehorn exec 3>&- 209218799Snwhitehorn 210218799Snwhitehorn case "$REVISIT" in 211218799Snwhitehorn "Add User") 212218799Snwhitehorn bsdinstall adduser 213218799Snwhitehorn finalconfig 214218799Snwhitehorn ;; 215218799Snwhitehorn "Root Password") 216218799Snwhitehorn bsdinstall rootpass 217218799Snwhitehorn finalconfig 218218799Snwhitehorn ;; 219218799Snwhitehorn "Hostname") 220218799Snwhitehorn bsdinstall hostname 221218799Snwhitehorn finalconfig 222218799Snwhitehorn ;; 223218799Snwhitehorn "Network") 224218799Snwhitehorn bsdinstall netconfig 225218799Snwhitehorn finalconfig 226218799Snwhitehorn ;; 227218799Snwhitehorn "Services") 228218799Snwhitehorn bsdinstall services 229218799Snwhitehorn finalconfig 230218799Snwhitehorn ;; 231218799Snwhitehorn "Time Zone") 232218799Snwhitehorn bsdinstall time 233218799Snwhitehorn finalconfig 234218799Snwhitehorn ;; 235223897Snwhitehorn "Handbook") 236223897Snwhitehorn bsdinstall docsinstall 237223897Snwhitehorn finalconfig 238223897Snwhitehorn ;; 239218799Snwhitehorn esac 240218799Snwhitehorn} 241218799Snwhitehorn 242218799Snwhitehorn# Allow user to change his mind 243218799Snwhitehornfinalconfig 244218799Snwhitehorn 245218799Snwhitehorntrap error SIGINT # SIGINT is bad again 246269653Sthompsabsdinstall config || error "Failed to save config" 247218799Snwhitehorn 248218799Snwhitehornif [ ! -z "$BSDINSTALL_FETCHDEST" ]; then 249218799Snwhitehorn [ "$BSDINSTALL_FETCHDEST" != "$BSDINSTALL_DISTDIR" ] && \ 250218799Snwhitehorn umount "$BSDINSTALL_DISTDIR" 251218799Snwhitehorn rm -rf "$BSDINSTALL_FETCHDEST" 252218799Snwhitehornfi 253218799Snwhitehorn 254228194Snwhitehorndialog --backtitle "FreeBSD Installer" --title "Manual Configuration" \ 255271552Snwhitehorn --default-button no --yesno \ 256271552Snwhitehorn "The installation is now finished. Before exiting the installer, would you like to open a shell in the new system to make any final manual modifications?" 0 0 257228194Snwhitehornif [ $? -eq 0 ]; then 258228194Snwhitehorn clear 259232531Snwhitehorn mount -t devfs devfs "$BSDINSTALL_CHROOT/dev" 260228194Snwhitehorn echo This shell is operating in a chroot in the new system. \ 261228194Snwhitehorn When finished making configuration changes, type \"exit\". 262228194Snwhitehorn chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1 263228194Snwhitehornfi 264228194Snwhitehorn 265256338Sdesbsdinstall entropy 266256338Sdesbsdinstall umount 267256338Sdes 268257842Sdteskef_dprintf "Installation Completed at %s" "$( date )" 269218799Snwhitehorn 270257842Sdteske################################################################################ 271257842Sdteske# END 272257842Sdteske################################################################################ 273