summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrpe <rpe@openbsd.org>2014-10-23 21:33:21 +0000
committerrpe <rpe@openbsd.org>2014-10-23 21:33:21 +0000
commitb926ff7ac5a5ef3990af10a7959598ed9d43ba43 (patch)
tree6991edf520671cc0e7fb22ae6593e89a27af03bc
parentAdd GRAMMAR to list of sections. (diff)
downloadwireguard-openbsd-b926ff7ac5a5ef3990af10a7959598ed9d43ba43.tar.xz
wireguard-openbsd-b926ff7ac5a5ef3990af10a7959598ed9d43ba43.zip
Extend autoinstall(8) feature:
- Ask for responsefile location (url or local path) if dhcp discovery fails for location or mode. If 'next-server' is found in dhcp lease file, provide a default url http://next-server/install.conf. - Ask for installer mode if the specified response file name does not match *install.conf or *upgrade.conf. - If present, use /auto_install.conf or /auto_upgrade.conf as response file for unattended installation or upgrade. - Automatically start installer in unattended mode if either one of these files is present when the system boots. - Document changes in manpage and installation notes. OK krw@ deraadt@
-rw-r--r--distrib/miniroot/dot.profile6
-rw-r--r--distrib/miniroot/install.sub107
-rw-r--r--distrib/notes/m4.common19
-rw-r--r--share/man/man8/autoinstall.86
4 files changed, 80 insertions, 58 deletions
diff --git a/distrib/miniroot/dot.profile b/distrib/miniroot/dot.profile
index 6aa77b849f9..ebcfb4a38b0 100644
--- a/distrib/miniroot/dot.profile
+++ b/distrib/miniroot/dot.profile
@@ -1,4 +1,4 @@
-# $OpenBSD: dot.profile,v 1.25 2014/07/16 14:19:05 deraadt Exp $
+# $OpenBSD: dot.profile,v 1.26 2014/10/23 21:33:21 rpe Exp $
# $NetBSD: dot.profile,v 1.1 1995/12/18 22:54:43 pk Exp $
#
# Copyright (c) 2009 Kenneth R. Westerback
@@ -69,7 +69,9 @@ __EOT
# after a timeout, but only the very first time around.
timeout=false
timer_pid=
- if [ ! -f /tmp/noai ] && ifconfig netboot >/dev/null 2>&1; then
+ if [ ! -f /tmp/noai ] && { ifconfig netboot >/dev/null 2>&1 ||
+ [ -f /auto_install.conf ] ||
+ [ -f /auto_upgrade.conf ]; }; then
echo "Starting non-interactive mode in 5 seconds..."
>/tmp/noai
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub
index 01dc1221db7..d4b62470124 100644
--- a/distrib/miniroot/install.sub
+++ b/distrib/miniroot/install.sub
@@ -1,4 +1,4 @@
-# $OpenBSD: install.sub,v 1.795 2014/10/08 00:26:38 krw Exp $
+# $OpenBSD: install.sub,v 1.796 2014/10/23 21:33:21 rpe Exp $
#
# Copyright (c) 1997-2009 Todd Miller, Theo de Raadt, Ken Westerback
# All rights reserved.
@@ -2069,56 +2069,69 @@ for _ifs in $(get_ifdevs dhcp); do
ifconfig $_ifs delete down -group dhcp 2>/dev/null
done
-# Fetch a response file from a http server.
-#
-# Select a network interface for an initial dhcp request to get the IP
-# from the lease file via the next-server attribute.
-#
+# Fetch response file for autoinstall.
get_responsefile() {
- local _f _ifdev _mac _mode _server _lf
- [[ -x /sbin/dhclient ]] || return
-
- _ifdev=$(get_ifdevs netboot)
- if [[ -z $_ifdev ]]; then
- set -- $(get_ifdevs)
- (($#)) || return
- if (($# == 1)); then
- _ifdev=$1
- else
- while :; do
- ask_which "network interface" \
- "should be used for the initial DHCP request" \
- "$*"
- isin "$resp" $* && _ifdev=$resp && break
- done
- fi
- fi
- [[ -n $_ifdev ]] || return
-
- dhclient $_ifdev
-
- _lf=/var/db/dhclient.leases.$_ifdev
- _server=$(sed "/^ *next-server /!d;s///;s/;$//;q" $_lf)
- _mode=$(sed -E '/^ *filename "auto_(install|upgrade)";$/!d;s//\1/;q' \
- $_lf)
- _mac=$(ifconfig $_ifdev | sed 's/.*lladdr \(.*\)/\1/p;d')
-
- # Prime hostname with host-name option
- hostname "$(sed -E '/^ *option host-name "(.*)";$/!d;s//\1/;q' $_lf)"
+ local _rf _ifdev _mac _mode _server _lf
+
+ [[ -f /auto_upgrade.conf ]] && _rf=/auto_upgrade.conf _mode=upgrade
+ [[ -f /auto_install.conf ]] && _rf=/auto_install.conf _mode=install
+ [[ -f $_rf ]] && cp $_rf /ai.$_mode.conf && action=$_mode && return
+
+ # Select a network interface for initial dhcp request.
+ # Ask if multiple were found and system was not netbooted.
+ # Extract server ip address and installer mode from lease file.
+ # Prime hostname with host-name option.
+ for _ifdev in ''; do
+ [[ -x /sbin/dhclient ]] || break
+ set -- $(get_ifdevs netboot)
+ (($# == 0)) && set -- $(get_ifdevs)
+ (($# == 1)) && _ifdev=$1
+ while (($# > 1)); do
+ ask_which "network interface" \
+ "should be used for the initial DHCP request" "$*"
+ isin "$resp" $* && _ifdev=$resp && break
+ done
+ [[ -n $_ifdev ]] && dhclient $_ifdev || break
+ _lf=/var/db/dhclient.leases.$_ifdev
+ _server=$(sed "/^ *next-server /!d;s///;s/;$//;q" $_lf)
+ _mode=$(sed -E '/^ *filename "auto_(install|upgrade)";$/!d;s//\1/;q' $_lf)
+ hostname "$(sed -E '/^ *option host-name "(.*)";$/!d;s//\1/;q' $_lf)"
+ done
- if [[ -z $_server ]]; then
- echo "Could not determine next-server."
- elif [[ -z $_mode ]]; then
- echo "Could not determine auto mode."
- else
- for _f in {$_mac-,}$_mode; do
- ftp -o "/$_mode.conf" "http://$_server/$_f.conf" &&
- action=$_mode && return 0
+ # Fetch response file if server and mode are known, otherwise tell which
+ # one was missing. First try to fetch mac-mode.conf, then mode.conf.
+ if [[ -n $_server && -n $_mode ]]; then
+ _mac=$(ifconfig $_ifdev | sed 's/.*lladdr \(.*\)/\1/p;d')
+ for _rf in {$_mac-,}$_mode; do
+ _url=http://$_server/$_rf.conf
+ echo "Fetching $_url"
+ ftp -Vo "/ai.$_mode.conf" "$_url" 2>/dev/null &&
+ action=$_mode && return
done
+ else
+ [[ -z $_server ]] && echo "Could not determine next-server."
+ [[ -z $_mode ]] && echo "Could not determine auto mode."
fi
- # No response file found
- return 1
+ # Ask for url or local path to response file. Provide a default url if
+ # server was found in lease file.
+ while :; do
+ ask "Response file location?" \
+ "${_server:+http://$_server/install.conf}"
+ [[ -n $resp ]] && _rf=$resp && break
+ done
+
+ # Ask for the installer mode only if auto-detection failed.
+ _mode=$(echo "$_rf" | sed -En 's/^.*(install|upgrade).conf$/\1/p')
+ while [[ -z $_mode ]]; do
+ ask "(I)nstall or (U)pgrade?"
+ [[ $resp == [iI]* ]] && _mode=install
+ [[ $resp == [uU]* ]] && _mode=upgrade
+ done
+
+ echo "Fetching $_rf"
+ [[ -f $_rf ]] && _rf="file://$_rf"
+ ftp -Vo "/ai.$_mode.conf" "$_rf" 2>/dev/null && action=$_mode
}
# Interactive or automatic installation?
@@ -2137,7 +2150,7 @@ elif [[ -z $respfile ]]; then
fi
rm -f /ai.done
echo "Performing non-interactive $action..."
- /$action -af /$action.conf 2>&1 </dev/null | sed 's/^.* //;w/ai.log'
+ /$action -af /ai.$action.conf 2>&1 </dev/null | sed 's/^.* //;w/ai.log'
if [[ -f /ai.done ]]; then
# Generate unique filename and let rc.firsttime feed it to
# whatever mail system we have at hand by then.
diff --git a/distrib/notes/m4.common b/distrib/notes/m4.common
index b327d74b489..404bba968e8 100644
--- a/distrib/notes/m4.common
+++ b/distrib/notes/m4.common
@@ -1,5 +1,5 @@
dnl
-dnl $OpenBSD: m4.common,v 1.112 2014/09/11 07:08:37 rpe Exp $
+dnl $OpenBSD: m4.common,v 1.113 2014/10/23 21:33:21 rpe Exp $
dnl
dnl Copyright (c) 2004 Todd T. Fries <todd@OpenBSD.org>
dnl
@@ -757,12 +757,17 @@ define({:-OpenBSDUnattendedInstallation-:},
Preparing an unattended installation of OpenBSD:
------------------------------------------------
-If the installation system detects that it booted from the network,
-and isn't interrupted within 5 seconds, it attempts a fully-automatic
-installation. In this mode the installer runs dhclient(8) on the
-network interface the system booted from, or in case of multiple
-interfaces it will ask which one to use. Upon success it retrieves a
-response file via HTTP.
+If '(A)utoinstall' is choosen at the install prompt or if the
+installation system detects that it booted from the network, and
+isn't interrupted within 5 seconds, it attempts a fully-automatic
+installation.
+
+The installer runs dhclient(8) on the network interface the system
+booted from, or in case of multiple interfaces it will ask which one
+to use. Upon success it retrieves a response file via HTTP. If that
+fails, the installer asks for the response file location which can be
+either an url or a local path and retrieves the response file from
+there.
The "next-server" DHCP option specifies the hostname part of the URL,
as in "http://<next-server>/install.conf". The "filename" DHCP
diff --git a/share/man/man8/autoinstall.8 b/share/man/man8/autoinstall.8
index 8410565af43..025d131f142 100644
--- a/share/man/man8/autoinstall.8
+++ b/share/man/man8/autoinstall.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: autoinstall.8,v 1.10 2014/08/08 14:52:53 schwarze Exp $
+.\" $OpenBSD: autoinstall.8,v 1.11 2014/10/23 21:33:21 rpe Exp $
.\"
.\" Copyright (c) 2013 Robert Peichaer <rpe@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 8 2014 $
+.Dd $Mdocdate: October 23 2014 $
.Dt AUTOINSTALL 8
.Os
.Sh NAME
@@ -29,6 +29,8 @@ answers from a response file.
.Nm
uses DHCP to discover the location of the response
file and HTTP to fetch the file.
+If that fails, the installer asks for the location which can either be
+an url or a local path.
.Ss Autoinstall methods
The first method is to choose '(A)utoinstall' at the install prompt.
If there is only one network interface, the installer fetches the response