nuageinit: Replace os.execute with Lua libraries

Prefer posix.sys.stat's chmod() to os.execute().  While here, change the
name of the locals to be more descriptive.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit 9b2d92addc31ba6f5696c85d184a45d43e9073dc)
This commit is contained in:
Jose Luis Duran 2024-07-30 00:37:10 +00:00 committed by Baptiste Daroussin
parent c96dbfbd1b
commit 1eaf3331ea

View file

@ -3,8 +3,9 @@
--
-- Copyright(c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
local unistd = require("posix.unistd")
local sys_stat = require("posix.sys.stat")
local lfs = require("lfs")
local pu = require("posix.unistd")
local function warnmsg(str)
io.stderr:write(str .. "\n")
@ -206,12 +207,12 @@ local function addsshkey(homedir, key)
f:write(key .. "\n")
f:close()
if chownak then
os.execute("chmod 0600 " .. ak_path)
pu.chown(ak_path, dirattrs.uid, dirattrs.gid)
sys_stat.chmod(ak_path, 384)
unistd.chown(ak_path, dirattrs.uid, dirattrs.gid)
end
if chowndotssh then
os.execute("chmod 0700 " .. dotssh_path)
pu.chown(dotssh_path, dirattrs.uid, dirattrs.gid)
sys_stat.chmod(dotssh_path, 448)
unistd.chown(dotssh_path, dirattrs.uid, dirattrs.gid)
end
end