From 351809f085043a9e2dbca72ba8c21b0ce2ac612c Mon Sep 17 00:00:00 2001 From: harveyshao Date: Tue, 21 Feb 2023 21:12:27 +0800 Subject: [PATCH] opt some --- base/web/dream.go | 8 ++++++-- base/web/serve.go | 11 ++++++++--- base/web/space.go | 9 +++++++++ conf.go | 2 ++ core/code/autogen.go | 4 ++-- core/code/publish.go | 6 ++---- core/code/sh.go | 3 ++- misc.go | 6 +++++- misc/git/git.go | 3 ++- misc/git/repos.go | 2 +- misc/git/server.go | 20 ++++++++++++-------- 11 files changed, 51 insertions(+), 23 deletions(-) diff --git a/base/web/dream.go b/base/web/dream.go index 2dfa3444..fa6a7a76 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -54,10 +54,10 @@ func _dream_show(m *ice.Message, name string) { defer ToastProcess(m)() defer m.Sleep3s() m.Options(cli.CMD_DIR, kit.Path(p), cli.CMD_ENV, kit.Simple( - cli.CTX_OPS, "http://localhost:"+m.CmdAppend(SERVE, tcp.PORT), + cli.CTX_OPS, "http://localhost:"+m.CmdAppend(SERVE, tcp.PORT), cli.CTX_LOG, ice.VAR_LOG_BOOT_LOG, cli.PATH, cli.BinPath(kit.Path(p, ice.BIN)), cli.USER, ice.Info.Username, kit.EnvSimple(cli.HOME, cli.TERM, cli.SHELL), m.Configv(cli.ENV), - ), cli.CMD_OUTPUT, path.Join(p, ice.BIN_BOOT_LOG)) + ), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG)) defer m.Options(cli.CMD_DIR, "", cli.CMD_ENV, "", cli.CMD_OUTPUT, "") gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME, mdb.TYPE)) m.Cmd(cli.DAEMON, kit.Select(os.Args[0], cli.SystemFind(m, ice.ICE_BIN, nfs.PWD+path.Join(p, ice.BIN), nfs.PWD+ice.BIN)), @@ -107,6 +107,10 @@ func init() { switch arg[0] { case mdb.NAME, nfs.TEMPLATE: _dream_list(m).Cut("name,status,time") + case "repos": + m.Cmdy(SPIDE, ice.OPS, SPIDE_MSG, "/x/list") + // m.Cmdy(SPIDE, ice.DEV, SPIDE_MSG, "/x/list") + // m.Cmdy(SPIDE, ice.SHY, SPIDE_MSG, "/x/list") default: gdb.Event(m, "", arg) } diff --git a/base/web/serve.go b/base/web/serve.go index fa28d398..6e91aa0d 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -4,6 +4,7 @@ import ( "net/http" "net/url" "path" + "regexp" "runtime" "strings" @@ -137,7 +138,12 @@ func _serve_domain(m *ice.Message) string { func() string { return kit.Select("", m.R.Header.Get(Referer), m.R.Method == http.MethodPost) }, func() string { return m.R.Header.Get("X-Host") }, func() string { return ice.Info.Domain }, - func() string { return kit.Format("%s://%s", kit.Select("https", ice.HTTP, m.R.TLS == nil), m.R.Host) }, + func() string { + if b, e := regexp.MatchString("^[0-9.]+$", m.R.Host); b && e == nil { + return kit.Format("%s://%s:%s", kit.Select("https", ice.HTTP, m.R.TLS == nil), m.R.Host, m.Option(tcp.PORT)) + } + return kit.Format("%s://%s", kit.Select("https", ice.HTTP, m.R.TLS == nil), m.R.Host) + }, ) } func _serve_login(m *ice.Message, key string, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) { @@ -178,7 +184,7 @@ func init() { _serve_start(m) }}, SERVE_START: {Hand: func(m *ice.Message, arg ...string) { - if domain := m.Cmdx(SPACE, DOMAIN); ice.Info.Colors { + if domain := m.Cmdx(SPACE, DOMAIN); ice.Info.Colors && m.Option(ice.DEV) == "" { m.Sleep30ms().Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, "\r"+ice.Render(m, ice.RENDER_QRCODE, domain))).Cmd(ssh.PROMPT) } switch runtime.GOOS { @@ -242,7 +248,6 @@ func init() { } } } - m.Debug("what %v", p) m.RenderDownload(p) }}, PP(ice.REQUIRE, ice.NODE_MODULES): {Name: "/require/node_modules/", Help: "依赖库", Hand: func(m *ice.Message, arg ...string) { diff --git a/base/web/space.go b/base/web/space.go index 05ac3802..80b514d7 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -12,6 +12,8 @@ import ( "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/gdb" "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/ssh" "shylinux.com/x/icebergs/base/tcp" kit "shylinux.com/x/toolkits" "shylinux.com/x/websocket" @@ -21,6 +23,7 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) { msg := m.Cmd(SPIDE, tcp.CLIENT, dev, PP(SPACE)) uri := kit.ParseURL(strings.Replace(kit.MergeURL(msg.Append(DOMAIN), mdb.TYPE, ice.Info.NodeType, mdb.NAME, name, SHARE, ice.Info.CtxShare, RIVER, ice.Info.CtxRiver, arg), ice.HTTP, "ws", 1)) args := kit.SimpleKV("type,name,host,port", msg.Append(tcp.PROTOCOL), dev, msg.Append(tcp.HOST), msg.Append(tcp.PORT)) + prints := false m.Go(func() { redial := kit.Dict(m.Configv(REDIAL)) a, b, c := kit.Int(redial["a"]), kit.Int(redial["b"]), kit.Int(redial["c"]) @@ -29,6 +32,12 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) { m.Cmd(tcp.CLIENT, tcp.DIAL, args, func(c net.Conn) { if conn, _, e := websocket.NewClient(c, uri, nil, kit.Int(redial["r"]), kit.Int(redial["w"])); !m.Warn(e, tcp.DIAL, dev, SPACE, uri.String()) { defer mdb.HashCreateDeferRemove(m, kit.SimpleKV("", MASTER, dev, msg.Append(tcp.HOSTNAME)), kit.Dict(mdb.TARGET, conn))() + if !prints { + m.Go(func() { + m.Sleep30ms().Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, "\r"+ice.Render(m, ice.RENDER_QRCODE, m.CmdAppend(SPACE, dev, cli.PWD, mdb.LINK)))).Cmd(ssh.PROMPT) + }) + prints = true + } _space_handle(m.Spawn(), true, dev, conn) i = 0 } diff --git a/conf.go b/conf.go index 0355f43d..12752548 100644 --- a/conf.go +++ b/conf.go @@ -120,6 +120,8 @@ const ( // DIR USR_LOCAL_EXPORT = "usr/local/export/" USR_LOCAL_REPOS = "usr/local/repos/" + VAR_LOG_BOOT_LOG = "var/log/boot.log" + VAR_TMP = "var/tmp/" VAR_LOG = "var/log/" VAR_CONF = "var/conf/" diff --git a/core/code/autogen.go b/core/code/autogen.go index 94643914..0be79cf9 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -54,9 +54,9 @@ func _autogen_version(m *ice.Message) { m.Cmdy(cli.SYSTEM, GIT, ice.INIT) m.Cmd(cli.SYSTEM, GIT, "remote", "add", "origin", "https://"+mod) m.Cmd(cli.SYSTEM, GIT, "add", ice.GO_MOD, ice.SRC, ice.ETC_MISS_SH) - m.Cmd(nfs.DEFS, ".gitignore", _git_ignore) m.Cmd("web.code.git.repos", mdb.CREATE, nfs.ORIGIN, "https://"+mod, mdb.NAME, path.Base(mod), nfs.PATH, nfs.PWD) } + m.Cmd(nfs.DEFS, ".gitignore", _git_ignore) m.Cmd(nfs.DEFS, ice.SRC_BINPACK_GO, `package main`+ice.NL) m.Cmd(nfs.SAVE, ice.SRC_VERSION_GO, kit.Format(_version_template, _autogen_gits(m, nfs.MODULE, _autogen_mod(m, ice.GO_MOD), tcp.HOSTNAME, ice.Info.Hostname, aaa.USERNAME, ice.Info.Username))) m.Cmd(cli.SYSTEM, "gofmt", "-w", ice.SRC_VERSION_GO) @@ -162,7 +162,7 @@ fi require miss.sh ish_miss_prepare_compile ish_miss_prepare_develop -ish_miss_prepare_operate +ish_miss_prepare_project ish_miss_make; if [ -n "$*" ]; then ish_miss_serve "$@"; fi ` diff --git a/core/code/publish.go b/core/code/publish.go index df387e96..559faf97 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -87,14 +87,12 @@ func init() { Index.MergeCommands(ice.Commands{ PUBLISH: {Name: "publish path auto create volcanos icebergs intshell", Help: "发布", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Config(ice.CONTEXTS, _contexts) }}, - mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.DIR, arg[1:]).Cut("path,size,time").ProcessAgain() - }}, + mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg[1:]).Cut("path,size,time").ProcessAgain() }}, web.SERVE_START: {Hand: func(m *ice.Message, arg ...string) { if runtime.GOOS == cli.WINDOWS { return } - _publish_file(m, ice.ICE_BIN) + // _publish_file(m, ice.ICE_BIN) }}, ice.VOLCANOS: {Help: "火山架", Hand: func(m *ice.Message, arg ...string) { defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }() diff --git a/core/code/sh.go b/core/code/sh.go index 7ecc077d..0fb77378 100644 --- a/core/code/sh.go +++ b/core/code/sh.go @@ -12,7 +12,8 @@ import ( ) func _sh_exec(m *ice.Message, arg ...string) { - m.Cmdy(cli.SYSTEM, SH, "-c", kit.Format(_sh_template, m.Option(ice.MSG_USERHOST), m.Option(ice.MSG_USERPOD), path.Join(arg[2], arg[1]))).StatusTime() + m.Cmdy(cli.SYSTEM, SH, "-c", kit.Format(_sh_template, m.Option(ice.MSG_USERHOST), m.Option(ice.MSG_USERPOD), path.Join(arg[2], arg[1]))) + m.StatusTime("script", kit.Renders(kit.Format(`export ctx_dev={{.Option "user.host"}}; temp=$(mktemp); wget -O $temp -q $ctx_dev; source $temp %s`, path.Join(arg[2], arg[1])), m)) } const SH = nfs.SH diff --git a/misc.go b/misc.go index 405ab726..36c0e78c 100644 --- a/misc.go +++ b/misc.go @@ -273,13 +273,17 @@ func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string) return c._action(m, cmd, key, arg[1], h, arg[2:]...) } } - // if len(arg) > 0 && arg[0] != COMMAND { if len(arg) > 0 { if h, ok := cmd.Actions[arg[0]]; ok { return c._action(m, cmd, key, arg[0], h, arg[1:]...) } } } + if len(arg) > 0 && arg[0] == ACTION { + if arg[1] == "inputs" { + return m + } + } return m.CmdHand(cmd, key, arg...) } func (c *Context) _action(m *Message, cmd *Command, key string, sub string, h *Action, arg ...string) *Message { diff --git a/misc/git/git.go b/misc/git/git.go index 1e2316ef..6a5ff33a 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -8,10 +8,11 @@ import ( "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/core/code" + kit "shylinux.com/x/toolkits" ) func _git_url(m *ice.Message, repos string) string { - return web.MergeLink(m, "/x/"+path.Join(repos)+".git") + return kit.MergeURL2(m.Option(ice.MSG_USERHOST), "/x/"+path.Join(repos)+".git") } func _git_dir(arg ...string) string { return path.Join(path.Join(arg...), ".git") } func _git_cmd(m *ice.Message, arg ...string) *ice.Message { return m.Cmd(cli.SYSTEM, GIT, arg) } diff --git a/misc/git/repos.go b/misc/git/repos.go index 49547140..dd4f8cbf 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -104,7 +104,7 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit file = "" } if repos, e := gogit.OpenRepository(dir); !m.Warn(e, ice.ErrNotFound, dir) { - if refer, e := repos.LookupReference(REFS_TAGS + commit); !m.Warn(e, ice.ErrNotFound, branch) { + if refer, e := repos.LookupReference(REFS_TAGS + commit); e == nil { commit = refer.Oid.String() } } diff --git a/misc/git/server.go b/misc/git/server.go index 6caf48ce..01cfb539 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -93,6 +93,12 @@ const SERVER = "server" func init() { web.Index.MergeCommands(ice.Commands{"/x/": {Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) { + if arg[0] == ice.LIST { + m.Cmd("web.code.git.server", func(value ice.Maps) { + m.Push(nfs.REPOS, web.MergeLink(m, "/x/"+value[nfs.REPOS]+".git")) + }) + return + } if !m.IsCliUA() || strings.Contains(arg[0], ice.AT) { if strings.Contains(arg[0], ice.AT) { ls := strings.Split(arg[0], ice.AT) @@ -140,7 +146,7 @@ func init() { _repos_cat(m, dir, arg[1], arg[2], kit.Select("", arg, 3)) } }}, - SERVER: {Name: "server repos branch commit path auto clone create import", Help: "服务器", Actions: ice.MergeActions(ice.Actions{ + SERVER: {Name: "server repos branch commit path auto create import", Help: "服务器", Actions: ice.MergeActions(ice.Actions{ mdb.CREATE: {Name: "create name*", Hand: func(m *ice.Message, arg ...string) { _repos_init(m, path.Join(ice.USR_LOCAL_REPOS, m.Option(mdb.NAME))) }}, @@ -153,8 +159,8 @@ func init() { }) }}, nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { - m.Assert(m.Option(nfs.PATH) != "") - nfs.Trash(m, path.Join(ice.USR_LOCAL_REPOS, m.Option(nfs.PATH))) + m.Assert(m.Option(nfs.REPOS) != "") + nfs.Trash(m, path.Join(ice.USR_LOCAL_REPOS, m.Option(nfs.REPOS))) }}, web.DREAM_INPUTS: {Hand: func(m *ice.Message, arg ...string) { switch arg[0] { @@ -162,9 +168,6 @@ func init() { m.Cmd("", func(value ice.Maps) { m.Push(nfs.PATH, _git_url(m, value[nfs.PATH])) }) } }}, - "clone": {Help: "克隆", Hand: func(m *ice.Message, arg ...string) { - m.EchoScript("git clone https://shylinux.com/x/contexts && cd contexts && source etc/miss.sh") - }}, "inner": {Help: "编辑器", Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 || arg[0] != ice.RUN { arg = []string{path.Join(ice.USR_LOCAL_REPOS, arg[0]), kit.Select("README.md", arg, 3)} @@ -181,8 +184,9 @@ func init() { }}, }, gdb.EventAction(web.DREAM_INPUTS)), Hand: func(m *ice.Message, arg ...string) { if m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_REPOS); len(arg) == 0 { - m.Option(nfs.DIR_TYPE, nfs.TYPE_DIR) - m.Cmdy(nfs.DIR, nfs.PWD, func(value ice.Maps) { m.PushScript("git clone " + _git_url(m, value[nfs.PATH])) }).Cut("time,path,size,script,action").RenameAppend("path", "repos") + m.Cmdy(nfs.DIR, nfs.PWD, "time,name,size,action", kit.Dict(nfs.DIR_TYPE, nfs.TYPE_DIR), func(value ice.Maps) { + m.PushScript("git clone " + _git_url(m, value[mdb.NAME])) + }).Cut("time,name,size,script,action").RenameAppend(mdb.NAME, nfs.REPOS).SortStrR(mdb.TIME) } else if dir := path.Join(m.Option(nfs.DIR_ROOT), arg[0]); len(arg) == 1 { _repos_branch(m, dir) } else if len(arg) == 2 {