antos-backend/libs/uman.lua
DanyLE 4d97476aab
All checks were successful
gitea-sync/antos-backend/pipeline/head This commit looks good
fix: correct way to process package cache & init neccessary directories when use first logged in
2023-06-20 17:11:58 +02:00

43 lines
1.0 KiB
Lua

local uman={}
uman.userinfo = function(user)
local info = {}
local uid = ulib.uid(user)
if uid then
-- create the following directory structure if does not exists
local dir = require('vfs').ospath("home:///.antos", user)
if not ulib.exists(dir) then
ulib.mkdir(dir)
ulib.chown(dir, uid.id, uid.gid)
end
local setting_dir = dir.."/settings"
if not ulib.exists(setting_dir) then
ulib.mkdir(setting_dir)
ulib.chown(setting_dir, uid.id, uid.gid)
end
local desktop_dir = dir.."/desktop"
if not ulib.exists(desktop_dir) then
ulib.mkdir(desktop_dir)
ulib.chown(desktop_dir, uid.id, uid.gid)
end
-- read the setting
-- use the decodeFile function of JSON instead
local file = require('vfs').ospath("home:///").."/.antos/settings/settings.json"
local st = JSON.decodeFile(file)
if(st) then
info = st
end
info.user = {
username = user,
id = uid.id,
name = user,
groups = uid.groups
}
--print(JSON.encode(info))
return info
else
return {}
end
end
return uman