From 37cab25dc01029e6429298355fdf587fbc517529 Mon Sep 17 00:00:00 2001 From: shy Date: Fri, 1 Dec 2023 12:05:26 +0800 Subject: [PATCH] opt mirrors.go --- base/cli/mirrors.go | 11 +++-------- base/web/option.go | 2 +- base/web/render.go | 2 +- base/web/spide.go | 2 +- base/web/token.go | 2 ++ core/code/py.go | 20 ++++++++++++++------ core/code/upgrade.go | 19 ++++++++++++------- core/wiki/spark.go | 2 +- misc/git/client.go | 3 +++ misc/git/repos.go | 9 +++++++++ misc/java/java.go | 6 +++--- misc/node/node.go | 2 +- misc/node/npm.go | 2 +- 13 files changed, 52 insertions(+), 30 deletions(-) diff --git a/base/cli/mirrors.go b/base/cli/mirrors.go index 8efc3a3a..de147cb6 100644 --- a/base/cli/mirrors.go +++ b/base/cli/mirrors.go @@ -17,8 +17,6 @@ const ( ADD = "add" OSID = "osid" REPOS = "repos" - UBUNTU = "ubuntu" - CENTOS = "centos" ALPINE = "alpine" BUSYBOX = "busybox" RELEASE = "release" @@ -110,12 +108,9 @@ func insert(m *ice.Message, sys, cmd string, arg ...string) bool { func IsAlpine(m *ice.Message, arg ...string) bool { return insert(m, ALPINE, "system apk add", arg...) } -func IsCentos(m *ice.Message, arg ...string) bool { - return insert(m, CENTOS, "system yum install -y", arg...) -} -func IsUbuntu(m *ice.Message, arg ...string) bool { - return insert(m, UBUNTU, "system apt get -y", arg...) +func IsRedhat(m *ice.Message, arg ...string) bool { + return insert(m, "rhel", "system yum install -y", arg...) } func IsSystem(m *ice.Message, arg ...string) bool { - return IsAlpine(m, arg...) || IsCentos(m, arg...) || IsUbuntu(m, arg...) + return IsAlpine(m, arg...) || IsRedhat(m, arg...) } diff --git a/base/web/option.go b/base/web/option.go index b8e461c2..51235584 100644 --- a/base/web/option.go +++ b/base/web/option.go @@ -149,7 +149,7 @@ func ToastProcess(m *ice.Message, arg ...ice.Any) func() { Toast(m, toastContent(m, ice.PROCESS), arg...) return func() { Toast(m, toastContent(m, ice.SUCCESS)) } } -func GoToast(m *ice.Message, title string, cb func(toast func(string, int, int)) []string) *ice.Message { +func GoToast(m *ice.Message, title string, cb func(toast func(name string, count, total int)) []string) *ice.Message { _total := 0 toast := func(name string, count, total int) { kit.If(total == 0, func() { total = 1 }) diff --git a/base/web/render.go b/base/web/render.go index 7a9a1a8c..1c25ba0a 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -124,7 +124,7 @@ func RenderMain(m *ice.Message) *ice.Message { if m.IsCliUA() { return m.RenderDownload(path.Join(ice.USR_INTSHELL, ice.INDEX_SH)) } - m.Options(nfs.SCRIPT, ice.SRC_MAIN_JS, nfs.VERSION, RenderVersion(m)+kit.Select("", "&pod="+m.Option(ice.MSG_USERPOD), m.Option(ice.MSG_USERPOD) != "")) + m.Options(nfs.SCRIPT, kit.MergeURL(ice.SRC_MAIN_JS, kit.Dict(nfs.VERSION, RenderVersion(m), ice.POD, m.Option(ice.MSG_USERPOD)))) return m.RenderResult(kit.Renders(m.Cmdx(nfs.CAT, ice.SRC_MAIN_HTML), m)) } func RenderCmds(m *ice.Message, cmds ...ice.Any) { diff --git a/base/web/spide.go b/base/web/spide.go index 20446e11..a2bc5d93 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -398,7 +398,7 @@ func SpidePost(m *ice.Message, arg ...ice.Any) ice.Any { func SpideDelete(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(http.MethodDelete, arg)) } -func SpideSave(m *ice.Message, file, link string, cb func(count int, total int, value int)) *ice.Message { +func SpideSave(m *ice.Message, file, link string, cb func(count, total, value int)) *ice.Message { return m.Cmd(Prefix(SPIDE), ice.DEV, SPIDE_SAVE, file, http.MethodGet, link, cb) } func SpideOrigin(m *ice.Message, name string) string { diff --git a/base/web/token.go b/base/web/token.go index 9009f222..592d8b97 100644 --- a/base/web/token.go +++ b/base/web/token.go @@ -5,6 +5,7 @@ import ( "strings" ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" @@ -41,6 +42,7 @@ func init() { line = strings.ReplaceAll(line, "%3a", ":") kit.IfNoKey(host, kit.ParseURL(line).Host, func(p string) { list = append(list, line) }) }).Cmd(nfs.SAVE, kit.HomePath(FILE), strings.Join(list, lex.NL)+lex.NL) + m.Cmd(cli.SYSTEM, "git", "config", "--global", "credential.helper", "store") m.ProcessClose() }}, }, StatsAction(), mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,type,name,text", mdb.EXPIRE, mdb.MONTH)), Hand: func(m *ice.Message, arg ...string) { diff --git a/core/code/py.go b/core/code/py.go index 74aef20c..b180a697 100644 --- a/core/code/py.go +++ b/core/code/py.go @@ -5,20 +5,23 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" + "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" ) func _py_exec(m *ice.Message, p string) { if _, e := nfs.DiskFile.StatFile(p); e == nil { - m.Cmdy(cli.SYSTEM, PYTHON, p) + m.Cmdy(cli.SYSTEM, mdb.Config(m, cli.CLI), p) } else if b, e := nfs.ReadFile(m, p); e == nil { - m.Cmdy(cli.SYSTEM, PYTHON, "-c", string(b)) + m.Cmdy(cli.SYSTEM, mdb.Config(m, cli.CLI), "-c", string(b)) } } const ( - PYTHON = "python" + PYTHON = "python" + PYTHON2 = "python2" + PYTHON3 = "python3" ) const PY = nfs.PY @@ -26,12 +29,17 @@ func init() { Index.MergeCommands(ice.Commands{ PY: {Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + mdb.Config(m, cli.CLI, PYTHON) cli.IsAlpine(m, PYTHON, "python3") - cli.IsCentos(m, PYTHON, "python2") + if cli.IsRedhat(m, PYTHON2, "python2") { + mdb.Config(m, cli.CLI, PYTHON2) + } + }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + ProcessXterm(m, mdb.Config(m, cli.CLI)+" -i "+path.Join(arg[2], arg[1]), "") }}, - mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { ProcessXterm(m, PYTHON+" -i "+path.Join(arg[2], arg[1]), "") }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _py_exec(m, path.Join(arg[2], arg[1])) }}, TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, DEMO_PY)) }}, - }, PlugAction())}, + }, PlugAction(), ctx.ConfAction(cli.CLI))}, }) } diff --git a/core/code/upgrade.go b/core/code/upgrade.go index 65f96cb7..c254d3a5 100644 --- a/core/code/upgrade.go +++ b/core/code/upgrade.go @@ -46,13 +46,18 @@ func init() { uri = kit.MergeURL2(os.Getenv(cli.CTX_DEV), web.CHAT_POD+p, cli.GOOS, runtime.GOOS, cli.GOARCH, runtime.GOARCH) }) dir := path.Join(kit.Format(value[nfs.PATH]), kit.Format(value[nfs.FILE])) - switch web.SpideSave(m, dir, uri, nil); value[mdb.TYPE] { - case nfs.TAR: - m.Cmd(cli.SYSTEM, nfs.TAR, "xf", dir, "-C", path.Dir(dir)) - // m.Cmd(nfs.TAR, mdb.EXPORT, dir, "-C", path.Dir(dir)) - case ice.BIN: - os.Chmod(dir, ice.MOD_DIR) - } + web.GoToast(m, m.PrefixKey(), func(toast func(name string, count, total int)) []string { + switch web.SpideSave(m, dir, uri, func(count, total, value int) { + toast(dir, count, total) + }); value[mdb.TYPE] { + case nfs.TAR: + m.Cmd(cli.SYSTEM, nfs.TAR, "xf", dir, "-C", path.Dir(dir)) + // m.Cmd(nfs.TAR, mdb.EXPORT, dir, "-C", path.Dir(dir)) + case ice.BIN: + os.Chmod(dir, ice.MOD_DIR) + } + return nil + }) m.Cmdy(nfs.DIR, dir, "time,size,path,hash") }) if web.ToastSuccess(m); m.Option(ice.EXIT) == ice.TRUE { diff --git a/core/wiki/spark.go b/core/wiki/spark.go index 1a2012d6..45fe9fd4 100644 --- a/core/wiki/spark.go +++ b/core/wiki/spark.go @@ -97,7 +97,7 @@ func init() { }), Hand: func(m *ice.Message, arg ...string) { if kit.Ext(arg[0]) == "md" { _spark_md(m, arg...) - } else if arg[0] == SHELL && kit.IsIn(kit.Select("", arg, 1), cli.ALPINE, cli.CENTOS, cli.LINUX, cli.DARWIN, cli.MACOS, cli.WINDOWS) { + } else if arg[0] == SHELL && kit.IsIn(kit.Select("", arg, 1), cli.ALPINE, "centos", cli.LINUX, cli.DARWIN, cli.MACOS, cli.WINDOWS) { _spark_tabs(m, arg...) } else { if arg = _name(m, arg); arg[0] == SHELL && len(arg) > 3 && arg[2] == "with" && arg[3] == cli.ECHO { diff --git a/misc/git/client.go b/misc/git/client.go index 6b15d41d..a694f6cb 100644 --- a/misc/git/client.go +++ b/misc/git/client.go @@ -13,6 +13,9 @@ const CLIENT = "client" func init() { Index.MergeCommands(ice.Commands{ CLIENT: {Help: "代码库", Actions: ice.MergeActions(ice.Actions{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + cli.IsRedhat(m, GIT, "git") + }}, cli.ORDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(code.INSTALL, cli.ORDER, mdb.Config(m, nfs.SOURCE), "_install/bin") m.Cmd(code.INSTALL, cli.ORDER, mdb.Config(m, nfs.SOURCE), "_install/libexec/git-core") diff --git a/misc/git/repos.go b/misc/git/repos.go index be1135d9..c5ab490f 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -471,6 +471,15 @@ func init() { m.Echo(_repos_remote(m, _repos_origin(m, _repos_open(m, path.Base(kit.Path("")))))) }}, mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { + switch m.Option(ctx.ACTION) { + case CLONE: + switch arg[0] { + case ORIGIN: + m.Push(arg[0], "https://shylinux.com/x/icons") + m.Push(arg[0], "https://shylinux.com/x/volcanos") + m.Push(arg[0], "https://shylinux.com/x/icebergs") + } + } switch arg[0] { case MESSAGE: ls := kit.Split(m.Option(nfs.FILE), " /") diff --git a/misc/java/java.go b/misc/java/java.go index 88bcd9be..946cfe34 100644 --- a/misc/java/java.go +++ b/misc/java/java.go @@ -27,9 +27,9 @@ func (s java) Init(m *ice.Message) { cli.IsAlpine(m.Message, JAVA, "openjdk8") cli.IsAlpine(m.Message, JAVAC, "openjdk8") cli.IsAlpine(m.Message, MVN, "maven openjdk8") - cli.IsCentos(m.Message, JAVA, "java-1.8.0-openjdk-devel.x86_64") - cli.IsCentos(m.Message, JAVAC, "java-1.8.0-openjdk-devel.x86_64") - cli.IsCentos(m.Message, MVN, "maven java-1.8.0-openjdk-devel.x86_64") + cli.IsRedhat(m.Message, JAVA, "java-1.8.0-openjdk-devel.x86_64") + cli.IsRedhat(m.Message, JAVAC, "java-1.8.0-openjdk-devel.x86_64") + cli.IsRedhat(m.Message, MVN, "maven java-1.8.0-openjdk-devel.x86_64") s.Lang.Init(m, nfs.SCRIPT, m.Resource("")) } func (s java) Render(m *ice.Message, arg ...string) { diff --git a/misc/node/node.go b/misc/node/node.go index d8f782f1..b1e1e016 100644 --- a/misc/node/node.go +++ b/misc/node/node.go @@ -18,7 +18,7 @@ type node struct { func (s node) Init(m *ice.Message) { cli.IsAlpine(m.Message, NODE, "nodejs") - cli.IsCentos(m.Message, NODE, "nodejs") + cli.IsRedhat(m.Message, NODE, "nodejs") } func (s node) List(m *ice.Message, arg ...string) { s.Code.Source(m, "", arg...) diff --git a/misc/node/npm.go b/misc/node/npm.go index 2b22e368..3e32317e 100644 --- a/misc/node/npm.go +++ b/misc/node/npm.go @@ -15,7 +15,7 @@ type npm struct { func (s npm) Init(m *ice.Message) { cli.IsAlpine(m.Message, NPM) - cli.IsCentos(m.Message, NPM, "nodejs") + cli.IsRedhat(m.Message, NPM, "nodejs") } func (s npm) List(m *ice.Message) { m.Cmdy(nfs.DIR, ice.USR_MODULES)