From owner-svn-src-head@freebsd.org Sun Jun 10 02:36:39 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 08C19100A0F9; Sun, 10 Jun 2018 02:36:39 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AAFF684DAB; Sun, 10 Jun 2018 02:36:38 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8CCF52683E; Sun, 10 Jun 2018 02:36:38 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5A2acWt088719; Sun, 10 Jun 2018 02:36:38 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5A2acUp088718; Sun, 10 Jun 2018 02:36:38 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201806100236.w5A2acUp088718@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sun, 10 Jun 2018 02:36:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334912 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 334912 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jun 2018 02:36:39 -0000 Author: kevans Date: Sun Jun 10 02:36:38 2018 New Revision: 334912 URL: https://svnweb.freebsd.org/changeset/base/334912 Log: lualoader: Support variable substitution in env var settings We support both of the following cases of substitution: bar="y" foo="${bar}" foo="$bar" The latter substitution syntax is, of course, not recommended- all punctuation must be considered potential variable names, and we do not go through the effort of searching the different combinations of, for instance, "$x.y.z" to determine if the variable is $x, $x.y, or $x.y.z. This is not officially documented as supported, but it has worked in forthloader for what is most likely a long time as `evaluate` is used to process the right hand side of the assignment. Modified: head/stand/lua/config.lua Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Sun Jun 10 02:34:41 2018 (r334911) +++ head/stand/lua/config.lua Sun Jun 10 02:36:38 2018 (r334912) @@ -102,6 +102,25 @@ local function setKey(key, name, value) modules[key][name] = value end +-- Escapes the named value for use as a literal in a replacement pattern. +-- e.g. dhcp.host-name gets turned into dhcp%.host%-name to remove the special +-- meaning. +local function escapeName(name) + return name:gsub("([%p])", "%%%1") +end + +local function processEnvVar(value) + for name in value:gmatch("${([^}]+)}") do + local replacement = loader.getenv(name) or "" + value = value:gsub("${" .. escapeName(name) .. "}", replacement) + end + for name in value:gmatch("$([%w%p]+)%s*") do + local replacement = loader.getenv(name) or "" + value = value:gsub("$" .. escapeName(name), replacement) + end + return value +end + local pattern_table = { { str = "^%s*(#.*)", @@ -172,7 +191,7 @@ local pattern_table = { { str = "^%s*([%w%p]+)%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) - if setEnv(k, v) ~= 0 then + if setEnv(k, processEnvVar(v)) ~= 0 then print(MSG_FAILSETENV:format(k, v)) end end, @@ -181,7 +200,7 @@ local pattern_table = { { str = "^%s*([%w%p]+)%s*=%s*(%d+)%s*(.*)", process = function(k, v) - if setEnv(k, v) ~= 0 then + if setEnv(k, processEnvVar(v)) ~= 0 then print(MSG_FAILSETENV:format(k, tostring(v))) end end,