1218799Snwhitehorn#!/bin/sh
2218799Snwhitehorn#-
3218799Snwhitehorn# Copyright (c) 2011 Nathan Whitehorn
4263956Sdteske# 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$
29263956Sdteske#
30263956Sdteske############################################################ INCLUDES
31218799Snwhitehorn
32263956Sdteske# Delay processing of debug flags as the parent until MAIN. export'd to disable
33263956Sdteske# re-processing of flags (all children log to the parent's log file).
34263956Sdteske#
35263956Sdteskeexport DEBUG_SELF_INITIALIZE=
36263956Sdteskeexport DEBUG_INITIALIZE_FILE=
37263956Sdteske
38263956SdteskeBSDCFG_SHARE="/usr/share/bsdconfig"
39263956Sdteske. $BSDCFG_SHARE/common.subr || exit 1
40263956Sdteske
41263956Sdteske############################################################ GLOBALS
42263956Sdteske
43218799Snwhitehorn: ${BSDINSTALL_TMPETC="/tmp/bsdinstall_etc"}; export BSDINSTALL_TMPETC
44264437Sdteske: ${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
49263956Sdteskeexport debugFile="${debugFile-${BSDINSTALL_LOG-/tmp/bsdinstall_log}}"
50218799Snwhitehorn
51263956Sdteske############################################################ MAIN
52263956Sdteske
53263956Sdteske#
54263956Sdteske# Process command-line arguments
55263956Sdteske#
56263956Sdteskewhile getopts $GETOPTS_STDARGS ignored; do
57263956Sdteske	: just skipping known flags
58263956Sdteskedone
59263956Sdteskeshift $(( $OPTIND - 1 ))
60263956Sdteske
61263956Sdteske# What are we here to do?
62263956SdteskeVERB="${1:-auto}"; shift
63263956Sdteske
64248237Snwhitehorn[ -d "$BSDINSTALL_TMPETC" ] || mkdir -p "$BSDINSTALL_TMPETC"
65264437Sdteske[ -d "$BSDINSTALL_TMPBOOT" ] || mkdir -p "$BSDINSTALL_TMPBOOT"
66263956Sdteske
67263956Sdteske# Only enable debugging if debugFile is non-NULL and can be initialized
68263956Sdteskef_quietly f_debug_init
69263956Sdteskef_isset debugFile || debug=
70263956Sdteske
71263956Sdteskef_dprintf "Running installation step: %s %s" "$VERB" "$*"
72263956Sdteskeif [ "$debug" ]; then
73263956Sdteske	case "$debugFile" in
74263956Sdteske	# If NULL, send errors to the bit-bucket
75263956Sdteske	"") exec "/usr/libexec/bsdinstall/$VERB" "$@" 2> /dev/null ;;
76263956Sdteske	# If begins with `+', send errors to both terminal and file (no `+')
77263956Sdteske	+*) exec "/usr/libexec/bsdinstall/$VERB" "$@" \
78263956Sdteske		2>&1 >&$TERMINAL_STDOUT_PASSTHRU | tee "${debugFile#+}" ;;
79263956Sdteske	# Otherwise, just send errors to the file specified
80263956Sdteske	*) exec "/usr/libexec/bsdinstall/$VERB" "$@" 2>> "$debugFile"
81263956Sdteske	esac
82263956Sdteskeelse
83263956Sdteske	exec "/usr/libexec/bsdinstall/$VERB" "$@" 2> /dev/null
84263956Sdteskefi
85263956Sdteske
86263956Sdteske################################################################################
87263956Sdteske# END
88263956Sdteske################################################################################
89