summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--distrib/miniroot/install.sh117
-rw-r--r--distrib/miniroot/install.sub169
-rw-r--r--distrib/miniroot/upgrade.sh14
3 files changed, 130 insertions, 170 deletions
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh
index dd3c43a0dc5..f5d785691fb 100644
--- a/distrib/miniroot/install.sh
+++ b/distrib/miniroot/install.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: install.sh,v 1.126 2002/12/04 03:39:07 krw Exp $
+# $OpenBSD: install.sh,v 1.127 2002/12/08 19:30:40 krw Exp $
# $NetBSD: install.sh,v 1.5.2.8 1996/08/27 18:15:05 gwr Exp $
#
# Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback
@@ -315,26 +315,36 @@ fi
mount_fs "-o async"
-# Use existing hostname, if any, as the default. Discard any
-# domain information supplied.
+# Set hostname.
+#
+# Use existing hostname (short form) as the default value because we could
+# be restarting an install.
+#
+# Don't ask for, but don't discard, domain information provided by the user.
+#
+# Only apply the new value if the new short form name differs from the existing
+# one. This preserves any existing domain information in the hostname.
ask_until "\nSystem hostname? (short form, e.g. 'foo')" "$(hostname -s)"
-HOSTNAME=${resp%%.*}
-FQDN=my.domain
-hostname $HOSTNAME.$FQDN
+[[ ${resp%%.*} != $(hostname -s) ]] && hostname $resp
+
+# Remove existing network configuration files in /tmp to ensure they don't leak
+# onto the installed system in the case of a restarted install. Any information
+# contained within them should be accessible via ifconfig, hostname, route,
+# etc.
+( cd /tmp; rm -f host* my* resolv.* dhclient.* )
+
+# Always create new hosts file.
+cat > /tmp/hosts << __EOT
+::1 localhost
+127.0.0.1 localhost
+::1 $(hostname -s)
+127.0.0.1 $(hostname -s)
+__EOT
-# Get network configuration information, and store it for placement in the
-# root filesystem later.
ask "Configure the network?" y
case $resp in
-y*|Y*) donetconfig
- ;;
-*) cat > /tmp/hosts << __EOT
-::1 localhost.$FQDN localhost
-127.0.0.1 localhost.$FQDN localhost
-::1 $HOSTNAME.$FQDN $HOSTNAME
-127.0.0.1 $HOSTNAME.$FQDN $HOSTNAME
-__EOT
- ;;
+y*|Y*) donetconfig ;;
+*) ;;
esac
_oifs=$IFS
@@ -354,44 +364,50 @@ IFS=$_oifs
install_sets
-# Remount all filesystems in /etc/fstab with the options from
-# /etc/fstab, i.e. without any options such as async which
-# may have been used in the first mount.
+# Remount all filesystems in /etc/fstab with the options from /etc/fstab, i.e.
+# without any options such as async which may have been used in the first
+# mount.
while read _dev _mp _fstype _opt _rest; do
mount -u -o $_opt $_dev $_mp || exit
done < /etc/fstab
-# Set machdep.apertureallowed if required. install_sets must be
-# done first so that /etc/sysctl.conf is available.
+# Create /tmp/sysctl.conf from installed sysctl.conf if appropriate.
set_machdep_apertureallowed
-# Move configuration files to /mnt/etc.
-cfgfiles="fstab hostname.* dhclient.conf resolv.conf resolv.conf.tail kbdtype sysctl.conf"
-
echo -n "Saving configuration files..."
-cd /tmp
-
-if [ -f dhclient.conf ]; then
- # Save any leases obtained during install.
- mv /var/db/dhclient.leases /mnt/var/db/.
-else
- # Install mygate for non-dhcp installations.
- mv mygate /mnt/etc/.
-fi
-
-hostname > /mnt/etc/myname
-
-# Try to retain useful leading comments in /etc/hosts file.
-grep "^#" /mnt/etc/hosts > hosts.comment
-cat hosts.comment hosts > /mnt/etc/hosts
-for file in $cfgfiles; do
- if [ -f $file ]; then
- cp $file /mnt/etc/.
- rm -f $file
+# Save any leases obtained during install.
+( cd /var/db
+[ -f dhclient.leases ] && mv dhclient.leases /mnt/var/db/. )
+
+# Prepend interesting comments from installed hosts and dhclient.conf files
+# to /tmp/hosts and /tmp/dhclient.conf.
+save_comments hosts
+save_comments dhclient.conf
+
+# Move configuration files from /tmp to /mnt/etc.
+( cd /tmp
+hostname > myname
+
+# Add FQDN to /tmp/hosts entries, changing lines of the form '1.2.3.4 hostname'
+# to '1.2.3.4 hostname.$FQDN hostname'. Leave untouched any lines containing
+# domain information or aliases. The user added those manually.
+_dn=$(get_fqdn)
+while read _addr _hn _aliases; do
+ if [[ -n $_aliases || $_hn != ${_hn%%.*} || -z $_dn ]]; then
+ echo "$_addr $_hn $_aliases"
+ else
+ echo "$_addr $_hn.$_dn $_hn"
fi
-done
-echo "...done."
+done < hosts > hosts.new
+mv hosts.new hosts
+
+# Possible files: fstab, kbdtype, myname, mygate, sysctl.conf
+# dhclient.conf resolv.conf resolv.conf.tail
+# hostname.* hosts
+for _f in fstab kbdtype my* *.conf *.tail host*; do
+ [[ -f $_f ]] && mv $_f /mnt/etc/.
+done )
_encr=`/mnt/usr/bin/encrypt -b 8 -- "$_password"`
echo "1,s@^root::@root:${_encr}:@
@@ -399,10 +415,11 @@ w
q" | ed /mnt/etc/master.passwd 2> /dev/null
/mnt/usr/sbin/pwd_mkdb -p -d /mnt/etc /etc/master.passwd
-echo -n "Generating initial host.random file ..."
-dd if=/mnt/dev/urandom of=/mnt/var/db/host.random bs=1024 count=64 >/dev/null 2>&1
-chmod 600 /mnt/var/db/host.random >/dev/null 2>&1
-echo "...done."
+echo -n "done.\nGenerating initial host.random file..."
+( cd /mnt/var/db
+dd if=/mnt/dev/urandom of=host.random bs=1024 count=64 >/dev/null 2>&1
+chmod 600 host.random >/dev/null 2>&1 )
+echo "done."
# Perform final steps common to both an install and an upgrade.
finish_up
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub
index 730a32ff564..da2a2673acf 100644
--- a/distrib/miniroot/install.sub
+++ b/distrib/miniroot/install.sub
@@ -1,4 +1,4 @@
-# $OpenBSD: install.sub,v 1.282 2002/12/04 03:39:07 krw Exp $
+# $OpenBSD: install.sub,v 1.283 2002/12/08 19:30:40 krw Exp $
# $NetBSD: install.sub,v 1.5.2.8 1996/09/02 23:25:02 pk Exp $
#
# Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback
@@ -366,6 +366,19 @@ bsort() {
fi
}
+# Add interesting/useful comments from mnt/etc/$1 to /tmp/$1.
+#
+# $1 == file in /tmp and /mnt/etc directories
+save_comments () {
+ local _file=$1
+
+ if [[ -f /mnt/etc/$_file ]]; then
+ grep "^#" /mnt/etc/$_file > /tmp/$_file.new
+ [[ -f /tmp/$_file ]] && cat /tmp/$_file >> /tmp/$_file.new
+ mv /tmp/$_file.new /tmp/$_file
+ fi
+}
+
# Offer to edit a file in /tmp and execute ${EDITOR} to do so if the user
# accepts the offer.
#
@@ -581,7 +594,7 @@ configure_ifs() {
[[ -n $2 && $2 != "0.0.0.0" ]] && { _addr=$2; _mask=$3; }
# Get symbolic name - will be used in DHCP requests.
- ask "Symbolic (host) name for $_ifs?" "$HOSTNAME"
+ ask "Symbolic (host) name for $_ifs?" "$(hostname -s)"
_name=$resp
# Get and apply media options.
@@ -1434,8 +1447,9 @@ set_timezone() {
if [ -f "$_zonepath" ]; then
TZ=${_zonepath#$_zoneroot}
- echo "You have selected timezone '$TZ'".
+ echo -n "Setting local timezone to '$TZ'..."
ln -sf /usr/share/zoneinfo/$TZ /mnt/etc/localtime
+ echo "done."
return
fi
@@ -1647,63 +1661,25 @@ check_fs() {
[ "$_fail" ] && exit
}
-# Find LAST instance of DOMAIN or SEARCH and extract first domain name
-# on that line as FQDN.
-# $1 = resolv.conf file name
-get_resolv_fqdn () {
- [[ -f $1 ]] || return
+# Extract fully qualified domain name from current hostname. If none is
+# currently set, use 'my.domain'.
+get_fqdn() {
+ local _dn
- FQDN=`sed -n \
- -e '/^domain[[:space:]][[:space:]]*/{s///;s/\([^[:space:]]*\).*$/\1/;h;}' \
- -e '/^search[[:space:]][[:space:]]*/{s///;s/\([^[:space:]]*\).*$/\1/;h;}' \
- -e '${g;p;}' $1`
-}
+ _dn=$(hostname)
+ _dn=${_dn#$(hostname -s)}
+ _dn=${_dn#.}
-# Get Fully Qualified Domain Name and update hosts file appropriately.
-#
-# $1 = resolv.conf file to search for FQDN
-# $2 = hosts file to add FQDN information to
-get_fqdn() {
- get_resolv_fqdn $1
-
- ask "DNS domain name? (e.g. 'bar.com')" "$FQDN"
- FQDN=$resp
-
- if [ -f "$2" -a -n "$FQDN" ]; then
- # Add FQDN to hosts file entries created by addhostent, changing
- # lines like
- # 1.2.3.4 hostname
- # to
- # 1.2.3.4 hostname.$FQDN hostname
- sed "s/\\(.*\\)[[:space:]]\\(.*\\)\$/\\1 \\2.$FQDN \\2/" $2 > $2.new
- mv $2.new $2
- fi
+ echo "${_dn:=my.domain}"
}
donetconfig() {
- local _nam
+ local _ns
- [ "$DIDNET" ] && return
+ [[ -n $DIDNET ]] && return
DIDNET=y
- # Always create new hosts file. If install.sh has been
- # restarted, an existing one may contain information which
- # will conflict with the information about to be entered.
- # Also ensures logic to put FQDN in hosts file will create
- # hosts file lines in correct format.
- echo "::1 localhost\n127.0.0.1 localhost" > /tmp/hosts
-
- # Remove any existing hostname.* files. If install.sh has
- # been restarted, this ensures a correct list of configured
- # interfaces is displayed, and gives the user a chance to
- # change which interfaces are to be configured.
- rm -f /tmp/hostname.*
-
- # Revoke any previous decision on whether or not to use
- # a nameserver during installation.
- rm -f /tmp/resolv.conf.shadow
-
configure_all_interfaces
# As dhclient will populate /etc/resolv.conf, a symbolic link to
@@ -1711,55 +1687,46 @@ donetconfig() {
# so it will eventually be copied to /mnt/etc/resolv.conf and will
# not in the meantime remove the user's ability to choose to use it
# or not, during the rest of the install.
+ resp=
if [ -f /tmp/resolv.conf.shadow ]; then
mv /tmp/resolv.conf.shadow /tmp/resolv.conf
+ # Get default fully qualified domain name from *first* domain
+ # given on *last* search or domain statement
+ resp=$(sed -n \
+ -e '/^domain[[:space:]][[:space:]]*/{s///;s/\([^[:space:]]*\).*$/\1/;h;}' \
+ -e '/^search[[:space:]][[:space:]]*/{s///;s/\([^[:space:]]*\).*$/\1/;h;}' \
+ -e '${g;p;}' /tmp/resolv.conf)
fi
- # Get/Confirm FQDN, and apply it to the hosts file.
- get_fqdn /tmp/resolv.conf /tmp/hosts
-
- hostname $HOSTNAME.$FQDN
-
- resp=`route -n show | sed -ne '/^default */{
- s///
- s/ .*//
- p
- }'`
- if [ -z "$resp" ] ; then
- resp=none
- if [ -f /tmp/mygate ]; then
- resp=`cat /etc/mygate`
- : ${_resp:=none}
- fi
- fi
- ask "IP address of default route?" "$resp"
- if [ "$resp" != "none" ]; then
- route delete default > /dev/null 2>&1
- if route add default $resp > /dev/null ; then
- echo $resp > /tmp/mygate
- fi
- fi
+ # Get & apply fully qualified domain name to hostname.
+ ask "DNS domain name? (e.g. 'bar.com')" "${resp:=$(get_fqdn)}"
+ hostname "$(hostname -s).$resp"
- resp=none
+ # Get/Confirm the default route.
+ resp=$(route -n show | sed -ne '/^default */{s///; s/ .*//; p;}')
+ [[ -z $resp && -f /tmp/mygate ]] && resp=$(< /tmp/mygate)
+ route delete default > /dev/null 2>&1
+ rm -f /tmp/mygate
+ while : ; do
+ ask "IP address of default route? (or 'none')" "${resp:=none}"
+ [[ $resp == none ]] && break
+ route add default $resp || { resp= ; continue; }
+ # Save default route if DHCP wasn't used.
+ [[ -f /tmp/dhclient.conf ]] || echo $resp > /tmp/mygate
+ break
+ done
+
+ # Get/Confirm nameservers, and construct appropriate resolv.conf.
+ resp=
if [ -f /tmp/resolv.conf ]; then
- resp=
- for n in `sed -ne '/^nameserver /s///p' /tmp/resolv.conf`
- do
- if [ -z "$resp" ] ; then
- resp=$n
- else
- resp="$resp $n"
- fi
- done
+ resp=$(sed -ne '/^nameserver /s///p' /tmp/resolv.conf)
fi
- ask "IP address of primary nameserver?" "$resp"
- if [ "$resp" != "none" ]; then
- echo "search $FQDN" > /tmp/resolv.conf
- for n in `echo ${resp}`; do
- echo "nameserver $n" >> /tmp/resolv.conf
+ ask "IP address of DNS nameserver? (or 'none')" "${resp:=none}"
+ if [[ $resp != none ]]; then
+ echo "lookup file bind" > /tmp/resolv.conf
+ for _ns in $resp; do
+ echo "nameserver $_ns" >> /tmp/resolv.conf
done
- echo "lookup file bind" >> /tmp/resolv.conf
-
ask "Would you like to use the nameserver now?" y
case $resp in
y*|Y*) cp /tmp/resolv.conf /tmp/resolv.conf.shadow
@@ -1767,17 +1734,7 @@ donetconfig() {
esac
fi
- if [ ! -f /tmp/resolv.conf.shadow ]; then
- cat << __EOT
-
-The host table contains:
-
-$(< /tmp/hosts)
-
-__EOT
- edit_tmp_file hosts
- fi
-
+ edit_tmp_file hosts
manual_net_cfg
}
@@ -1876,12 +1833,6 @@ done
SETSDONE=
GET_FILES=
-# The Fully Qualified Domain Name.
-FQDN=
-
-# The system hostname (short form).
-HOSTNAME=
-
# decide upon an editor
if [ -z "$EDITOR" ] ; then
EDITOR=ed
diff --git a/distrib/miniroot/upgrade.sh b/distrib/miniroot/upgrade.sh
index 3ef35596853..7f867ec403d 100644
--- a/distrib/miniroot/upgrade.sh
+++ b/distrib/miniroot/upgrade.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: upgrade.sh,v 1.47 2002/12/01 23:19:33 krw Exp $
+# $OpenBSD: upgrade.sh,v 1.48 2002/12/08 19:30:40 krw Exp $
# $NetBSD: upgrade.sh,v 1.2.4.5 1996/08/27 18:15:08 gwr Exp $
#
# Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback
@@ -84,15 +84,7 @@ for _file in fstab hosts myname; do
fi
cp /mnt/etc/$_file /tmp/$_file
done
-
-# Set the FQDN and system hostname (short form).
-HOSTNAME=`cat /tmp/myname`
-FQDN=$HOSTNAME
-HOSTNAME=${HOSTNAME%%.*}
-FQDN=${FQDN#${HOSTNAME}}
-FQDN=${FQDN#.}
-[[ -n $FQDN ]] || get_resolv_fqdn /mnt/etc/resolv.conf
-hostname $HOSTNAME.$FQDN
+hostname $(< /tmp/myname)
# Start up the network in same/similar configuration as the installed system
# uses.
@@ -111,7 +103,7 @@ cat << __EOT
The fstab is configured as follows:
-$(</tmp/fstab)
+$(< /tmp/fstab)
For the ${MODE}, filesystems in the fstab will be automatically mounted if the
'noauto' option is absent, and /sbin/mount_<fstype> is found, and the fstype is