Changeset View
Changeset View
Standalone View
Standalone View
head/stand/lua/config.lua
Show First 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | local function readFile(name, silent) | ||||
if text == nil and not silent then | if text == nil and not silent then | ||||
print(MSG_FAILREADCFG:format(name)) | print(MSG_FAILREADCFG:format(name)) | ||||
end | end | ||||
return text | return text | ||||
end | end | ||||
local function checkNextboot() | local function checkNextboot() | ||||
local nextboot_file = loader.getenv("nextboot_conf") | local nextboot_file = loader.getenv("nextboot_conf") | ||||
local nextboot_enable = loader.getenv("nextboot_enable") | |||||
if nextboot_file == nil then | if nextboot_file == nil then | ||||
return | return | ||||
end | end | ||||
-- is nextboot_enable set in nvstore? | |||||
if nextboot_enable == "NO" then | |||||
return | |||||
end | |||||
local text = readFile(nextboot_file, true) | local text = readFile(nextboot_file, true) | ||||
if text == nil then | if text == nil then | ||||
return | return | ||||
end | end | ||||
if text:match("^nextboot_enable=\"NO\"") ~= nil then | if nextboot_enable == nil and | ||||
text:match("^nextboot_enable=\"NO\"") ~= nil then | |||||
-- We're done; nextboot is not enabled | -- We're done; nextboot is not enabled | ||||
return | return | ||||
end | end | ||||
if not config.parse(text) then | if not config.parse(text) then | ||||
print(MSG_FAILPARSECFG:format(nextboot_file)) | print(MSG_FAILPARSECFG:format(nextboot_file)) | ||||
end | end | ||||
-- Attempt to rewrite the first line and only the first line of the | -- Attempt to rewrite the first line and only the first line of the | ||||
-- nextboot_file. We overwrite it with nextboot_enable="NO", then | -- nextboot_file. We overwrite it with nextboot_enable="NO", then | ||||
-- check for that on load. | -- check for that on load. | ||||
-- It's worth noting that this won't work on every filesystem, so we | -- It's worth noting that this won't work on every filesystem, so we | ||||
-- won't do anything notable if we have any errors in this process. | -- won't do anything notable if we have any errors in this process. | ||||
local nfile = io.open(nextboot_file, 'w') | local nfile = io.open(nextboot_file, 'w') | ||||
if nfile ~= nil then | if nfile ~= nil then | ||||
-- We need the trailing space here to account for the extra | -- We need the trailing space here to account for the extra | ||||
-- character taken up by the string nextboot_enable="YES" | -- character taken up by the string nextboot_enable="YES" | ||||
-- Or new end quotation mark lands on the S, and we want to | -- Or new end quotation mark lands on the S, and we want to | ||||
-- rewrite the entirety of the first line. | -- rewrite the entirety of the first line. | ||||
io.write(nfile, "nextboot_enable=\"NO\" ") | io.write(nfile, "nextboot_enable=\"NO\" ") | ||||
io.close(nfile) | io.close(nfile) | ||||
end | end | ||||
loader.setenv("nextboot_enable", "NO") | |||||
end | end | ||||
-- Module exports | -- Module exports | ||||
config.verbose = false | config.verbose = false | ||||
-- The first item in every carousel is always the default item. | -- The first item in every carousel is always the default item. | ||||
function config.getCarouselIndex(id) | function config.getCarouselIndex(id) | ||||
return carousel_choices[id] or 1 | return carousel_choices[id] or 1 | ||||
▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines |