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 34*9de72af2SPierre Pronchery############################################################ GLOBALS 35bc4a673fSDevin Teske 36*9de72af2SPierre Pronchery# 37*9de72af2SPierre Pronchery# List of environment variables that may be defined by the user, but modified 38*9de72af2SPierre Pronchery# during the installation process. They are then restored when restarting this 39*9de72af2SPierre Pronchery# script. 40*9de72af2SPierre Pronchery# 41*9de72af2SPierre Proncheryuser_env_vars="BSDINSTALL_DISTSITE DISTRIBUTIONS" 424effc388SAlfonso S. Siciliano 43*9de72af2SPierre Pronchery############################################################ FUNCTIONS 442118f387SNathan Whitehorn 45*9de72af2SPierre Pronchery# error [$msg] 46*9de72af2SPierre Pronchery# 47*9de72af2SPierre Pronchery# Display generic error message when a script fails. An optional message 48*9de72af2SPierre Pronchery# argument can preceed the generic message. User is given the choice of 49*9de72af2SPierre Pronchery# restarting the installer or exiting. 50*9de72af2SPierre Pronchery# 512118f387SNathan Whitehornerror() { 527041a67eSAndrew Thompson local msg 537041a67eSAndrew Thompson if [ -n "$1" ]; then 547041a67eSAndrew Thompson msg="$1\n\n" 557041a67eSAndrew Thompson fi 56cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" --title "Abort" \ 572118f387SNathan Whitehorn --no-label "Exit" --yes-label "Restart" --yesno \ 587041a67eSAndrew Thompson "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0 594effc388SAlfonso S. Siciliano if [ $? -ne $BSDDIALOG_OK ]; then 602118f387SNathan Whitehorn exit 612118f387SNathan Whitehorn else 62*9de72af2SPierre Pronchery environment_restore 63e7c52918SNathan Whitehorn exec $0 $BSDINSTALL_CHROOT 642118f387SNathan Whitehorn fi 652118f387SNathan Whitehorn} 662118f387SNathan Whitehorn 674daf244aSIsaac Freunddistbase() { 68e7c52918SNathan Whitehorn test ! -d $BSDINSTALL_DISTDIR && mkdir -p $BSDINSTALL_DISTDIR 69e7c52918SNathan Whitehorn 70e7c52918SNathan Whitehorn if [ ! -f $BSDINSTALL_DISTDIR/MANIFEST -a -z "$BSDINSTALL_DISTSITE" ]; then 71c0e249d3SLars Kellogg-Stedman exec 5>&1 72c0e249d3SLars Kellogg-Stedman BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&5) 73e7c52918SNathan Whitehorn MIRROR_BUTTON=$? 74c0e249d3SLars Kellogg-Stedman exec 5>&- 757041a67eSAndrew Thompson test $MIRROR_BUTTON -eq 0 || error "No mirror selected" 76e7c52918SNathan Whitehorn export BSDINSTALL_DISTSITE 777041a67eSAndrew Thompson fetch -o $BSDINSTALL_DISTDIR/MANIFEST $BSDINSTALL_DISTSITE/MANIFEST || error "Could not download $BSDINSTALL_DISTSITE/MANIFEST" 78e7c52918SNathan Whitehorn fi 79e7c52918SNathan Whitehorn 806f4c1456Seoli3n : ${DISTRIBUTIONS="base.txz"}; export DISTRIBUTIONS 81e7c52918SNathan Whitehorn if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then 82e7c52918SNathan Whitehorn DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base` 83e7c52918SNathan Whitehorn 846f4c1456Seoli3n if [ ! "$nonInteractive" == "YES" ] 856f4c1456Seoli3n then 86c0e249d3SLars Kellogg-Stedman exec 5>&1 874effc388SAlfonso S. Siciliano EXTRA_DISTS=$(echo $DISTMENU | xargs -o bsddialog \ 88cc42ef53SBrad Davis --backtitle "$OSNAME Installer" \ 894daf244aSIsaac Freund --title "Distribution Select" --no-cancel \ 904daf244aSIsaac Freund --separate-output \ 91e7c52918SNathan Whitehorn --checklist "Choose optional system components to install:" \ 92e7c52918SNathan Whitehorn 0 0 0 \ 93c0e249d3SLars Kellogg-Stedman 2>&1 1>&5) 94e7c52918SNathan Whitehorn for dist in $EXTRA_DISTS; do 95e7c52918SNathan Whitehorn export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" 96e7c52918SNathan Whitehorn done 97e7c52918SNathan Whitehorn fi 986f4c1456Seoli3n fi 992118f387SNathan Whitehorn 1002118f387SNathan Whitehorn FETCH_DISTRIBUTIONS="" 1012118f387SNathan Whitehorn for dist in $DISTRIBUTIONS; do 1022118f387SNathan Whitehorn if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then 1032118f387SNathan Whitehorn FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" 1042118f387SNathan Whitehorn fi 1052118f387SNathan Whitehorn done 106e7c52918SNathan Whitehorn FETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS` # Trim white space 1072118f387SNathan Whitehorn 108e7c52918SNathan Whitehorn if [ -n "$FETCH_DISTRIBUTIONS" -a -z "$BSDINSTALL_DISTSITE" ]; then 109c0e249d3SLars Kellogg-Stedman exec 5>&1 110c0e249d3SLars Kellogg-Stedman BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&5) 111e7c52918SNathan Whitehorn MIRROR_BUTTON=$? 112c0e249d3SLars Kellogg-Stedman exec 5>&- 1137041a67eSAndrew Thompson test $MIRROR_BUTTON -eq 0 || error "No mirror selected" 114e7c52918SNathan Whitehorn export BSDINSTALL_DISTSITE 1152118f387SNathan Whitehorn fi 1162118f387SNathan Whitehorn 117e7c52918SNathan Whitehorn if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then 1187041a67eSAndrew Thompson bsdinstall distfetch || error "Failed to fetch distribution" 119e7c52918SNathan Whitehorn fi 120e7c52918SNathan Whitehorn 1217041a67eSAndrew Thompson bsdinstall checksum || error "Distribution checksum failed" 1227041a67eSAndrew Thompson bsdinstall distextract || error "Distribution extract failed" 1234daf244aSIsaac Freund} 1244daf244aSIsaac Freund 125*9de72af2SPierre Pronchery# environment_restore 126*9de72af2SPierre Pronchery# 127*9de72af2SPierre Pronchery# Restore a list of environment variables when this script is restarted. 128*9de72af2SPierre Pronchery# 129*9de72af2SPierre Proncheryenvironment_restore() 130*9de72af2SPierre Pronchery{ 131*9de72af2SPierre Pronchery for var in $user_env_vars; do 132*9de72af2SPierre Pronchery eval "if [ -n \"\${ORIG_$var}\" -o -z \"\${ORIG_$var-z}\" ]; then $var=\${ORIG_$var}; else unset $var; fi" 133*9de72af2SPierre Pronchery done 134*9de72af2SPierre Pronchery} 135*9de72af2SPierre Pronchery 136*9de72af2SPierre Pronchery# environment_save 137*9de72af2SPierre Pronchery# 138*9de72af2SPierre Pronchery# Save any user-defined environment variable that may be modified during the 139*9de72af2SPierre Pronchery# installation process. They are then restored when restarting this script. 140*9de72af2SPierre Pronchery# 141*9de72af2SPierre Proncheryenvironment_save() 142*9de72af2SPierre Pronchery{ 143*9de72af2SPierre Pronchery for var in $user_env_vars; do 144*9de72af2SPierre Pronchery eval "if [ -n \"\${$var}\" -o -z \"\${$var-z}\" ]; then ORIG_$var=\${$var}; else unset ORIG_$var; fi" 145*9de72af2SPierre Pronchery done 146*9de72af2SPierre Pronchery} 147*9de72af2SPierre Pronchery 148*9de72af2SPierre Pronchery############################################################ MAIN 149*9de72af2SPierre Pronchery 150*9de72af2SPierre Pronchery: ${BSDDIALOG_OK=0} 151*9de72af2SPierre Pronchery 152*9de72af2SPierre Proncheryf_dprintf "Began Installation at %s" "$( date )" 153*9de72af2SPierre Pronchery 1544daf244aSIsaac Freundif [ -z "$1" ]; then 1554daf244aSIsaac Freund error "Directory can not be empty\n\nUsage:\nbsdinstall jail directory" 1564daf244aSIsaac Freundfi 1574daf244aSIsaac Freundexport BSDINSTALL_CHROOT=$1 1584daf244aSIsaac Freund 159*9de72af2SPierre Proncheryenvironment_save 160*9de72af2SPierre Pronchery 1614daf244aSIsaac Freundrm -rf $BSDINSTALL_TMPETC 1624daf244aSIsaac Freundmkdir $BSDINSTALL_TMPETC 1634daf244aSIsaac Freundmkdir -p $1 || error "mkdir failed for $1" 1644daf244aSIsaac Freundrm -f $TMPDIR/bsdinstall-installscript-setup 1654daf244aSIsaac Freund 1664daf244aSIsaac Freundif [ -n "$SCRIPT" ]; then 1674daf244aSIsaac Freund # split script into preamble and setup script at first shebang 1684daf244aSIsaac Freund awk 'BEGIN {pathb=ARGV[2]; ARGV[2]=""} /^#!/{b=1} { 1694daf244aSIsaac Freund if (b) print >pathb; else print}' \ 1704daf244aSIsaac Freund "$SCRIPT" $TMPDIR/bsdinstall-installscript-setup \ 1714daf244aSIsaac Freund >$TMPDIR/bsdinstall-installscript-preamble 1724daf244aSIsaac Freund 1734daf244aSIsaac Freund . $TMPDIR/bsdinstall-installscript-preamble 1744daf244aSIsaac Freundfi 1754daf244aSIsaac Freund 1764daf244aSIsaac Freundif [ ! "$nonInteractive" == "YES" ]; then 1774daf244aSIsaac Freund bsddialog --backtitle "$OSNAME Installer" --title "Select Installation Type" \ 1784daf244aSIsaac Freund --yes-label "Traditional" --no-label "Packages (Experimental)" --yesno \ 1794daf244aSIsaac Freund "Would you like to install the base system using traditional distribution sets or packages (experimental)?" 0 0 1804daf244aSIsaac Freund if [ $? -eq 1 ]; then 1814daf244aSIsaac Freund PKGBASE=yes 1824daf244aSIsaac Freund fi 1834daf244aSIsaac Freundfi 1844daf244aSIsaac Freund 1854daf244aSIsaac Freundif [ "$PKGBASE" == yes ]; then 1864daf244aSIsaac Freund bsdinstall pkgbase --no-kernel || error "Installation of base system packages failed" 1874daf244aSIsaac Freundelse 1884daf244aSIsaac Freund distbase 1894daf244aSIsaac Freundfi 1906f4c1456Seoli3n 1916f4c1456Seoli3nif [ ! "$nonInteractive" == "YES" ] 1926f4c1456Seoli3nthen 1937041a67eSAndrew Thompson bsdinstall rootpass || error "Could not set root password" 1946f4c1456Seoli3nfi 1952118f387SNathan Whitehorn 1962118f387SNathan Whitehorntrap true SIGINT # This section is optional 1976f4c1456Seoli3n 1986f4c1456Seoli3nif [ ! "$nonInteractive" == "YES" ] 1996f4c1456Seoli3nthen 2002118f387SNathan Whitehornbsdinstall services 2012118f387SNathan Whitehorn 202cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" --title "Add User Accounts" --yesno \ 2032118f387SNathan Whitehorn "Would you like to add users to the installed system now?" 0 0 && \ 2042118f387SNathan Whitehorn bsdinstall adduser 2056f4c1456Seoli3nfi 2062118f387SNathan Whitehorn 2072118f387SNathan Whitehorntrap error SIGINT # SIGINT is bad again 2087041a67eSAndrew Thompsonbsdinstall config || error "Failed to save config" 209e7c52918SNathan Whitehorncp /etc/resolv.conf $1/etc 210e7c52918SNathan Whitehorncp /etc/localtime $1/etc 2116ce785c5SJose Luis Durancp /var/db/zoneinfo $1/var/db 2122118f387SNathan Whitehorn 2136f4c1456Seoli3n# Run post-install script 214731704f5SMichael Gmelinif [ -f $TMPDIR/bsdinstall-installscript-setup ]; then 215731704f5SMichael Gmelin cp $TMPDIR/bsdinstall-installscript-setup \ 216731704f5SMichael Gmelin $BSDINSTALL_CHROOT/tmp/installscript 2176f4c1456Seoli3n chmod a+x $BSDINSTALL_CHROOT/tmp/installscript 2186f4c1456Seoli3n mount -t devfs devfs "$BSDINSTALL_CHROOT/dev" 2196f4c1456Seoli3n chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1 2206f4c1456Seoli3n umount "$BSDINSTALL_CHROOT/dev" 2216f4c1456Seoli3n rm $BSDINSTALL_CHROOT/tmp/installscript 2226f4c1456Seoli3nfi 2236f4c1456Seoli3n 224dfc23ba5SDag-Erling Smørgravbsdinstall entropy 225dfc23ba5SDag-Erling Smørgrav 226bc4a673fSDevin Teskef_dprintf "Installation Completed at %s" "$(date)" 2270705286bSDevin Teskeexit $SUCCESS 2282118f387SNathan Whitehorn 229bc4a673fSDevin Teske################################################################################ 230bc4a673fSDevin Teske# END 231bc4a673fSDevin Teske################################################################################ 232