1#!/bin/sh 2#- 3# Copyright (c) 2011 Nathan Whitehorn 4# Copyright (c) 2013-2015 Devin Teske 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33 34############################################################ MAIN 35 36: ${BSDDIALOG_OK=0} 37 38f_dprintf "Began Installation at %s" "$( date )" 39export BSDINSTALL_CHROOT=$1 40 41error() { 42 local msg 43 if [ -n "$1" ]; then 44 msg="$1\n\n" 45 fi 46 bsddialog --backtitle "$OSNAME Installer" --title "Abort" \ 47 --no-label "Exit" --yes-label "Restart" --yesno \ 48 "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0 49 if [ $? -ne $BSDDIALOG_OK ]; then 50 exit 51 else 52 exec $0 $BSDINSTALL_CHROOT 53 fi 54} 55 56rm -rf $BSDINSTALL_TMPETC 57mkdir $BSDINSTALL_TMPETC 58mkdir -p $1 || error "mkdir failed for $1" 59 60if [ -n "$SCRIPT" ] 61then 62 split -a 2 -p '^#!.*' "$SCRIPT" $TMPDIR/bsdinstall-installscript- 63 . $TMPDIR/bsdinstall-installscript-aa 64fi 65 66test ! -d $BSDINSTALL_DISTDIR && mkdir -p $BSDINSTALL_DISTDIR 67 68if [ ! -f $BSDINSTALL_DISTDIR/MANIFEST -a -z "$BSDINSTALL_DISTSITE" ]; then 69 exec 3>&1 70 BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3) 71 MIRROR_BUTTON=$? 72 exec 3>&- 73 test $MIRROR_BUTTON -eq 0 || error "No mirror selected" 74 export BSDINSTALL_DISTSITE 75 fetch -o $BSDINSTALL_DISTDIR/MANIFEST $BSDINSTALL_DISTSITE/MANIFEST || error "Could not download $BSDINSTALL_DISTSITE/MANIFEST" 76fi 77 78: ${DISTRIBUTIONS="base.txz"}; export DISTRIBUTIONS 79if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then 80 DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base` 81 82 if [ ! "$nonInteractive" == "YES" ] 83 then 84 exec 3>&1 85 EXTRA_DISTS=$(echo $DISTMENU | xargs -o bsddialog \ 86 --backtitle "$OSNAME Installer" \ 87 --title "Distribution Select" --no-cancel --separate-output \ 88 --checklist "Choose optional system components to install:" \ 89 0 0 0 \ 90 2>&1 1>&3) 91 for dist in $EXTRA_DISTS; do 92 export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" 93 done 94 fi 95fi 96 97FETCH_DISTRIBUTIONS="" 98for dist in $DISTRIBUTIONS; do 99 if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then 100 FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" 101 fi 102done 103FETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS` # Trim white space 104 105if [ -n "$FETCH_DISTRIBUTIONS" -a -z "$BSDINSTALL_DISTSITE" ]; then 106 exec 3>&1 107 BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3) 108 MIRROR_BUTTON=$? 109 exec 3>&- 110 test $MIRROR_BUTTON -eq 0 || error "No mirror selected" 111 export BSDINSTALL_DISTSITE 112fi 113 114if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then 115 bsdinstall distfetch || error "Failed to fetch distribution" 116fi 117 118bsdinstall checksum || error "Distribution checksum failed" 119bsdinstall distextract || error "Distribution extract failed" 120 121if [ ! "$nonInteractive" == "YES" ] 122then 123 bsdinstall rootpass || error "Could not set root password" 124fi 125 126trap true SIGINT # This section is optional 127 128if [ ! "$nonInteractive" == "YES" ] 129then 130bsdinstall services 131 132 bsddialog --backtitle "$OSNAME Installer" --title "Add User Accounts" --yesno \ 133 "Would you like to add users to the installed system now?" 0 0 && \ 134 bsdinstall adduser 135fi 136 137trap error SIGINT # SIGINT is bad again 138bsdinstall config || error "Failed to save config" 139cp /etc/resolv.conf $1/etc 140cp /etc/localtime $1/etc 141cp /var/db/zoneinfo $1/var/db 142 143# Run post-install script 144if [ -f $TMPDIR/bsdinstall-installscript-ab ]; then 145 cp $TMPDIR/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript 146 chmod a+x $BSDINSTALL_CHROOT/tmp/installscript 147 mount -t devfs devfs "$BSDINSTALL_CHROOT/dev" 148 chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1 149 umount "$BSDINSTALL_CHROOT/dev" 150 rm $BSDINSTALL_CHROOT/tmp/installscript 151fi 152 153bsdinstall entropy 154 155f_dprintf "Installation Completed at %s" "$(date)" 156exit $SUCCESS 157 158################################################################################ 159# END 160################################################################################ 161