New build system + hysh functionality

This commit is contained in:
2026-02-21 12:49:57 -06:00
parent 0655f2a39e
commit 3cc1459769
23 changed files with 269 additions and 934 deletions

View File

@@ -1,7 +1,7 @@
--:Minify:--
local fs = require("sys.fs")
local targetUser = ({...})[1] or "root"
local targetUser = ({ ... })[1] or "root"
local currentUid = syscall.getuid()
local currentUser = syscall.getUsername(currentUid) or tostring(currentUid)
@@ -26,7 +26,9 @@ else
syscall.write(1, "\n")
break
elseif ch == "\b" then
if #pw > 0 then pw = pw:sub(1, -2); syscall.write(1, "\b \b") end
if #pw > 0 then
pw = pw:sub(1, -2); syscall.write(1, "\b \b")
end
else
pw = pw .. ch
syscall.write(1, "*")
@@ -46,13 +48,13 @@ if currentUid == 0 then
syscall.setuid(targetUid)
end
local pwent = syscall.auth_getpasswd(targetUid)
local shell = (pwent and pwent.shell) or "/bin/hysh"
local pwent = syscall.auth_getpasswd(targetUid)
local shell = (pwent and pwent.shell) or "/bin/hysh"
local homedir = (pwent and pwent.homedir) or "/"
syscall.chdir(homedir)
syscall.setEnviron("HOME", homedir)
syscall.setEnviron("USER", targetUser)
syscall.setEnviron("HOME", homedir)
syscall.setEnviron("USER", targetUser)
syscall.setEnviron("SHELL", shell)
local shellText = fs.readAllText(shell)
@@ -63,10 +65,13 @@ if not shellText then
end
local shellFn, loadErr = load(shellText, "@" .. shell)
if not shellFn then
print("su: cannot load shell: " .. tostring(loadErr))
syscall.exit(1)
return
end
shellFn()
syscall.kill(syscall.getppid())
syscall.spawn(shellFn, targetUser .. ":" .. shell, syscall.getEnviron())
syscall.exit(0)