From c34383f9fe24b3855135a34fc97b4adc1d2386f0 Mon Sep 17 00:00:00 2001 From: rpe Date: Thu, 14 May 2015 10:58:55 +0000 Subject: [PATCH] Extend autoinstall(8) to allow for -.conf response files and to put response files in a subdir of the webserver's document root. Based on diffs from Nathanael Rensen, thanks! While here fix a buglet introduced by the $_server -> $AI_SERVER change. OK krw, halex --- distrib/miniroot/install.sub | 23 +++++++++++++---------- share/man/man8/autoinstall.8 | 28 +++++++++++++++++++++------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 2d14bbdcfa2..9965d59bf49 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,4 +1,4 @@ -# $OpenBSD: install.sub,v 1.836 2015/05/04 19:55:26 rpe Exp $ +# $OpenBSD: install.sub,v 1.837 2015/05/14 10:58:55 rpe Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback # Copyright (c) 2015, Robert Peichaer @@ -304,7 +304,7 @@ retrap() { # Fetch response file for autoinstall. get_responsefile() { - local _rf _ifdev _mac _mode _lf + local _rf _ifdev _mac _mode _lf _hn _path action= [[ -f /auto_upgrade.conf ]] && _rf=/auto_upgrade.conf _mode=upgrade @@ -313,8 +313,8 @@ get_responsefile() { # 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. + # Extract server ip address, installer mode and response file path + # from lease file. Prime hostname with host-name option. for _ifdev in ''; do [[ -x /sbin/dhclient ]] || break set -- $(get_ifdevs netboot) @@ -328,16 +328,19 @@ get_responsefile() { [[ -n $_ifdev ]] && dhclient $_ifdev || break _lf=/var/db/dhclient.leases.$_ifdev export AI_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)" + _mode=$(sed -E '/^ *filename "(.*\/)?auto_(install|upgrade)";$/!d;s//\2/;q' $_lf) + _path=$(sed -E '/^ *filename "(.*\/)[^/]+";$/!d;s//\1/;q' $_lf) + _hn=$(sed -E '/^ *option host-name "(.*)";$/!d;s//\1/;q' $_lf) + hostname "$_hn" done # 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. + # one was missing. Try to fetch mac-mode.conf, then hostname-mode.conf, + # and finally mode.conf. if [[ -n $AI_SERVER && -n $_mode ]]; then _mac=$(ifconfig $_ifdev | sed 's/.*lladdr \(.*\)/\1/p;d') - for _rf in {$_mac-,}$_mode; do - _url="http://$AI_SERVER/$_rf.conf?path=$HTTP_SETDIR" + for _rf in {$_mac-,${_hn:+$_hn-,}}$_mode; do + _url="http://$AI_SERVER/$_path$_rf.conf?path=$HTTP_SETDIR" echo "Fetching $_url" if ftp -Vo "/ai.$_mode.conf" "$_url" 2>/dev/null; then action=$_mode @@ -354,7 +357,7 @@ get_responsefile() { # server was found in lease file. while :; do ask "Response file location?" \ - "${AI_SERVER:+http://$_server/install.conf}" + "${AI_SERVER:+http://$AI_SERVER/install.conf}" [[ -n $resp ]] && _rf=$resp && break done diff --git a/share/man/man8/autoinstall.8 b/share/man/man8/autoinstall.8 index 401d1bad477..e90ec4f51b5 100644 --- a/share/man/man8/autoinstall.8 +++ b/share/man/man8/autoinstall.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: autoinstall.8,v 1.14 2015/05/05 07:20:42 jmc Exp $ +.\" $OpenBSD: autoinstall.8,v 1.15 2015/05/14 10:58:55 rpe Exp $ .\" .\" Copyright (c) 2013 Robert Peichaer .\" @@ -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: May 5 2015 $ +.Dd $Mdocdate: May 14 2015 $ .Dt AUTOINSTALL 8 .Os .Sh NAME @@ -59,13 +59,15 @@ takes precedence. .Pp .Nm uses HTTP to fetch one of the files -.Pa install.conf -or +.Pa install.conf , .Ar MAC_address Ns - Ns Pa install.conf -for install answers, or one of -.Pa upgrade.conf or +.Ar hostname Ns - Ns Pa install.conf +for install answers, or one of +.Pa upgrade.conf , .Ar MAC_address Ns - Ns Pa upgrade.conf +or +.Ar hostname Ns - Ns Pa upgrade.conf for upgrade answers. The URL used to fetch the file is constructed from information provided in the @@ -82,6 +84,7 @@ then the URLs tried are, in order: .Sm off .Bd -unfilled -offset indent .No http:// Ar next-server No / Ar MAC_address No -install.conf +.No http:// Ar next-server No / Ar hostname No -install.conf .No http:// Ar next-server No /install.conf .Ed .Sm on @@ -90,7 +93,10 @@ where .Ar MAC_address is a string of six hex octets separated by colons representing the MAC -address of the interface being used to fetch the files. +address of the interface being used to fetch the files, +and +.Ar hostname +is the hostname assigned to the system by DHCP. .Pp If .Ar filename @@ -100,6 +106,7 @@ the URLs tried are, in order: .Sm off .Bd -unfilled -offset indent .No http:// Ar next-server No / Ar MAC_address No -upgrade.conf +.No http:// Ar next-server No / Ar hostname No -upgrade.conf .No http:// Ar next-server No /upgrade.conf .Ed .Sm on @@ -121,6 +128,13 @@ file to be or .Cm auto_upgrade . .Pp +To use a subdirectory as response file location on the HTTP server, the same +directory structure containig the symbolic links has to exist in the tftproot +directory. +The value of +.Ic filename +has to be the full path to these symbolic links. +.Pp Note that in these cases, the HTTP server and TFTP server must be on the same machine. .Pp -- 2.20.1