From 634054425d6f34aca3d7002925fe9f17778e6534 Mon Sep 17 00:00:00 2001 From: "shylinux@163.com" Date: Tue, 13 Sep 2022 11:42:33 +0800 Subject: [PATCH] opt some --- base/cli/forever.go | 19 +++++++------------ base/cli/mirrors.go | 11 ++++++----- base/cli/runtime.go | 1 + base/cli/system.go | 3 +++ base/web/space.go | 2 +- conf.go | 1 + core/code/install.go | 13 ++----------- core/code/xterm.go | 23 +++++++++++++++++++---- misc.go | 8 +++----- misc/node/compile.go | 3 ++- 10 files changed, 45 insertions(+), 39 deletions(-) diff --git a/base/cli/forever.go b/base/cli/forever.go index e2983b73..80740dc4 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -27,8 +27,7 @@ func init() { env = append(env, k, kit.Env(k)) } } - m.Option(CMD_ENV, env) - + m.Optionv(CMD_ENV, env) m.Optionv(CMD_INPUT, os.Stdin) m.Optionv(CMD_OUTPUT, os.Stdout) m.Optionv(CMD_ERRPUT, os.Stderr) @@ -37,12 +36,10 @@ func init() { } m.Cmd(FOREVER, STOP) - if len(arg) > 0 && arg[0] == "space" { - m.Cmdy(FOREVER, kit.Select(os.Args[0], ice.BIN_ICE_BIN, nfs.ExistsFile(m, ice.BIN_ICE_BIN)), - "space", "dial", ice.DEV, ice.OPS, arg[2:]) + if bin := kit.Select(os.Args[0], ice.BIN_ICE_BIN, nfs.ExistsFile(m, ice.BIN_ICE_BIN)); len(arg) > 0 && arg[0] == "space" { + m.Cmdy(FOREVER, bin, "space", "dial", ice.DEV, ice.OPS, arg[2:]) } else { - m.Cmdy(FOREVER, kit.Select(os.Args[0], ice.BIN_ICE_BIN, nfs.ExistsFile(m, ice.BIN_ICE_BIN)), - "serve", START, ice.DEV, "", aaa.USERNAME, aaa.ROOT, aaa.PASSWORD, aaa.ROOT, arg) + m.Cmdy(FOREVER, bin, "serve", START, ice.DEV, "", aaa.USERNAME, aaa.ROOT, aaa.PASSWORD, aaa.ROOT, arg) } }}, RESTART: {Name: "restart", Help: "重启", Hand: func(m *ice.Message, arg ...string) { @@ -59,14 +56,12 @@ func init() { for { logs.Println("run %s", kit.Join(arg, ice.SP)) - msg := m.Cmd(SYSTEM, arg) - if m.Sleep300ms(); IsSuccess(msg) { - logs.Println() + if IsSuccess(m.Cmd(SYSTEM, arg)) { logs.Println(ice.EXIT) // 正常退出 break } else { - m.Sleep("10s") - logs.Println("what %v", msg.FormatMeta()) + logs.Println() + m.Sleep("1s") } } }}, diff --git a/base/cli/mirrors.go b/base/cli/mirrors.go index 84b96401..c14a5137 100644 --- a/base/cli/mirrors.go +++ b/base/cli/mirrors.go @@ -10,11 +10,12 @@ import ( ) const ( - CMD = "cmd" - OSID = "osid" - ALPINE = "alpine" - CENTOS = "centos" - UBUNTU = "ubuntu" + CMD = "cmd" + OSID = "osid" + UBUNTU = "ubuntu" + CENTOS = "centos" + ALPINE = "alpine" + BUSYBOX = "busybox" ) const MIRRORS = "mirrors" diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 951680ab..aa9211dd 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -162,6 +162,7 @@ const ( var ENV_LIST = []string{ TERM, SHELL, CTX_SHY, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER, CTX_DAEMON, + "DOCKER_HOST", } const ( diff --git a/base/cli/system.go b/base/cli/system.go index 6ee621a0..15027bce 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -185,6 +185,9 @@ func init() { arg = kit.Split(arg[0]) } _system_exec(m, _system_cmd(m, arg...)) + if IsSuccess(m) { + m.SetAppend() + } }}, }) } diff --git a/base/web/space.go b/base/web/space.go index 874f5556..0d02f12e 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -88,7 +88,7 @@ func _space_handle(m *ice.Message, safe bool, frame *Frame, c *websocket.Conn, n socket, msg := c, m.Spawn(b) target := kit.Simple(msg.Optionv(ice.MSG_TARGET)) source := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name) - msg.Log("recv", "%v->%v %s %v", source, target, msg.Detailv(), msg.FormatMeta()) + msg.Log("recv", "%v<-%v %s %v", target, source, msg.Detailv(), msg.FormatMeta()) if len(target) == 0 { // 执行命令 if msg.Optionv(ice.MSG_HANDLE, ice.TRUE); safe { // 下行命令 diff --git a/conf.go b/conf.go index b2c0fd2d..be1013f1 100644 --- a/conf.go +++ b/conf.go @@ -294,6 +294,7 @@ const ( // ctx INDEX = "index" ) const ( // mdb + AAA = "aaa" MDB = "mdb" KEY = "key" VALUE = "value" diff --git a/core/code/install.go b/core/code/install.go index 839b99d3..a03d191a 100644 --- a/core/code/install.go +++ b/core/code/install.go @@ -8,7 +8,6 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/cli" - "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/gdb" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" @@ -180,7 +179,7 @@ const INSTALL = "install" func init() { Index.MergeCommands(ice.Commands{ - INSTALL: {Name: "install name port path auto download", Help: "安装", Meta: kit.Dict(), Actions: ice.MergeActions(ice.Actions{ + INSTALL: {Name: "install name port path:text auto download", Help: "安装", Meta: kit.Dict(), Actions: ice.MergeActions(ice.Actions{ web.DOWNLOAD: {Name: "download link path", Help: "下载", Hand: func(m *ice.Message, arg ...string) { _install_download(m) }}, @@ -205,15 +204,7 @@ func init() { _install_stop(m, arg...) }}, gdb.DEBUG: {Name: "debug", Help: "调试", Hand: func(m *ice.Message, arg ...string) { - if cmd := "web.code.xterm"; len(arg) > 0 && arg[0] == ice.RUN { - if len(arg) > 2 && arg[1] == ctx.ACTION && arg[2] == mdb.CREATE { - arg = append(arg, mdb.TYPE, "gdb") - } - m.Cmdy(cmd, arg[1:]) - } else { - m.Cmdy(ctx.COMMAND, cmd) - m.ProcessField(m.ActionKey(), ice.RUN) - } + ProcessXterm(m, []string{mdb.TYPE, "gdb"}) }}, nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) { _install_trash(m, arg...) diff --git a/core/code/xterm.go b/core/code/xterm.go index 23907647..6e0110cf 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -2,6 +2,7 @@ package code import ( "encoding/base64" + "fmt" "io" "os" "os/exec" @@ -10,10 +11,12 @@ import ( pty "shylinux.com/x/creackpty" ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -25,9 +28,7 @@ func _xterm_socket(m *ice.Message, h, t string) { } func _xterm_get(m *ice.Message, h string, must bool) *os.File { t := mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE) - m.Debug("what %v", h) if f, ok := mdb.HashTarget(m, h, func() ice.Any { - m.Debug("what %v", h) if !must { return nil } @@ -76,6 +77,7 @@ func init() { c.Close() } }) + m.Conf("", mdb.HASH, "") }}, mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { switch mdb.HashInputs(m, arg); arg[0] { @@ -96,6 +98,19 @@ func init() { }) mdb.HashRemove(m) }}, + "install": {Name: "install", Help: "安装", Hand: func(m *ice.Message, arg ...string) { + if m.Option(mdb.HASH) != "" { + u := web.OptionUserWeb(m) + host := strings.Split(u.Host, ice.DF)[0] + if host == tcp.LOCALHOST { + host = m.Cmd(tcp.HOST).Append(aaa.IP) + } + m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, host, kit.Select(kit.Select("443", "80", u.Scheme == ice.HTTP), strings.Split(u.Host, ice.DF), 1))) + cmd := kit.Renders(`export ctx_dev={{.Option "httphost"}}{{.Option "ctx_env"}}; ctx_temp=$(mktemp); wget -O $ctx_temp -q $ctx_dev; source $ctx_temp app username {{.Option "user.name"}}`, m) + _xterm_get(m, m.Option(mdb.HASH), true).Write([]byte(cmd + "\n")) + } + m.ProcessHold() + }}, "rename": {Name: "rename", Help: "重命名", Hand: func(m *ice.Message, arg ...string) { mdb.HashModify(m, arg) }}, @@ -119,9 +134,9 @@ func init() { }) } -func ProcessXterm(m *ice.Message, bin string, arg ...string) { +func ProcessXterm(m *ice.Message, args []string, arg ...string) { if len(arg) > 2 && arg[0] == ice.RUN && arg[1] == ctx.ACTION && arg[2] == mdb.CREATE { - arg = append(arg, mdb.TYPE, bin) + arg = append(arg, args...) } ctx.ProcessField(m, "web.code.xterm", nil, arg...) } diff --git a/misc.go b/misc.go index db00aa86..4b0dd7f5 100644 --- a/misc.go +++ b/misc.go @@ -263,12 +263,10 @@ func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string) if m._target = kit.FileLine(cmd.Hand, 3); cmd.RawHand != nil { m._target = kit.Format(cmd.RawHand) } - if key == "select" { - m.Log(LOG_CMDS, "%s.%s %d %v %v", c.Name, key, len(arg), arg, m.Optionv(MSG_FIELDS), - logs.FileLineMeta(kit.Select(m._target, m._source, m.target.Name == MDB))) + if fileline := kit.Select(m._target, m._source, m.target.Name == MDB); key == "select" { + m.Log(LOG_CMDS, "%s.%s %d %v %v", c.Name, key, len(arg), arg, m.Optionv(MSG_FIELDS), logs.FileLineMeta(fileline)) } else { - m.Log(LOG_CMDS, "%s.%s %d %v", c.Name, key, len(arg), arg, - logs.FileLineMeta(kit.Select(m._target, m._source, m.target.Name == MDB))) + m.Log(LOG_CMDS, "%s.%s %d %v", c.Name, key, len(arg), arg, logs.FileLineMeta(fileline)) } if cmd.Hand != nil { diff --git a/misc/node/compile.go b/misc/node/compile.go index 5bc89faa..674c8c5d 100644 --- a/misc/node/compile.go +++ b/misc/node/compile.go @@ -3,6 +3,7 @@ package node import ( "shylinux.com/x/ice" "shylinux.com/x/icebergs/base/cli" + "shylinux.com/x/icebergs/base/mdb" ) const ( @@ -29,7 +30,7 @@ func (s compile) List(m *ice.Message, arg ...string) { s.Code.Source(m, "", arg...) } func (s compile) Xterm(m *ice.Message, arg ...string) { - s.Code.Xterm(m, NODE, arg...) + s.Code.Xterm(m, []string{mdb.TYPE, NODE}, arg...) } func init() { ice.CodeCtxCmd(compile{}) }