#!/bin/sh #- # Copyright (c) 2011 Nathan Whitehorn # Copyright (c) 2013 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: head/usr.sbin/bsdinstall/scripts/config 257842 2013-11-08 09:57:03Z dteske $ # ############################################################ CONFIGURATION # # Location of ttys(5) # ETC_TTYS=/etc/ttys ############################################################ FUNCTIONS # ttus_set_type $serterm # # Set terminal type of `ttyu*' and entries in ttys(5) to $serterm. # ttus_set_type() { local serterm="$1" err # # Create new temporary file to write our ttys(5) update with new types. # local tmpfile="$( mktemp -t "pgm" )" [ "$tmpfile" ] || return $FAILURE # # Fixup permissions and ownership (mktemp(1) creates the temporary file # with 0600 permissions -- change the permissions and ownership to # match ttys(5) before we write it out and mv(1) it into place). # local mode="$( stat -f '%#Lp' "$ETC_TTYS" 2> /dev/null )" local owner="$( stat -f '%u:%g' "$ETC_TTYS" 2> /dev/null )" f_quietly chmod "${mode:-0644}" "$tmpfile" f_quietly chown "${owner:-root:wheel}" "$tmpfile" # # Operate on ttys(5), replacing only the types of `ttyu*' terminals # with the new type. # if ! err=$( awk -v serterm="$serterm" ' BEGIN { } { # "Skip" blank-lines, lines containing only whitespace, and # lines containing only a comment or whitespace-then-comment. # if ( $0 ~ /^[[:space:]]*(#|$)/ ) { print; next } # "Skip" terminal types other than those supported # if ( $1 !~ /^ttyu.*$/ ) { print; next } # Change the terminal type to the new value and enable it # match($0, /[[:alnum:]\.\+-_]+[[:space:]]+(on|off)([[:space:]]|$).*$/) if ( ! RSTART ) { print; next } start = RSTART left=substr($0, 0, RSTART - 1) right=substr($0, start) match(right, /[[:alnum:]\.\+-_]+[[:space:]]+(on|off)([[:space:]]+|$)/) right=substr(right, RSTART + RLENGTH) printf "%s%s on %s\n", left, serterm, right } ' "$ETC_TTYS" > "$tmpfile" 2>&1 ); then f_show_err "%s" "$err" return $FAILURE fi if ! err=$( mv -f "$tmpfile" "$ETC_TTYS" 2>&1 ); then f_show_err "%s" "$err" return $FAILURE fi return $SUCCESS } ############################################################ MAIN cat $BSDINSTALL_TMPETC/rc.conf.* >> $BSDINSTALL_TMPETC/rc.conf rm $BSDINSTALL_TMPETC/rc.conf.* cp $BSDINSTALL_TMPETC/* $BSDINSTALL_CHROOT/etc cat $BSDINSTALL_TMPBOOT/loader.conf.* >> $BSDINSTALL_TMPBOOT/loader.conf rm $BSDINSTALL_TMPBOOT/loader.conf.* cp $BSDINSTALL_TMPBOOT/* $BSDINSTALL_CHROOT/boot # Set up other things from installed config chroot $BSDINSTALL_CHROOT /usr/bin/newaliases kbdcontrol -d || ttus_set_type vt100 ################################################################################ # END ################################################################################