From owner-svn-soc-all@freebsd.org Fri Oct 16 19:12:16 2015 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8B124A165A5 for ; Fri, 16 Oct 2015 19:12:16 +0000 (UTC) (envelope-from kczekirda@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 700CA1602 for ; Fri, 16 Oct 2015 19:12:16 +0000 (UTC) (envelope-from kczekirda@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id t9GJCGRJ098650 for ; Fri, 16 Oct 2015 19:12:16 GMT (envelope-from kczekirda@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id t9GJCFY7098641 for svn-soc-all@FreeBSD.org; Fri, 16 Oct 2015 19:12:15 GMT (envelope-from kczekirda@FreeBSD.org) Date: Fri, 16 Oct 2015 19:12:15 GMT Message-Id: <201510161912.t9GJCFY7098641@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to kczekirda@FreeBSD.org using -f From: kczekirda@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r292495 - in soc2014/kczekirda/pxe-fai-head/head: . usr.sbin usr.sbin/bsdinstall usr.sbin/bsdinstall/scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Oct 2015 19:12:16 -0000 Author: kczekirda Date: Fri Oct 16 19:12:15 2015 New Revision: 292495 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=292495 Log: bsdinstall fai init - rework of architecture Added: soc2014/kczekirda/pxe-fai-head/head/ soc2014/kczekirda/pxe-fai-head/head/usr.sbin/ soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/ soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/ soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/script (contents, props changed) Added: soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/script ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/script Fri Oct 16 19:12:15 2015 (r292495) @@ -0,0 +1,334 @@ +#!/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 + +BSDINSTALL_FETCHDEST="$BSDINSTALL_CHROOT/usr/freebsd-dist" +export BSDINSTALL_DISTDIR="$BSDINSTALL_FETCHDEST" +echo "$BSDINSTALL_FETCHDEST" +mkdir -p "$BSDINSTALL_FETCHDEST" + +export FTP_PASSIVE_MODE=YES +bsdinstall distfetch + +# 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 +################################################################################