12118f387SNathan Whitehorn#!/bin/sh 22118f387SNathan Whitehorn#- 32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn 40705286bSDevin Teske# Copyright (c) 2013-2015 Devin Teske 52118f387SNathan Whitehorn# All rights reserved. 62118f387SNathan Whitehorn# 72118f387SNathan Whitehorn# Redistribution and use in source and binary forms, with or without 82118f387SNathan Whitehorn# modification, are permitted provided that the following conditions 92118f387SNathan Whitehorn# are met: 102118f387SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright 112118f387SNathan Whitehorn# notice, this list of conditions and the following disclaimer. 122118f387SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright 132118f387SNathan Whitehorn# notice, this list of conditions and the following disclaimer in the 142118f387SNathan Whitehorn# documentation and/or other materials provided with the distribution. 152118f387SNathan Whitehorn# 162118f387SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 172118f387SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 182118f387SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 192118f387SNathan Whitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 202118f387SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 212118f387SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 222118f387SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 232118f387SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 242118f387SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 252118f387SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 262118f387SNathan Whitehorn# SUCH DAMAGE. 272118f387SNathan Whitehorn# 28bc4a673fSDevin Teske# 29bc4a673fSDevin Teske############################################################ INCLUDES 302118f387SNathan Whitehorn 31bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 32bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 33bc4a673fSDevin Teske 34bc4a673fSDevin Teske############################################################ MAIN 35bc4a673fSDevin Teske 364effc388SAlfonso S. Siciliano: ${BSDDIALOG_OK=0} 374effc388SAlfonso S. Siciliano 38bc4a673fSDevin Teskef_dprintf "Began Installation at %s" "$( date )" 392118f387SNathan Whitehorn 402118f387SNathan Whitehornerror() { 417041a67eSAndrew Thompson local msg 427041a67eSAndrew Thompson if [ -n "$1" ]; then 437041a67eSAndrew Thompson msg="$1\n\n" 447041a67eSAndrew Thompson fi 45cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" --title "Abort" \ 462118f387SNathan Whitehorn --no-label "Exit" --yes-label "Restart" --yesno \ 477041a67eSAndrew Thompson "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0 484effc388SAlfonso S. Siciliano if [ $? -ne $BSDDIALOG_OK ]; then 492118f387SNathan Whitehorn exit 502118f387SNathan Whitehorn else 5101ab86f7SPierre Pronchery [ -z "$MIRROR_BUTTON" ] || unset BSDINSTALL_DISTSITE 52e7c52918SNathan Whitehorn exec $0 $BSDINSTALL_CHROOT 532118f387SNathan Whitehorn fi 542118f387SNathan Whitehorn} 552118f387SNathan Whitehorn 56b9cf9892SFernando Apesteguíaif [ -z "$1" ]; then 57b9cf9892SFernando Apesteguía error "Directory can not be empty\n\nUsage:\nbsdinstall jail directory" 58b9cf9892SFernando Apesteguíafi 59b9cf9892SFernando Apesteguíaexport BSDINSTALL_CHROOT=$1 60b9cf9892SFernando Apesteguía 612118f387SNathan Whitehornrm -rf $BSDINSTALL_TMPETC 622118f387SNathan Whitehornmkdir $BSDINSTALL_TMPETC 637041a67eSAndrew Thompsonmkdir -p $1 || error "mkdir failed for $1" 64*731704f5SMichael Gmelinrm -f $TMPDIR/bsdinstall-installscript-setup 652118f387SNathan Whitehorn 66*731704f5SMichael Gmelinif [ -n "$SCRIPT" ]; then 67*731704f5SMichael Gmelin # split script into preamble and setup script at first shebang 68*731704f5SMichael Gmelin awk 'BEGIN {pathb=ARGV[2]; ARGV[2]=""} /^#!/{b=1} { 69*731704f5SMichael Gmelin if (b) print >pathb; else print}' \ 70*731704f5SMichael Gmelin "$SCRIPT" $TMPDIR/bsdinstall-installscript-setup \ 71*731704f5SMichael Gmelin >$TMPDIR/bsdinstall-installscript-preamble 72*731704f5SMichael Gmelin 73*731704f5SMichael Gmelin . $TMPDIR/bsdinstall-installscript-preamble 746f4c1456Seoli3nfi 756f4c1456Seoli3n 76e7c52918SNathan Whitehorntest ! -d $BSDINSTALL_DISTDIR && mkdir -p $BSDINSTALL_DISTDIR 77e7c52918SNathan Whitehorn 78e7c52918SNathan Whitehornif [ ! -f $BSDINSTALL_DISTDIR/MANIFEST -a -z "$BSDINSTALL_DISTSITE" ]; then 79c0e249d3SLars Kellogg-Stedman exec 5>&1 80c0e249d3SLars Kellogg-Stedman BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&5) 81e7c52918SNathan Whitehorn MIRROR_BUTTON=$? 82c0e249d3SLars Kellogg-Stedman exec 5>&- 837041a67eSAndrew Thompson test $MIRROR_BUTTON -eq 0 || error "No mirror selected" 84e7c52918SNathan Whitehorn export BSDINSTALL_DISTSITE 857041a67eSAndrew Thompson fetch -o $BSDINSTALL_DISTDIR/MANIFEST $BSDINSTALL_DISTSITE/MANIFEST || error "Could not download $BSDINSTALL_DISTSITE/MANIFEST" 86e7c52918SNathan Whitehornfi 87e7c52918SNathan Whitehorn 886f4c1456Seoli3n: ${DISTRIBUTIONS="base.txz"}; export DISTRIBUTIONS 89e7c52918SNathan Whitehornif [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then 90e7c52918SNathan Whitehorn DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base` 91e7c52918SNathan Whitehorn 926f4c1456Seoli3n if [ ! "$nonInteractive" == "YES" ] 936f4c1456Seoli3n then 94c0e249d3SLars Kellogg-Stedman exec 5>&1 954effc388SAlfonso S. Siciliano EXTRA_DISTS=$(echo $DISTMENU | xargs -o bsddialog \ 96cc42ef53SBrad Davis --backtitle "$OSNAME Installer" \ 974effc388SAlfonso S. Siciliano --title "Distribution Select" --no-cancel --separate-output \ 98e7c52918SNathan Whitehorn --checklist "Choose optional system components to install:" \ 99e7c52918SNathan Whitehorn 0 0 0 \ 100c0e249d3SLars Kellogg-Stedman 2>&1 1>&5) 101e7c52918SNathan Whitehorn for dist in $EXTRA_DISTS; do 102e7c52918SNathan Whitehorn export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" 103e7c52918SNathan Whitehorn done 104e7c52918SNathan Whitehorn fi 1056f4c1456Seoli3nfi 1062118f387SNathan Whitehorn 1072118f387SNathan WhitehornFETCH_DISTRIBUTIONS="" 1082118f387SNathan Whitehornfor dist in $DISTRIBUTIONS; do 1092118f387SNathan Whitehorn if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then 1102118f387SNathan Whitehorn FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" 1112118f387SNathan Whitehorn fi 1122118f387SNathan Whitehorndone 113e7c52918SNathan WhitehornFETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS` # Trim white space 1142118f387SNathan Whitehorn 115e7c52918SNathan Whitehornif [ -n "$FETCH_DISTRIBUTIONS" -a -z "$BSDINSTALL_DISTSITE" ]; then 116c0e249d3SLars Kellogg-Stedman exec 5>&1 117c0e249d3SLars Kellogg-Stedman BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&5) 118e7c52918SNathan Whitehorn MIRROR_BUTTON=$? 119c0e249d3SLars Kellogg-Stedman exec 5>&- 1207041a67eSAndrew Thompson test $MIRROR_BUTTON -eq 0 || error "No mirror selected" 121e7c52918SNathan Whitehorn export BSDINSTALL_DISTSITE 1222118f387SNathan Whitehornfi 1232118f387SNathan Whitehorn 124e7c52918SNathan Whitehornif [ ! -z "$FETCH_DISTRIBUTIONS" ]; then 1257041a67eSAndrew Thompson bsdinstall distfetch || error "Failed to fetch distribution" 126e7c52918SNathan Whitehornfi 127e7c52918SNathan Whitehorn 1287041a67eSAndrew Thompsonbsdinstall checksum || error "Distribution checksum failed" 1297041a67eSAndrew Thompsonbsdinstall distextract || error "Distribution extract failed" 1306f4c1456Seoli3n 1316f4c1456Seoli3nif [ ! "$nonInteractive" == "YES" ] 1326f4c1456Seoli3nthen 1337041a67eSAndrew Thompson bsdinstall rootpass || error "Could not set root password" 1346f4c1456Seoli3nfi 1352118f387SNathan Whitehorn 1362118f387SNathan Whitehorntrap true SIGINT # This section is optional 1376f4c1456Seoli3n 1386f4c1456Seoli3nif [ ! "$nonInteractive" == "YES" ] 1396f4c1456Seoli3nthen 1402118f387SNathan Whitehornbsdinstall services 1412118f387SNathan Whitehorn 142cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" --title "Add User Accounts" --yesno \ 1432118f387SNathan Whitehorn "Would you like to add users to the installed system now?" 0 0 && \ 1442118f387SNathan Whitehorn bsdinstall adduser 1456f4c1456Seoli3nfi 1462118f387SNathan Whitehorn 1472118f387SNathan Whitehorntrap error SIGINT # SIGINT is bad again 1487041a67eSAndrew Thompsonbsdinstall config || error "Failed to save config" 149e7c52918SNathan Whitehorncp /etc/resolv.conf $1/etc 150e7c52918SNathan Whitehorncp /etc/localtime $1/etc 1516ce785c5SJose Luis Durancp /var/db/zoneinfo $1/var/db 1522118f387SNathan Whitehorn 1536f4c1456Seoli3n# Run post-install script 154*731704f5SMichael Gmelinif [ -f $TMPDIR/bsdinstall-installscript-setup ]; then 155*731704f5SMichael Gmelin cp $TMPDIR/bsdinstall-installscript-setup \ 156*731704f5SMichael Gmelin $BSDINSTALL_CHROOT/tmp/installscript 1576f4c1456Seoli3n chmod a+x $BSDINSTALL_CHROOT/tmp/installscript 1586f4c1456Seoli3n mount -t devfs devfs "$BSDINSTALL_CHROOT/dev" 1596f4c1456Seoli3n chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1 1606f4c1456Seoli3n umount "$BSDINSTALL_CHROOT/dev" 1616f4c1456Seoli3n rm $BSDINSTALL_CHROOT/tmp/installscript 1626f4c1456Seoli3nfi 1636f4c1456Seoli3n 164dfc23ba5SDag-Erling Smørgravbsdinstall entropy 165dfc23ba5SDag-Erling Smørgrav 166bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$(date)" 1670705286bSDevin Teskeexit $SUCCESS 1682118f387SNathan Whitehorn 169bc4a673fSDevin Teske################################################################################ 170bc4a673fSDevin Teske# END 171bc4a673fSDevin Teske################################################################################ 172