xref: /freebsd/usr.sbin/bsdinstall/scripts/jail (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
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# $FreeBSD$
29#
30############################################################ INCLUDES
31
32BSDCFG_SHARE="/usr/share/bsdconfig"
33. $BSDCFG_SHARE/common.subr || exit 1
34
35############################################################ MAIN
36
37f_dprintf "Began Installation at %s" "$( date )"
38export BSDINSTALL_CHROOT=$1
39
40error() {
41	local msg
42	if [ -n "$1" ]; then
43		msg="$1\n\n"
44	fi
45	dialog --backtitle "FreeBSD Installer" --title "Abort" \
46	    --no-label "Exit" --yes-label "Restart" --yesno \
47	    "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
48	if [ $? -ne 0 ]; then
49		exit
50	else
51		exec $0 $BSDINSTALL_CHROOT
52	fi
53}
54
55
56rm -rf $BSDINSTALL_TMPETC
57mkdir $BSDINSTALL_TMPETC
58mkdir -p $1 || error "mkdir failed for $1"
59
60test ! -d $BSDINSTALL_DISTDIR && mkdir -p $BSDINSTALL_DISTDIR
61
62if [ ! -f $BSDINSTALL_DISTDIR/MANIFEST -a -z "$BSDINSTALL_DISTSITE" ]; then
63	exec 3>&1
64	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
65	MIRROR_BUTTON=$?
66	exec 3>&-
67	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
68	export BSDINSTALL_DISTSITE
69	fetch -o $BSDINSTALL_DISTDIR/MANIFEST $BSDINSTALL_DISTSITE/MANIFEST || error "Could not download $BSDINSTALL_DISTSITE/MANIFEST"
70fi
71
72export DISTRIBUTIONS="base.txz"
73if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
74	DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base`
75
76	exec 3>&1
77	EXTRA_DISTS=$(echo $DISTMENU | xargs dialog \
78	    --backtitle "FreeBSD Installer" \
79	    --title "Distribution Select" --nocancel --separate-output \
80	    --checklist "Choose optional system components to install:" \
81	    0 0 0 \
82	2>&1 1>&3)
83	for dist in $EXTRA_DISTS; do
84		export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
85	done
86fi
87
88FETCH_DISTRIBUTIONS=""
89for dist in $DISTRIBUTIONS; do
90	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
91		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
92	fi
93done
94FETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
95
96if [ -n "$FETCH_DISTRIBUTIONS" -a -z "$BSDINSTALL_DISTSITE" ]; then
97	exec 3>&1
98	BSDINSTALL_DISTSITE=`bsdinstall mirrorselect 2>&1 1>&3`
99	MIRROR_BUTTON=$?
100	exec 3>&-
101	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
102	export BSDINSTALL_DISTSITE
103fi
104
105if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
106	bsdinstall distfetch || error "Failed to fetch distribution"
107fi
108
109bsdinstall checksum || error "Distribution checksum failed"
110bsdinstall distextract || error "Distribution extract failed"
111bsdinstall rootpass || error "Could not set root password"
112
113trap true SIGINT	# This section is optional
114bsdinstall services
115
116dialog --backtitle "FreeBSD Installer" --title "Add User Accounts" --yesno \
117    "Would you like to add users to the installed system now?" 0 0 && \
118    bsdinstall adduser
119
120trap error SIGINT	# SIGINT is bad again
121bsdinstall config  || error "Failed to save config"
122cp /etc/resolv.conf $1/etc
123cp /etc/localtime $1/etc
124
125bsdinstall entropy
126
127f_dprintf "Installation Completed at %s" "$(date)"
128exit $SUCCESS
129
130################################################################################
131# END
132################################################################################
133