polish up installer
This commit is contained in:
parent
c7d7f9be98
commit
6cf175e5f0
55
install.lua
55
install.lua
@ -64,34 +64,39 @@ local function main()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
log.info(#toDownload .. " files to download")
|
if #toDownload > 0 then
|
||||||
for k, v in ipairs(toDownload) do
|
log.info(#toDownload .. " files to download")
|
||||||
if not fs.exists("/tmp") then
|
for k, v in ipairs(toDownload) do
|
||||||
fs.makeDir("/tmp")
|
if not fs.exists("/tmp") then
|
||||||
|
fs.makeDir("/tmp")
|
||||||
|
end
|
||||||
|
log.info("Downloading '" .. v.dest .. "'")
|
||||||
|
local filerequest = http.get(repoRoot .. v.src)
|
||||||
|
local tempfile = fs.open("/tmp/" .. v.hash .. ".lua", "w")
|
||||||
|
tempfile.write(filerequest.readAll())
|
||||||
|
filerequest.close()
|
||||||
|
tempfile.close()
|
||||||
|
-- Check the validity of the hash, this acts both as a checksum
|
||||||
|
-- and a way to raise an error if the index is incorrect
|
||||||
|
tempfile = fs.open("/tmp/" .. v.hash .. ".lua", "r")
|
||||||
|
local filehash = hash.sha256(tempfile.readAll() .. "\n") -- newline is weird hack because of awkward hashes
|
||||||
|
tempfile.close()
|
||||||
|
if filehash ~= v.hash then
|
||||||
|
log.error("File " .. v.dest .. " (from " .. v.src .. ") has a mismatched hash.")
|
||||||
|
log.error("Installation aborted. Remember to clean /tmp manually.")
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
log.info("Downloading '" .. v.dest .. "'")
|
|
||||||
local filerequest = http.get(repoRoot .. v.src)
|
log.info("Installing")
|
||||||
local tempfile = fs.open("/tmp/" .. v.hash .. ".lua", "w")
|
for k, v in ipairs(toDownload) do
|
||||||
tempfile.write(filerequest.readAll())
|
fs.delete(v.dest)
|
||||||
filerequest.close()
|
fs.move("/tmp/" .. v.hash .. ".lua", v.dest)
|
||||||
tempfile.close()
|
|
||||||
-- Check the validity of the hash, this acts both as a checksum
|
|
||||||
-- and a way to raise an error if the index is incorrect
|
|
||||||
tempfile = fs.open("/tmp/" .. v.hash .. ".lua", "r")
|
|
||||||
local filehash = hash.sha256(tempfile.readAll() .. "\n") -- newline is weird hack because of awkward hashes
|
|
||||||
tempfile.close()
|
|
||||||
if filehash ~= v.hash then
|
|
||||||
log.error("File " .. v.dest .. " (from " .. v.src .. ") has a mismatched hash.")
|
|
||||||
log.error("Installation aborted.")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.info("Nothing to do")
|
||||||
end
|
end
|
||||||
|
|
||||||
log.info("Installing")
|
|
||||||
for k, v in ipairs(toDownload) do
|
|
||||||
fs.move("/tmp/" .. v.hash .. ".lua", v.dest)
|
|
||||||
end
|
|
||||||
|
|
||||||
log.info("Installation complete!")
|
log.info("Installation complete!")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user