From 78d5f44aede9089bd293c12ac3d5899958fe4ad4 Mon Sep 17 00:00:00 2001 From: krw Date: Wed, 17 Aug 2016 13:53:20 +0000 Subject: [PATCH] Use more dhcp info when trying autoinstall/autoupgrade. For the file name try 'filename' then 'option bootfile-name'. For the server name try 'server-name' then 'option tftp-server-name' then 'next-server'. Original idea from Patrick Lundin. Suggestions from rpe@. Tweaks & ok halex@ --- distrib/miniroot/install.sub | 33 ++++++++++++++++++++++++++------- share/man/man8/autoinstall.8 | 33 +++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 359bba51a49..8df92d6239e 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: install.sub,v 1.902 2016/07/23 17:55:45 deraadt Exp $ +# $OpenBSD: install.sub,v 1.903 2016/08/17 13:53:20 krw Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback # Copyright (c) 2015, Robert Peichaer @@ -228,6 +228,19 @@ prep_root_mail() { __EOT } +# Examine the contents of the DHCP lease file named in $1 for a line +# containing the field provided as parameters. +# +# Return the value of the first field found. +lease_value () { + local _lf=$1 _o + + shift + for _o; do + sed -E '/^ *(option )?'"$_o"' (.*);$/!d;s//\2/;s/^"//;s/"$//;q' "$_lf" | grep ^ && return + done +} + # ------------------------------------------------------------------------------ # Device related functions # ------------------------------------------------------------------------------ @@ -489,7 +502,7 @@ log_answers() { # Fetch response file for autoinstall. get_responsefile() { - local _rf _if _mac _mode _lf _hn _path + local _rf _if _mac _mode _lf _hn _path _aifile AI_MODE= [[ -f /auto_upgrade.conf ]] && _rf=/auto_upgrade.conf _mode=upgrade @@ -512,10 +525,16 @@ get_responsefile() { done [[ -n $_if ]] && dhclient $_if || break _lf=/var/db/dhclient.leases.$_if - export AI_SERVER=$(sed "/^ *next-server /!d;s///;s/;$//;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) + + _aifile=$(lease_value $_lf filename bootfile-name) + [[ $_aifile = ?(*/)auto_@(install|upgrade) ]] || _aifile= + _path=${_aifile%auto_@(install|upgrade)} + _mode=${_aifile##*?(/)auto_} + + AI_SERVER=$(lease_value $_lf server-name tftp-server-name next-server) + export AI_SERVER + + _hn=$(lease_value $_if host-name) hostname "$_hn" done @@ -534,7 +553,7 @@ get_responsefile() { fi done else - [[ -z $AI_SERVER ]] && echo "Could not determine next-server." + [[ -z $AI_SERVER ]] && echo "Could not determine auto server." [[ -z $_mode ]] && echo "Could not determine auto mode." fi diff --git a/share/man/man8/autoinstall.8 b/share/man/man8/autoinstall.8 index 424bdfd9e0d..e107cb1928e 100644 --- a/share/man/man8/autoinstall.8 +++ b/share/man/man8/autoinstall.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: autoinstall.8,v 1.17 2016/02/28 18:10:26 rpe Exp $ +.\" $OpenBSD: autoinstall.8,v 1.18 2016/08/17 13:53:20 krw 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: February 28 2016 $ +.Dd $Mdocdate: August 17 2016 $ .Dt AUTOINSTALL 8 .Os .Sh NAME @@ -70,12 +70,21 @@ 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 .Xr dhcpd.conf 5 -statements +statements. +One of the statements +.Ic server-name , +.Ic option tftp-server-name , +or .Ic next-server -and -.Ic filename . +(in that order of priority) specify the +.Ar server . +One of the statements +.Ic filename +or +.Ic option bootfile-name +(in that order of priority) specify the +.Ar filename . If .Ar filename is @@ -83,9 +92,9 @@ is 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 +.No http:// Ar server No / Ar MAC_address No -install.conf +.No http:// Ar server No / Ar hostname No -install.conf +.No http:// Ar server No /install.conf .Ed .Sm on .Pp @@ -105,9 +114,9 @@ is 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 +.No http:// Ar server No / Ar MAC_address No -upgrade.conf +.No http:// Ar server No / Ar hostname No -upgrade.conf +.No http:// Ar server No /upgrade.conf .Ed .Sm on .Pp -- 2.20.1