1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-04-11 12:38:38 +08:00
parent 29d7a98ec6
commit 25ac2e3a1b
3 changed files with 17 additions and 12 deletions

View File

@ -11,4 +11,4 @@ var Index = &ice.Context{Name: CLI, Help: "命令模块"}
func Prefix(arg ...string) string { return kit.Keys(CLI, arg) } func Prefix(arg ...string) string { return kit.Keys(CLI, arg) }
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, FOREVER, MIRRORS, QRCODE) } func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, FOREVER, MIRRORS, QRCODE, SUDO) }

View File

@ -54,7 +54,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm {
} }
func _xterm_echo(m *ice.Message, h string, str string) { func _xterm_echo(m *ice.Message, h string, str string) {
m.Options(ice.MSG_DAEMON, mdb.HashSelectField(m, h, cli.DAEMON), ice.MSG_COUNT, "0") m.Options(ice.MSG_DAEMON, mdb.HashSelectField(m, h, cli.DAEMON), ice.MSG_COUNT, "0")
// m.Options(ice.LOG_DISABLE, ice.TRUE) m.Options(ice.LOG_DISABLE, ice.TRUE)
web.PushNoticeGrow(m, h, str) web.PushNoticeGrow(m, h, str)
} }
func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) { func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) {

View File

@ -7,6 +7,7 @@ import (
"path" "path"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
@ -45,21 +46,25 @@ var list = map[string]handler{}
func AddCommand(key string, cb handler) { list[key] = cb } func AddCommand(key string, cb handler) { list[key] = cb }
func Command(m *ice.Message, dir string, cli string, arg ...string) (XTerm, error) { func Command(m *ice.Message, dir string, cmd string, arg ...string) (XTerm, error) {
if cb, ok := list[path.Base(cli)]; ok { if cb, ok := list[path.Base(cmd)]; ok {
m.Debug("find shell %s %s", cli, kit.FileLines(cb)) m.Debug("find shell %s %s", cmd, kit.FileLines(cb))
return cb(m.Spawn(), arg...) return cb(m.Spawn(), arg...)
} }
cmd := exec.Command(cli, arg...) if m.Cmd(cli.SUDO, cmd).Length() > 0 {
cmd.Dir = nfs.MkdirAll(m, kit.Path(dir)) m.Debug("find sudo %s", cmd)
cmd.Env = append(cmd.Env, os.Environ()...) cmd, arg = cli.SUDO, kit.Simple(cmd, arg)
cmd.Env = append(cmd.Env, "TERM=xterm") }
p := exec.Command(cmd, arg...)
p.Dir = nfs.MkdirAll(m, kit.Path(dir))
p.Env = append(p.Env, os.Environ()...)
p.Env = append(p.Env, "TERM=xterm")
if pty, tty, err := Open(); err != nil { if pty, tty, err := Open(); err != nil {
return nil, err return nil, err
} else { } else {
Setsid(cmd) Setsid(p)
cmd.Stdin, cmd.Stdout, cmd.Stderr = tty, tty, tty p.Stdin, p.Stdout, p.Stderr = tty, tty, tty
return &xterm{cmd, pty}, cmd.Start() return &xterm{p, pty}, p.Start()
} }
} }
func PushShell(m *ice.Message, xterm XTerm, cmds []string, cb func(string)) { func PushShell(m *ice.Message, xterm XTerm, cmds []string, cb func(string)) {