script revision 264449
1245702Snwhitehorn#!/bin/sh
2245702Snwhitehorn#-
3245702Snwhitehorn# Copyright (c) 2013 Nathan Whitehorn
4258421Sdteske# Copyright (c) 2013 Devin Teske
5245702Snwhitehorn# All rights reserved.
6245702Snwhitehorn#
7245702Snwhitehorn# Redistribution and use in source and binary forms, with or without
8245702Snwhitehorn# modification, are permitted provided that the following conditions
9245702Snwhitehorn# are met:
10245702Snwhitehorn# 1. Redistributions of source code must retain the above copyright
11245702Snwhitehorn#    notice, this list of conditions and the following disclaimer.
12245702Snwhitehorn# 2. Redistributions in binary form must reproduce the above copyright
13245702Snwhitehorn#    notice, this list of conditions and the following disclaimer in the
14245702Snwhitehorn#    documentation and/or other materials provided with the distribution.
15245702Snwhitehorn#
16245702Snwhitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17245702Snwhitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18245702Snwhitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19245702Snwhitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20245702Snwhitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21245702Snwhitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22245702Snwhitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23245702Snwhitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24245702Snwhitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25245702Snwhitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26245702Snwhitehorn# SUCH DAMAGE.
27245702Snwhitehorn#
28245702Snwhitehorn# $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/script 264449 2014-04-14 05:37:21Z dteske $
29258421Sdteske#
30258421Sdteske############################################################ INCLUDES
31245702Snwhitehorn
32258421SdteskeBSDCFG_SHARE="/usr/share/bsdconfig"
33258421Sdteske. $BSDCFG_SHARE/common.subr || exit 1
34258421Sdteskef_dprintf "%s: loading includes..." "$0"
35258421Sdteskef_include $BSDCFG_SHARE/dialog.subr
36258421Sdteskef_include $BSDCFG_SHARE/variable.subr
37258421Sdteske
38258421Sdteske############################################################ CONFIGURATION
39258421Sdteske
40245702Snwhitehorn# VARIABLES:
41245702Snwhitehorn# PARTITIONS
42245702Snwhitehorn# DISTRIBUTIONS
43245702Snwhitehorn# BSDINSTALL_DISTDIR
44245702Snwhitehorn
45258421Sdteske############################################################ GLOBALS
46258421Sdteske
47258421Sdteske#
48258421Sdteske# Strings that should be moved to an i18n file and loaded with f_include_lang()
49258421Sdteske#
50258421Sdteskemsg_installation_error="Installation Error!"
51258421Sdteske
52258421Sdteske############################################################ FUNCTIONS
53258421Sdteske
54258421Sdteskeerror()
55258421Sdteske{
56258421Sdteske	[ -f "$PATH_FSTAB" ] && bsdinstall umount
57258421Sdteske	
58258421Sdteske	local file
59258421Sdteske	f_getvar "$VAR_DEBUG_FILE#+" file
60258421Sdteske	if [ "$file" ]; then
61258421Sdteske		f_dialog_title "$msg_installation_error"
62258421Sdteske		f_dialog_textbox "$file"
63258421Sdteske		# No need to restore title, pining for the fjords
64258421Sdteske	fi
65258421Sdteske
66245702Snwhitehorn	exit 1
67245702Snwhitehorn}
68245702Snwhitehorn
69258421Sdteske############################################################ MAIN
70258421Sdteske
71245702Snwhitehornset -e
72245702Snwhitehorntrap error EXIT
73245702Snwhitehorn
74245702SnwhitehornSCRIPT="$1"
75245702Snwhitehornshift
76245702Snwhitehorn
77264449Sdteskef_dprintf "Began Installation at %s" "$( date )"
78245702Snwhitehornrm -rf $BSDINSTALL_TMPETC
79245702Snwhitehornmkdir $BSDINSTALL_TMPETC
80245702Snwhitehorn
81245702Snwhitehornsplit -a 2 -p '^#!.*' "$SCRIPT" /tmp/bsdinstall-installscript-
82245702Snwhitehorn
83245707Snwhitehorn. /tmp/bsdinstall-installscript-aa
84245702Snwhitehorn: ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS
85245702Snwhitehornexport BSDINSTALL_DISTDIR
86245702Snwhitehorn
87258421Sdteske# Re-initialize a new log if preamble changed BSDINSTALL_LOG
88258421Sdteskeif [ "$BSDINSTALL_LOG" != "${debugFile#+}" ]; then
89258421Sdteske	export debugFile="$BSDINSTALL_LOG"
90258421Sdteske	f_quietly f_debug_init
91258421Sdteske	# NB: Being scripted, let debug go to terminal for invalid debugFile
92258421Sdteske	f_dprintf "Began Instalation at %s" "$( date )"
93258421Sdteskefi
94258421Sdteske
95245702Snwhitehorn# Make partitions
96245702Snwhitehornrm -f $PATH_FSTAB
97245702Snwhitehorntouch $PATH_FSTAB
98245702Snwhitehornbsdinstall scriptedpart "$PARTITIONS"
99245702Snwhitehornbsdinstall mount
100245702Snwhitehorn
101245702Snwhitehorn# Unpack distributions
102245702Snwhitehornbsdinstall checksum
103245702Snwhitehornbsdinstall distextract
104245702Snwhitehorn
105245702Snwhitehorn# Finalize install
106245702Snwhitehornbsdinstall config
107245702Snwhitehorn
108246013Snwhitehorn# Make sure networking is functional, if we can arrange that
109246013Snwhitehornif [ ! -f $BSDINSTALL_CHROOT/etc/resolv.conf -a -f /etc/resolv.conf ]; then
110246013Snwhitehorn	cp /etc/resolv.conf $BSDINSTALL_CHROOT/etc/resolv.conf
111246013Snwhitehornfi
112246013Snwhitehorn
113245702Snwhitehorn# Run post-install script
114245702Snwhitehornif [ -f /tmp/bsdinstall-installscript-ab ]; then
115245702Snwhitehorn	cp /tmp/bsdinstall-installscript-ab $BSDINSTALL_CHROOT/tmp/installscript
116245702Snwhitehorn	chmod a+x $BSDINSTALL_CHROOT/tmp/installscript
117245702Snwhitehorn	mount -t devfs devfs "$BSDINSTALL_CHROOT/dev"
118245702Snwhitehorn	chroot $BSDINSTALL_CHROOT /tmp/installscript $@ 2>&1
119245702Snwhitehorn	umount "$BSDINSTALL_CHROOT/dev"
120245702Snwhitehorn	rm $BSDINSTALL_CHROOT/tmp/installscript
121245702Snwhitehornfi
122245702Snwhitehorn
123256340Sdesbsdinstall entropy
124245702Snwhitehornbsdinstall umount
125245702Snwhitehorn
126258421Sdteskef_dprintf "Installation Completed at %s" "$( date )"
127245702Snwhitehorn
128245702Snwhitehorntrap true EXIT
129258421Sdteske
130258421Sdteske################################################################################
131258421Sdteske# END
132258421Sdteske################################################################################
133