1
0
forked from x/icebergs
This commit is contained in:
shylinux@163.com 2022-09-13 11:42:33 +08:00
parent 8d3bb899b1
commit 634054425d
10 changed files with 45 additions and 39 deletions

View File

@ -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")
}
}
}},

View File

@ -12,9 +12,10 @@ import (
const (
CMD = "cmd"
OSID = "osid"
ALPINE = "alpine"
CENTOS = "centos"
UBUNTU = "ubuntu"
CENTOS = "centos"
ALPINE = "alpine"
BUSYBOX = "busybox"
)
const MIRRORS = "mirrors"

View File

@ -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 (

View File

@ -185,6 +185,9 @@ func init() {
arg = kit.Split(arg[0])
}
_system_exec(m, _system_cmd(m, arg...))
if IsSuccess(m) {
m.SetAppend()
}
}},
})
}

View File

@ -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 { // 下行命令

View File

@ -294,6 +294,7 @@ const ( // ctx
INDEX = "index"
)
const ( // mdb
AAA = "aaa"
MDB = "mdb"
KEY = "key"
VALUE = "value"

View File

@ -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...)

View File

@ -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...)
}

View File

@ -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 {

View File

@ -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{}) }