xref: /freebsd/usr.sbin/bsdinstall/scripts/jail (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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
37: ${BSDDIALOG_OK=0}
38
39f_dprintf "Began Installation at %s" "$( date )"
40export BSDINSTALL_CHROOT=$1
41
42error() {
43	local msg
44	if [ -n "$1" ]; then
45		msg="$1\n\n"
46	fi
47	bsddialog --backtitle "$OSNAME Installer" --title "Abort" \
48	    --no-label "Exit" --yes-label "Restart" --yesno \
49	    "${msg}An installation step has been aborted. Would you like to restart the installation or exit the installer?" 0 0
50	if [ $? -ne $BSDDIALOG_OK ]; then
51		exit
52	else
53		exec $0 $BSDINSTALL_CHROOT
54	fi
55}
56
57rm -rf $BSDINSTALL_TMPETC
58mkdir $BSDINSTALL_TMPETC
59mkdir -p $1 || error "mkdir failed for $1"
60
61if [ -n "$SCRIPT" ]
62then
63        split -a 2 -p '^#!.*' "$SCRIPT" $TMPDIR/bsdinstall-installscript-
64        . $TMPDIR/bsdinstall-installscript-aa
65fi
66
67test ! -d $BSDINSTALL_DISTDIR && mkdir -p $BSDINSTALL_DISTDIR
68
69if [ ! -f $BSDINSTALL_DISTDIR/MANIFEST -a -z "$BSDINSTALL_DISTSITE" ]; then
70	exec 3>&1
71	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
72	MIRROR_BUTTON=$?
73	exec 3>&-
74	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
75	export BSDINSTALL_DISTSITE
76	fetch -o $BSDINSTALL_DISTDIR/MANIFEST $BSDINSTALL_DISTSITE/MANIFEST || error "Could not download $BSDINSTALL_DISTSITE/MANIFEST"
77fi
78
79: ${DISTRIBUTIONS="base.txz"}; export DISTRIBUTIONS
80if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then
81	DISTMENU=`cut -f 4,5,6 $BSDINSTALL_DISTDIR/MANIFEST | grep -v -e ^kernel -e ^base`
82
83    if [ ! "$nonInteractive" == "YES" ]
84    then
85	    exec 3>&1
86	    EXTRA_DISTS=$(echo $DISTMENU | xargs -o bsddialog \
87	        --backtitle "$OSNAME Installer" \
88	        --title "Distribution Select" --no-cancel --separate-output \
89	        --checklist "Choose optional system components to install:" \
90	        0 0 0 \
91	    2>&1 1>&3)
92	    for dist in $EXTRA_DISTS; do
93	    	export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz"
94	    done
95    fi
96fi
97
98FETCH_DISTRIBUTIONS=""
99for dist in $DISTRIBUTIONS; do
100	if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then
101		FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist"
102	fi
103done
104FETCH_DISTRIBUTIONS=`echo $FETCH_DISTRIBUTIONS`	# Trim white space
105
106if [ -n "$FETCH_DISTRIBUTIONS" -a -z "$BSDINSTALL_DISTSITE" ]; then
107	exec 3>&1
108	BSDINSTALL_DISTSITE=$(`dirname $0`/mirrorselect 2>&1 1>&3)
109	MIRROR_BUTTON=$?
110	exec 3>&-
111	test $MIRROR_BUTTON -eq 0 || error "No mirror selected"
112	export BSDINSTALL_DISTSITE
113fi
114
115if [ ! -z "$FETCH_DISTRIBUTIONS" ]; then
116	bsdinstall distfetch || error "Failed to fetch distribution"
117fi
118
119bsdinstall checksum || error "Distribution checksum failed"
120bsdinstall distextract || error "Distribution extract failed"
121
122if [ ! "$nonInteractive" == "YES" ]
123then
124    bsdinstall rootpass || error "Could not set root password"
125fi
126
127trap true SIGINT	# This section is optional
128
129if [ ! "$nonInteractive" == "YES" ]
130then
131bsdinstall services
132
133    bsddialog --backtitle "$OSNAME Installer" --title "Add User Accounts" --yesno \
134        "Would you like to add users to the installed system now?" 0 0 && \
135        bsdinstall adduser
136fi
137
138trap error SIGINT	# SIGINT is bad again
139bsdinstall config  || error "Failed to save config"
140cp /etc/resolv.conf $1/etc
141cp /etc/localtime $1/etc
142cp /var/db/zoneinfo $1/var/db
143
144# Run post-install script
145if [ -f $TMPDIR/bsdinstall-installscript-ab ]; then
146	cp $TMPDIR/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript
147	chmod a+x $BSDINSTALL_CHROOT/tmp/installscript
148	mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
149	chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1
150	umount "$BSDINSTALL_CHROOT/dev"
151	rm $BSDINSTALL_CHROOT/tmp/installscript
152fi
153
154bsdinstall entropy
155
156f_dprintf "Installation Completed at %s" "$(date)"
157exit $SUCCESS
158
159################################################################################
160# END
161################################################################################
162