#!/bin/sh #- # Copyright (c) 2013 Nathan Whitehorn # Copyright (c) 2013 Devin Teske # Copyright (c) 2014 Kamil Czekirda # 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$ # ############################################################ INCLUDES BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 f_dprintf "%s: loading includes..." "$0" f_include $BSDCFG_SHARE/dialog.subr f_include $BSDCFG_SHARE/variable.subr ############################################################ CONFIGURATION # VARIABLES: # PARTITIONS # DISTRIBUTIONS # BSDINSTALL_DISTDIR # MIRROR default: : ${MIRROR:=ftp://ftp.freebsd.org} # RELEASE default: : ${RELEASE:=10.1} # HOSTNAME if not exist, don't set # KEYMAP if not exist, don't set # DAEMONS if not exist, don't set # TIMEZONE # INTERFACE (em0, bge0) # IPV4 (default: YES) : ${IPV4:=YES} # DHCP (default: YES) : ${DHCP:=YES} # ADDRESSV4 # NETMASK # GWV4 # DOMAIN # DNS1 # DNS2 # IPV6 (default: NO) : ${IPV6:=NO} # SLAAC (default: YES) : ${SLAAC:=YES} # ADDRESSV6 # PREFIXV6 : ${PREFIXV6:=64} # GWV6 # DNS3 # DNS4 # ROOTPWHASH # USERSCONFIG ############################################################ GLOBALS # # Strings that should be moved to an i18n file and loaded with f_include_lang() # msg_installation_error="Installation Error!" ############################################################ FUNCTIONS error() { [ -f "$PATH_FSTAB" ] && bsdinstall umount local file f_getvar "$VAR_DEBUG_FILE#+" file if [ "$file" ]; then f_dialog_title "$msg_installation_error" f_dialog_textbox "$file" # No need to restore title, pining for the fjords fi exit 1 } ############################################################ MAIN set -e trap error EXIT SCRIPT="$1" shift f_dprintf "Began Installation at %s" "$( date )" split -a 2 -p '^#!.*' "$SCRIPT" /tmp/bsdinstall-installscript- if [ -f /tmp/bsdinstall-installscript-ab ]; then mv /tmp/bsdinstall-installscript-ab /tmp/bsdinstall-installscript fi . /tmp/bsdinstall-installscript-aa : ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS export BSDINSTALL_DISTDIR # Re-initialize a new log if preamble changed BSDINSTALL_LOG if [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then export debugFile="$BSDINSTALL_LOG" f_quietly f_debug_init # NB: Being scripted, let debug go to terminal for invalid debugFile f_dprintf "Began Instalation at %s" "$( date )" fi ############################################################ DEVICE PREPARING # Make partitions rm -f $PATH_FSTAB touch $PATH_FSTAB if [ "$ZFSBOOT" = "YES" ]; then bsdinstall zfsboot /tmp/bsdinstall-installscript-aa else bsdinstall scriptedpart "$PARTITIONS" fi bsdinstall mount ############################################################ INSTALLATION # Build mirror path if [ "$RELEASE" = "11.0" ]; then RELDIR="snapshots" RELEASE="$RELEASE-CURRENT" else RELDIR="releases" RELEASE="$RELEASE-RELEASE" fi MIRROR=$(echo "$MIRROR" | sed 's/\/$//') BSDINSTALL_DISTSITE="$MIRROR/pub/FreeBSD/$RELDIR/$UNAME_M/$UNAME_P/$RELEASE" export BSDINSTALL_DISTSITE # Fetch distributions # disabled # Unpack distributions bsdinstall checksum bsdinstall distextract ############################################################ CONFIGURATION # Hostname if [ -n "$HOSTNAME" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi echo "echo hostname=\\\"$HOSTNAME\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab fi # Keymap if [ -n "$KEYMAP" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi echo "echo keymap=\\\"$KEYMAP\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab fi # Services havedump= if [ -n "$DAEMONS" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi fi for daemon in $DAEMONS; do [ "$daemon" = "dumpdev" ] && havedump=1 continue echo "echo ${daemon}_enable=\\\"YES\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab done if [ "$havedump" ]; then echo "echo dumpdev=\\\"AUTO\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab else echo "echo dumpdev=\\\"NO\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab fi # Time zone if [ -n "$TIMEZONE" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi echo "tzsetup \"$TIMEZONE\"" >> /tmp/bsdinstall-installscript-ab fi # Root password hash if [ -n "$ROOTPWHASH" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi echo "echo '$ROOTPWHASH' | pw user mod root -H 0" >> /tmp/bsdinstall-installscript-ab fi # Root password plaintext if [ -n "$ROOTPWPLAIN" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi echo "echo '$ROOTPWPLAIN' | pw user mod root -h 0" >> /tmp/bsdinstall-installscript-ab fi # Users if [ -n "$USERSCONFIG" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi echo "adduser -f $USERSCONFIG" >> /tmp/bsdinstall-installscript-ab fi # Network if [ -n "$INTERFACE" ] && [ "$IPV4" = "YES" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi if [ "$DHCP" = "YES" ]; then echo "echo ifconfig_${INTERFACE}=\\\"DHCP\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab fi if [ "$DHCP" = "NO" ]; then echo "echo \"ifconfig_${INTERFACE}=\\\"inet $ADDRESSV4 netmask $NETMASK\\\"\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab echo "echo defaultrouter=\\\"$GWV4\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab fi fi if [ -n "$INTERFACE" ] && [ "$IPV6" = "YES" ]; then if [ ! -f /tmp/bsdinstall-installscript-ab ]; then echo "#!/bin/sh" > /tmp/bsdinstall-installscript-ab fi echo "echo ipv6_enable=\\\"YES\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab if [ "$SLAAC" = "YES" ]; then echo "echo ifconfig_${INTERFACE}_ipv6=\\\"inet6 accept_rtadv\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab fi if [ "$SLAAC" = "NO" ]; then echo "echo \"ifconfig_${INTERFACE}_ipv6=\\\"ineti6 $ADDRESSV6\\\"\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab echo "echo ipv6_defaultrouter=\\\"$GWV6\\\" >> /etc/rc.conf" >> /tmp/bsdinstall-installscript-ab fi fi # Resolver if [ "$DOMAIN" ]; then echo "echo domain $DOMAIN >> /etc/resolv.conf" >> /tmp/bsdinstall-installscript-ab fi if [ "$DNS1" ]; then echo "echo nameserver $DNS1 >> /etc/resolv.conf" >> /tmp/bsdinstall-installscript-ab fi if [ "$DNS2" ]; then echo "echo nameserver $DNS2 >> /etc/resolv.conf" >> /tmp/bsdinstall-installscript-ab fi if [ "$DNS3" ]; then echo "echo nameserver $DNS3 >> /etc/resolv.conf" >> /tmp/bsdinstall-installscript-ab fi if [ "$DNS4" ]; then echo "echo \"nameserver $DNS4\" >> /etc/resolv.conf" >> /tmp/bsdinstall-installscript-ab fi # Finalize install cat $BSDINSTALL_TMPBOOT/loader.conf.* >> $BSDINSTALL_TMPBOOT/loader.conf rm $BSDINSTALL_TMPBOOT/loader.conf.* df -t zfs $BSDINSTALL_CHROOT > /dev/null && echo "zfs_load=\"YES\"" >> $BSDINSTALL_TMPBOOT/loader.conf cp $BSDINSTALL_TMPBOOT/* $BSDINSTALL_CHROOT/boot [ "${debugFile#+}" ] && cp "${debugFile#+}" $BSDINSTALL_CHROOT/var/log/ echo "/usr/bin/newaliases" >> /tmp/bsdinstall-installscript-ab # Run post-install script if [ -f /tmp/bsdinstall-installscript-ab ]; then if [ -f /tmp/bsdinstall-installscript ]; then echo "rm /etc/rc.local" >> /tmp/bsdinstall-installscript echo "mv /etc/rc.script /etc/rc.local" >> /tmp/bsdinstall-installscript-ab else echo "rm /etc/rc.local" >> /tmp/bsdinstall-installscript-ab fi echo "reboot" >> /tmp/bsdinstall-installscript-ab cp /tmp/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/etc/rc.local cp /tmp/bsdinstall-installscript $BSDINSTALL_CHROOT/etc/rc.script chmod a+x $BSDINSTALL_CHROOT/etc/rc.local rm /tmp/bsdinstall-installscript-ab fi ############################################################ CONFIGURATION END bsdinstall entropy [ -z "$ZFSBOOT" ] && bsdinstall umount f_dprintf "Installation Completed at %s" "$( date )" trap true EXIT ################################################################################ # END ################################################################################