summaryrefslogtreecommitdiff
path: root/distrib/miniroot/install.sub
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2016-08-17 13:53:21 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2016-08-17 13:53:21 +0000
commitda225b7764cb3064d92c6d72f6d600c432cab38a (patch)
treea7893839e11a11e2b669e8f361ee6eea1f7df853 /distrib/miniroot/install.sub
parentf19315ab5dfca362a8c336ffaadee2e63cf5b44f (diff)
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@
Diffstat (limited to 'distrib/miniroot/install.sub')
-rw-r--r--distrib/miniroot/install.sub33
1 files changed, 26 insertions, 7 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 <rpe@openbsd.org>
@@ -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