1218799Snwhitehorn#!/bin/sh
2218799Snwhitehorn#-
3218799Snwhitehorn# Copyright (c) 2011 Nathan Whitehorn
4258421Sdteske# Copyright (c) 2013 Devin Teske
5218799Snwhitehorn# All rights reserved.
6218799Snwhitehorn#
7218799Snwhitehorn# Redistribution and use in source and binary forms, with or without
8218799Snwhitehorn# modification, are permitted provided that the following conditions
9218799Snwhitehorn# are met:
10218799Snwhitehorn# 1. Redistributions of source code must retain the above copyright
11218799Snwhitehorn#    notice, this list of conditions and the following disclaimer.
12218799Snwhitehorn# 2. Redistributions in binary form must reproduce the above copyright
13218799Snwhitehorn#    notice, this list of conditions and the following disclaimer in the
14218799Snwhitehorn#    documentation and/or other materials provided with the distribution.
15218799Snwhitehorn#
16218799Snwhitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17218799Snwhitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18218799Snwhitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19218799Snwhitehorn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20218799Snwhitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21218799Snwhitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22218799Snwhitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23218799Snwhitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24218799Snwhitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25218799Snwhitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26218799Snwhitehorn# SUCH DAMAGE.
27218799Snwhitehorn#
28218799Snwhitehorn# $FreeBSD$
29258421Sdteske#
30258421Sdteske############################################################ INCLUDES
31218799Snwhitehorn
32258421Sdteske# Delay processing of debug flags as the parent until MAIN. export'd to disable
33258421Sdteske# re-processing of flags (all children log to the parent's log file).
34258421Sdteske#
35258421Sdteskeexport DEBUG_SELF_INITIALIZE=
36259396Sgjbexport DEBUG_INITIALIZE_FILE=
37258421Sdteske
38258421SdteskeBSDCFG_SHARE="/usr/share/bsdconfig"
39258421Sdteske. $BSDCFG_SHARE/common.subr || exit 1
40258421Sdteske
41258421Sdteske############################################################ GLOBALS
42258421Sdteske
43218799Snwhitehorn: ${BSDINSTALL_TMPETC="/tmp/bsdinstall_etc"}; export BSDINSTALL_TMPETC
44256361Sdteske: ${BSDINSTALL_TMPBOOT="/tmp/bsdinstall_boot"}; export BSDINSTALL_TMPBOOT
45218799Snwhitehorn: ${PATH_FSTAB="$BSDINSTALL_TMPETC/fstab"}; export PATH_FSTAB
46218799Snwhitehorn: ${BSDINSTALL_DISTDIR="/usr/freebsd-dist"}; export BSDINSTALL_DISTDIR
47218799Snwhitehorn: ${BSDINSTALL_CHROOT="/mnt"}; export BSDINSTALL_CHROOT
48218799Snwhitehorn
49258421Sdteskeexport debugFile="${debugFile-${BSDINSTALL_LOG-/tmp/bsdinstall_log}}"
50218799Snwhitehorn
51258421Sdteske############################################################ MAIN
52258421Sdteske
53258421Sdteske#
54258421Sdteske# Process command-line arguments
55258421Sdteske#
56258421Sdteskewhile getopts $GETOPTS_STDARGS ignored; do
57258421Sdteske	: just skipping known flags
58258421Sdteskedone
59258421Sdteskeshift $(( $OPTIND - 1 ))
60258421Sdteske
61258421Sdteske# What are we here to do?
62258421SdteskeVERB="${1:-auto}"; shift
63258421Sdteske
64241902Sdteske[ -d "$BSDINSTALL_TMPETC" ] || mkdir -p "$BSDINSTALL_TMPETC"
65256361Sdteske[ -d "$BSDINSTALL_TMPBOOT" ] || mkdir -p "$BSDINSTALL_TMPBOOT"
66258421Sdteske
67258421Sdteske# Only enable debugging if debugFile is non-NULL and can be initialized
68258421Sdteskef_quietly f_debug_init
69258421Sdteskef_isset debugFile || debug=
70258421Sdteske
71258421Sdteskef_dprintf "Running installation step: %s %s" "$VERB" "$*"
72258421Sdteskeif [ "$debug" ]; then
73258421Sdteske	case "$debugFile" in
74258421Sdteske	# If NULL, send errors to the bit-bucket
75258421Sdteske	"") exec "/usr/libexec/bsdinstall/$VERB" "$@" 2> /dev/null ;;
76258421Sdteske	# If begins with `+', send errors to both terminal and file (no `+')
77258421Sdteske	+*) exec "/usr/libexec/bsdinstall/$VERB" "$@" \
78258421Sdteske		2>&1 >&$TERMINAL_STDOUT_PASSTHRU | tee "${debugFile#+}" ;;
79258421Sdteske	# Otherwise, just send errors to the file specified
80258421Sdteske	*) exec "/usr/libexec/bsdinstall/$VERB" "$@" 2>> "$debugFile"
81258421Sdteske	esac
82258421Sdteskeelse
83258421Sdteske	exec "/usr/libexec/bsdinstall/$VERB" "$@" 2> /dev/null
84258421Sdteskefi
85258421Sdteske
86258421Sdteske################################################################################
87258421Sdteske# END
88258421Sdteske################################################################################
89