From 4c981b2236608235d0959cedf0e642a4b51bdbc4 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Sun, 28 Aug 2022 20:35:26 +0800 Subject: [PATCH] opt some --- base/cli/mirrors.go | 9 +++++++++ base/mdb/hash.go | 7 ++++++- base/nfs/cat.go | 2 +- base/ssh/script.go | 8 ++++---- core/code/go.go | 6 ++++++ core/code/publish.go | 25 +++++++++++++++---------- core/code/xterm.go | 2 ++ misc/git/repos.go | 7 ++++++- misc/input/input.go | 2 +- misc/node/compile.go | 1 + 10 files changed, 51 insertions(+), 18 deletions(-) diff --git a/base/cli/mirrors.go b/base/cli/mirrors.go index 1000590a..84b96401 100644 --- a/base/cli/mirrors.go +++ b/base/cli/mirrors.go @@ -71,3 +71,12 @@ func IsCentos(m *ice.Message, arg ...string) bool { } return false } +func IsUbuntu(m *ice.Message, arg ...string) bool { + if strings.Contains(m.Conf(RUNTIME, kit.Keys(HOST, OSID)), UBUNTU) { + if len(arg) > 0 { + m.Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, UBUNTU, CMD, "yum install -y "+kit.Select(arg[0], arg, 1)) + } + return true + } + return false +} diff --git a/base/mdb/hash.go b/base/mdb/hash.go index b08082f5..5e4b5e25 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -143,7 +143,9 @@ func _hash_import(m *ice.Message, prefix, chain, file string) { defer Lock(m, prefix, chain)() f, e := miss.OpenFile(kit.Keys(file, JSON)) - m.Assert(e) + if m.Warn(e) { + return + } defer f.Close() list := Map{} @@ -279,17 +281,20 @@ func HashTarget(m *ice.Message, h string, add Any) (p Any) { if pp, ok := p.(Map); ok && len(pp) == 0 { p = nil } + m.Debug("what %v", p) if p == nil && add != nil { switch add := add.(type) { case func(ice.Map) ice.Any: p = add(value) case func() ice.Any: p = add() + m.Debug("what %v", p) default: m.ErrorNotImplement(p) return } value[TARGET] = p + m.Debug("what %v", p) } }) return diff --git a/base/nfs/cat.go b/base/nfs/cat.go index 5df4fa38..8d4a014b 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -41,7 +41,7 @@ func _cat_list(m *ice.Message, name string) { return // 没有权限 } f, e := _cat_find(m, name) - if m.Warn(e, ice.ErrNotFound, name) { + if m.Warn(e) { return // 没有文件 } defer f.Close() diff --git a/base/ssh/script.go b/base/ssh/script.go index 4f604a50..61c38422 100644 --- a/base/ssh/script.go +++ b/base/ssh/script.go @@ -89,7 +89,7 @@ func (f *Frame) alias(m *ice.Message, ls []string) []string { } return ls } -func (f *Frame) parse(m *ice.Message, line string) string { +func (f *Frame) parse(m *ice.Message, h, line string) string { msg := m.Spawn(f.target) ls := f.change(msg, f.alias(msg, kit.Split(strings.TrimSpace(line)))) if len(ls) == 0 { @@ -97,7 +97,7 @@ func (f *Frame) parse(m *ice.Message, line string) string { } msg.Render("", kit.List()) - if msg.Cmdy(ls); msg.IsErrNotFound() { + if msg.Cmdy(ls); h == STDIO && msg.IsErrNotFound() { msg.SetResult().Cmdy(cli.SYSTEM, ls) } @@ -111,7 +111,7 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { if m.I, m.O = f.stdin, f.stdout; h == STDIO { gdb.Event(m, SOURCE_STDIO) - m.Sleep("2.1s") + m.Sleep("3s") } bio := bufio.NewScanner(f.stdin) @@ -141,7 +141,7 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { f.printf(m, "\033[0m") // 清空格式 } } - line = f.parse(m, line) + line = f.parse(m, h, line) } return f } diff --git a/core/code/go.go b/core/code/go.go index c7244c9c..624c1bf1 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -240,6 +240,12 @@ func init() { m.Cmd(mdb.RENDER, mdb.CREATE, k, m.Prefix(k)) m.Cmd(mdb.PLUGIN, mdb.CREATE, k, m.Prefix(k)) } + m.Go(func() { + m.Sleep300ms() + cli.IsAlpine(m, GO) + cli.IsCentos(m, GO) + cli.IsUbuntu(m, GO, "golang") + }) }}, GODOC: {Name: "godoc", Help: "文档", Actions: ice.MergeActions(ice.Actions{ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { diff --git a/core/code/publish.go b/core/code/publish.go index 5f9e45c0..2edb80a1 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -13,6 +13,7 @@ import ( "shylinux.com/x/icebergs/base/gdb" "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" ) @@ -67,8 +68,8 @@ func init() { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.USR_PUBLISH) m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, m.PrefixKey()) - m.Config(ice.CONTEXTS, _contexts) gdb.Watch(m, web.SERVE_START, m.PrefixKey()) + m.Config(ice.CONTEXTS, _contexts) }}, web.SERVE_START: {Name: "serve.start", Help: "服务启动", Hand: func(m *ice.Message, arg ...string) { _publish_file(m, ice.ICE_BIN) @@ -88,8 +89,12 @@ func init() { }}, ice.CONTEXTS: {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) { u := web.OptionUserWeb(m) - m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(u.Host, ice.DF)[0], - kit.Select(kit.Select("443", "80", u.Scheme == ice.HTTP), strings.Split(u.Host, ice.DF), 1))) + host := strings.Split(u.Host, ice.DF)[0] + if host == tcp.LOCALHOST { + host = m.Cmd(tcp.HOST).Append(aaa.IP) + } + m.Option("ctx_env", kit.Select("", " "+kit.JoinKV("=", " ", "ctx_pod", m.Option(ice.MSG_USERPOD)), m.Option(ice.MSG_USERPOD) != "")) + 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))) if len(arg) == 0 { arg = append(arg, ice.MISC, ice.CORE, ice.BASE) @@ -158,15 +163,15 @@ func init() { } var _contexts = kit.Dict( - ice.MISC, `# 下载命令 -export ctx_dev={{.Option "httphost"}} ctx_pod={{.Option "user.pod"}}; ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL $ctx_dev; source $ctx_temp app username {{.Option "user.name"}} -export ctx_dev={{.Option "httphost"}} ctx_pod={{.Option "user.pod"}}; ctx_temp=$(mktemp); wget -O $ctx_temp -q $ctx_dev; source $ctx_temp app username {{.Option "user.name"}} + ice.MISC, `# 下载命令 curl 或 wget +export ctx_dev={{.Option "httphost"}}{{.Option "ctx_env"}}; ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL $ctx_dev; source $ctx_temp app username {{.Option "user.name"}} +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"}} `, - ice.CORE, `# 克隆源码 -git clone {{.Option "remote"}}; cd {{.Option "pathname"}} && source etc/miss.sh port 9020 -`, - ice.BASE, `# 下载工具 + ice.CORE, `# 下载工具 curl 或 wget ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL {{.Cmdx "spide" "shy" "client.url"}}; source $ctx_temp binary ctx_temp=$(mktemp); wget -O $ctx_temp -q {{.Cmdx "spide" "shy" "client.url"}}; source $ctx_temp binary +`, + ice.BASE, `# 下载源码 +git clone {{.Option "remote"}}; cd {{.Option "pathname"}} && source etc/miss.sh `, ) diff --git a/core/code/xterm.go b/core/code/xterm.go index 3223c032..d830e807 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -25,7 +25,9 @@ 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 } diff --git a/misc/git/repos.go b/misc/git/repos.go index c9121b86..efdbcc75 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -49,7 +49,12 @@ func init() { m.Conf(REPOS, mdb.HASH, "") _repos_insert(m, path.Base(kit.Pwd()), kit.Pwd()) m.Cmd(nfs.DIR, ice.USR, "name,path", func(value ice.Maps) { _repos_insert(m, value[mdb.NAME], value[nfs.PATH]) }) - m.Go(func() { m.Sleep300ms(); cli.IsAlpine(m, GIT) }) + m.Go(func() { + m.Sleep300ms() + cli.IsAlpine(m, GIT) + cli.IsCentos(m, GIT) + cli.IsUbuntu(m, GIT) + }) m.Config(REPOS, "https://shylinux.com/x") }}, mdb.CREATE: {Name: "create repos branch name path", Help: "添加", Hand: func(m *ice.Message, arg ...string) { diff --git a/misc/input/input.go b/misc/input/input.go index 1feeb79e..39957550 100644 --- a/misc/input/input.go +++ b/misc/input/input.go @@ -34,7 +34,7 @@ type input struct { } func (s input) Load(m *ice.Message, arg ...string) { - if f, e := nfs.OpenFile(m.Message, m.Option(nfs.FILE)); m.Assert(e) { + if f, e := nfs.OpenFile(m.Message, m.Option(nfs.FILE)); !m.Warn(e) { defer f.Close() // 清空数据 diff --git a/misc/node/compile.go b/misc/node/compile.go index 7acc0814..5bc89faa 100644 --- a/misc/node/compile.go +++ b/misc/node/compile.go @@ -14,6 +14,7 @@ type compile struct { ice.Code regexp string `data:".*.js"` linux string `data:"https://mirrors.tencent.com/nodejs-release/v16.15.1/node-v16.15.1-linux-x64.tar.xz"` + darwin string `data:"https://mirrors.tencent.com/nodejs-release/v16.15.1/node-v16.15.1-darwin-x64.tar.gz"` list string `name:"list path auto xterm listScript order install" help:"编译器"` }