diff --git a/halyde/config/startupapps.json b/halyde/config/startupapps.json index f624ae2..fb54b34 100644 --- a/halyde/config/startupapps.json +++ b/halyde/config/startupapps.json @@ -1 +1 @@ -["/halyde/scripts/shell.lua"] +["/halyde/scripts/login.lua"] diff --git a/halyde/scripts/login.lua b/halyde/scripts/login.lua new file mode 100644 index 0000000..f0bb1ee --- /dev/null +++ b/halyde/scripts/login.lua @@ -0,0 +1,60 @@ +local fs = require("filesystem") +local json = require("json") + +terminal.clear() + +::retry:: + +local username = terminal.read({ + prefix = "Username: " +}) + +local handle, data, tmpdata = fs.open("/halyde/kernel/userreg.json"), "", nil +repeat + tmpdata = handle:read(math.huge or math.maxinteger) + data = data .. (tmpdata or "") +until not tmpdata +handle:close() + +local userRegistry = json.decode(data) + +local foundUser, uid = false, nil +for i, user in pairs(userRegistry) do + if user.name == username then + foundUser = true + uid = i + break + end +end + +if not foundUser then + print("User does not exist.") + goto retry +end + +local password = terminal.read({ + prefix = "Password: ", + censor = "*" +}) + +local shellPath = "/halyde/scripts/shell.lua" -- TODO: Add shell selection (perhaps in a config file or user prompt?) + +local handle, data, tmpdata = fs.open(shellPath), "", nil +repeat + tmpdata = handle:read(math.huge or math.maxinteger) + data = data .. (tmpdata or "") +until not tmpdata +handle:close() + +-- Prepare userland environment +local temporaryGlobals = _G +_G = nil -- This is so copying doesn't cause an infinite loop +local userland = table.copy(temporaryGlobals) +_G = temporaryGlobals +userland._G = userland + +local result, errorMessage = user.addTask(assert(load(data, "=" .. shellPath, "t", userland)), "shell", uid, password) +if not result then + print(errorMessage) + goto retry +end diff --git a/halyde/scripts/shell.lua b/halyde/scripts/shell.lua index 2d856b5..9276692 100644 --- a/halyde/scripts/shell.lua +++ b/halyde/scripts/shell.lua @@ -129,8 +129,6 @@ end local shareTable = ipc.shareWithAll() shareTable.shell = _G.shell -terminal.clear() - print(shellcfg["startupMessage"]:format(_OSVERSION, shellcfg.splashMessages[math.random(1, #shellcfg.splashMessages)])) while true do coroutine.yield() diff --git a/home/test.lua b/home/test.lua deleted file mode 100644 index 4473c0b..0000000 --- a/home/test.lua +++ /dev/null @@ -1,6 +0,0 @@ -local args = {...} - -print(user.addTask(function() - print("I eat rocks") - print(tsched.getCurrentTask()) -end, "testerpester", tonumber(args[1]), args[2]))