config revision 257842
1#!/bin/sh
2#-
3# Copyright (c) 2011 Nathan Whitehorn
4# Copyright (c) 2013 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: head/usr.sbin/bsdinstall/scripts/config 257842 2013-11-08 09:57:03Z dteske $
29#
30############################################################ CONFIGURATION
31
32#
33# Location of ttys(5)
34#
35ETC_TTYS=/etc/ttys
36
37############################################################ FUNCTIONS
38
39# ttus_set_type $serterm
40#
41# Set terminal type of `ttyu*' and entries in ttys(5) to $serterm.
42#
43ttus_set_type()
44{
45	local serterm="$1" err
46
47	#
48	# Create new temporary file to write our ttys(5) update with new types.
49	#
50	local tmpfile="$( mktemp -t "pgm" )"
51	[ "$tmpfile" ] || return $FAILURE
52
53	#
54	# Fixup permissions and ownership (mktemp(1) creates the temporary file
55	# with 0600 permissions -- change the permissions and ownership to
56	# match ttys(5) before we write it out and mv(1) it into place).
57	#
58	local mode="$( stat -f '%#Lp' "$ETC_TTYS" 2> /dev/null )"
59	local owner="$( stat -f '%u:%g' "$ETC_TTYS" 2> /dev/null )"
60	f_quietly chmod "${mode:-0644}" "$tmpfile"
61	f_quietly chown "${owner:-root:wheel}" "$tmpfile"
62
63	#
64	# Operate on ttys(5), replacing only the types of `ttyu*' terminals
65	# with the new type.
66	#
67	if ! err=$( awk -v serterm="$serterm" '
68	BEGIN {
69	}
70	{
71		# "Skip" blank-lines, lines containing only whitespace, and
72		# lines containing only a comment or whitespace-then-comment.
73		#
74		if ( $0 ~ /^[[:space:]]*(#|$)/ ) { print; next }
75
76		# "Skip" terminal types other than those supported
77		#
78		if ( $1 !~ /^ttyu.*$/ ) { print; next }
79
80		# Change the terminal type to the new value and enable it
81		#
82		match($0,
83		  /[[:alnum:]\.\+-_]+[[:space:]]+(on|off)([[:space:]]|$).*$/)
84		if ( ! RSTART ) { print; next }
85		start = RSTART
86		left=substr($0, 0, RSTART - 1)
87		right=substr($0, start)
88		match(right,
89		  /[[:alnum:]\.\+-_]+[[:space:]]+(on|off)([[:space:]]+|$)/)
90		right=substr(right, RSTART + RLENGTH)
91		printf "%s%s on %s\n", left, serterm, right
92	}
93	' "$ETC_TTYS" > "$tmpfile" 2>&1 ); then
94		f_show_err "%s" "$err"
95		return $FAILURE
96	fi
97	if ! err=$( mv -f "$tmpfile" "$ETC_TTYS" 2>&1 ); then
98		f_show_err "%s" "$err"
99		return $FAILURE
100	fi
101
102	return $SUCCESS
103}
104
105############################################################ MAIN
106
107cat $BSDINSTALL_TMPETC/rc.conf.* >> $BSDINSTALL_TMPETC/rc.conf
108rm $BSDINSTALL_TMPETC/rc.conf.*
109
110cp $BSDINSTALL_TMPETC/* $BSDINSTALL_CHROOT/etc
111
112cat $BSDINSTALL_TMPBOOT/loader.conf.* >> $BSDINSTALL_TMPBOOT/loader.conf
113rm $BSDINSTALL_TMPBOOT/loader.conf.*
114
115cp $BSDINSTALL_TMPBOOT/* $BSDINSTALL_CHROOT/boot
116
117# Set up other things from installed config
118chroot $BSDINSTALL_CHROOT /usr/bin/newaliases
119
120kbdcontrol -d || ttus_set_type vt100
121
122################################################################################
123# END
124################################################################################
125