diff options
author | Ted Trask <ttrask01@yahoo.com> | 2019-10-02 18:11:11 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2019-10-02 18:11:11 +0000 |
commit | 71afb59bdd467a62ab20bd25aec26af42d7880ab (patch) | |
tree | 6d60921b3cb1627ac3678c12bb4790867295ce96 | |
parent | 5d6ba4690e83ba29831bc504e733320f2f8091c7 (diff) | |
download | acf-alpine-baselayout-71afb59bdd467a62ab20bd25aec26af42d7880ab.tar.bz2 acf-alpine-baselayout-71afb59bdd467a62ab20bd25aec26af42d7880ab.tar.xz |
Add support for symlink'd interfaces file
Also minor changes to avoid crash on empty file or syntax error
-rw-r--r-- | interfaces-model.lua | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/interfaces-model.lua b/interfaces-model.lua index 2d9ff6d..156e1b5 100644 --- a/interfaces-model.lua +++ b/interfaces-model.lua @@ -7,7 +7,7 @@ fs = require("acf.fs") format = require("acf.format") local servicename = "networking" -local filename = "/etc/network/interfaces" +local interfacesfile = "/etc/network/interfaces" local array @@ -15,6 +15,20 @@ local array -- Depending on the address family and corresponding method, different options are valid local iface = require("alpine-baselayout/interfaces-definitions") +local followlink = function(path) + local where = path + while fs.is_link(where) do + local link = posix.readlink(where) + if link and not string.find(link, "^/") then + link = posix.dirname(where).."/"..link + end + where = link + end + return where +end + +local filename = followlink(interfacesfile) + -- Create an interface structure with all options local get_blank_iface = function () local f = {} @@ -86,7 +100,7 @@ end -- This function parses the interfaces file and creates array local unpack_interfaces = function () if array == nil then - local filecontent = fs.read_file(filename) + local filecontent = fs.read_file(filename) or "" -- make sure it has a terminating \n filecontent = string.gsub (filecontent, "([^\n])$", "%1\n") @@ -110,7 +124,7 @@ local unpack_interfaces = function () interface.name.value = name or "" interface.family.value = family or "" interface.method.value = method or "" - elseif #array then + elseif #array > 0 then -- it must be some kind of parameter local param, val = string.match(line, "(%S+)%s*(.*)$") |