1238438Sdteske#!/bin/sh
2238438Sdteske#-
3249746Sdteske# Copyright (c) 2012-2013 Devin Teske
4252980Sdteske# All rights reserved.
5238438Sdteske#
6238438Sdteske# Redistribution and use in source and binary forms, with or without
7238438Sdteske# modification, are permitted provided that the following conditions
8238438Sdteske# are met:
9238438Sdteske# 1. Redistributions of source code must retain the above copyright
10238438Sdteske#    notice, this list of conditions and the following disclaimer.
11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright
12238438Sdteske#    notice, this list of conditions and the following disclaimer in the
13238438Sdteske#    documentation and/or other materials provided with the distribution.
14238438Sdteske#
15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16252987Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18238438Sdteske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20252987Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25238438Sdteske# SUCH DAMAGE.
26238438Sdteske#
27238438Sdteske# $FreeBSD$
28238438Sdteske#
29238438Sdteske############################################################ INCLUDES
30238438Sdteske
31240684SdteskeBSDCFG_SHARE="/usr/share/bsdconfig"
32240684Sdteske. $BSDCFG_SHARE/common.subr || exit 1
33244675Sdteskef_dprintf "%s: loading includes..." "$0"
34240684Sdteskef_include $BSDCFG_SHARE/dialog.subr
35240684Sdteskef_include $BSDCFG_SHARE/mustberoot.subr
36238438Sdteske
37240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="150.ttys"
38238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
39238438Sdteske
40260678Sdteskef_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
41260678Sdteske	pgm="${ipgm:-$pgm}"
42238438Sdteske
43238438Sdteske############################################################ CONFIGURATION
44238438Sdteske
45238438Sdteske#
46238438Sdteske# Default text-editor to use
47238438Sdteske#
48238438Sdteske: ${EDITOR:=ee}
49238438Sdteske
50238438Sdteske
51238438Sdteske#
52238438Sdteske# If X11 is requested, which terminal and what options should we use?
53238438Sdteske#
54238438SdteskeX11TERM=xterm
55238438SdteskeX11TERM_OPTS=
56238438Sdteske
57238438Sdteske#
58238438Sdteske# Location of ttys(5)
59238438Sdteske#
60238438SdteskeETC_TTYS=/etc/ttys
61238438Sdteske
62238438Sdteske############################################################ MAIN
63238438Sdteske
64238438Sdteske# Incorporate rc-file if it exists
65238438Sdteske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
66238438Sdteske
67238438Sdteske#
68238438Sdteske# Process command-line arguments
69238438Sdteske#
70250633Sdteskewhile getopts h$GETOPTS_STDARGS flag; do
71238438Sdteske	case "$flag" in
72252178Sdteske	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
73238438Sdteske	esac
74238438Sdteskedone
75238438Sdteskeshift $(( $OPTIND - 1 ))
76238438Sdteske
77238438Sdteske#
78238438Sdteske# Initialize
79238438Sdteske#
80238438Sdteskef_dialog_title "$msg_configure_ttys"
81238438Sdteskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
82238438Sdteskef_mustberoot_init
83238438Sdteskef_dialog_title "$msg_user_confirmation_requested"
84238438Sdteskef_dialog_yesno "$msg_help_text" || exit $SUCCESS
85238438Sdteskef_dialog_title_restore
86238438Sdteske
87238438Sdteske#
88238438Sdteske# Make sure $EDITOR exists and is executable
89238438Sdteske#
90238438Sdteskecase "$EDITOR" in
91238438Sdteske*/*)
92238438Sdteske	[ -e "$EDITOR" ] ||
93238438Sdteske		f_die 1 "$msg_no_such_file_or_directory" "$pgm" "$EDITOR"
94238438Sdteske	[ -x "$EDITOR" ] ||
95238438Sdteske		f_die 1 "$msg_permission_denied" "$pgm" "$EDITOR"
96238438Sdteske	;;
97238438Sdteske*)
98238438Sdteske	f_have "$EDITOR" || 
99238438Sdteske		f_die 1 "$msg_no_such_file_or_directory" "$pgm" "$EDITOR"
100238438Sdteskeesac
101238438Sdteske
102238438Sdteske#
103238438Sdteske# If Xdialog(1) is requested, we'll need to wrap bsdinstall(8) into xterm(1)
104238438Sdteske#
105238438Sdteskeif [ "$USE_XDIALOG" ]; then
106238438Sdteske	#
107238438Sdteske	# Make sure $X11TERM exists and is executable
108238438Sdteske	#
109238438Sdteske	case "$X11TERM" in
110238438Sdteske	*/*)
111238438Sdteske		[ -e "$X11TERM" ] || f_die 1 \
112238438Sdteske			"$msg_no_such_file_or_directory" "$pgm" "$X11TERM"
113238438Sdteske		[ -x "$X11TERM" ] || f_die 1 \
114238438Sdteske			"$msg_permission_denied" "$pgm" "$X11TERM"
115238438Sdteske		;;
116238438Sdteske	*)
117238438Sdteske		f_have "$X11TERM" || f_die 1 \
118238438Sdteske			"$msg_no_such_file_or_directory" "$pgm" "$X11TERM"
119238438Sdteske	esac
120238438Sdteske
121238438Sdteske	exec $X11TERM $X11TERM_OPTS -e $EDITOR $ETC_TTYS
122238438Sdteskeelse
123238438Sdteske	exec $EDITOR $ETC_TTYS
124238438Sdteskefi
125238438Sdteske
126238438Sdteske################################################################################
127238438Sdteske# END
128238438Sdteske################################################################################
129