diff --git a/base/cli/forever.go b/base/cli/forever.go index 4e56a936..57a81d09 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -37,7 +37,7 @@ func init() { } m.Cmd(FOREVER, STOP) - m.Cmdy(FOREVER, kit.Select(os.Args[0], nfs.PWD+ice.BIN_ICE_BIN, kit.FileExists(ice.BIN_ICE_BIN)), + m.Cmdy(FOREVER, kit.Select(os.Args[0], nfs.PWD+ice.BIN_ICE_BIN, nfs.ExistsFile(m, ice.BIN_ICE_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) { diff --git a/base/cli/mirrors.go b/base/cli/mirrors.go index e5e1db13..1000590a 100644 --- a/base/cli/mirrors.go +++ b/base/cli/mirrors.go @@ -35,15 +35,6 @@ func init() { if IsAlpine(m, "git"); !IsAlpine(m, "go", "go git") { mdb.ZoneInsert(m, CLI, "go", CMD, kit.Format("install download https://golang.google.cn/dl/go1.15.5.%s-%s.tar.gz usr/local", runtime.GOOS, runtime.GOARCH)) } - - IsAlpine(m, "npm") - IsAlpine(m, "node", "nodejs") - IsAlpine(m, "java", "openjdk8") - IsAlpine(m, "javac", "openjdk8") - IsAlpine(m, "mvn", "maven openjdk8") - IsAlpine(m, "python", "python2") - IsAlpine(m, "python2") - IsAlpine(m, "python3") }) }}, mdb.INSERT: {Name: "insert cli osid cmd", Help: "添加"}, @@ -65,7 +56,16 @@ func init() { func IsAlpine(m *ice.Message, arg ...string) bool { if strings.Contains(m.Conf(RUNTIME, kit.Keys(HOST, OSID)), ALPINE) { if len(arg) > 0 { - m.Cmd(mdb.INSERT, m.Prefix(MIRRORS), "", mdb.ZONE, arg[0], OSID, ALPINE, CMD, "system apk add "+kit.Select(arg[0], arg, 1)) + m.Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, ALPINE, CMD, "system apk add "+kit.Select(arg[0], arg, 1)) + } + return true + } + return false +} +func IsCentos(m *ice.Message, arg ...string) bool { + if strings.Contains(m.Conf(RUNTIME, kit.Keys(HOST, OSID)), CENTOS) { + if len(arg) > 0 { + m.Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, CENTOS, CMD, "yum install -y "+kit.Select(arg[0], arg, 1)) } return true } diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 9b183f1c..39716a54 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -27,6 +27,8 @@ func _runtime_init(m *ice.Message) { m.Conf(RUNTIME, kit.Keys(HOST, PID), os.Getpid()) m.Conf(RUNTIME, kit.Keys(HOST, HOME), kit.Env(HOME)) m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), runtime.GOMAXPROCS(0)) + m.Conf(RUNTIME, mdb.META, "") + m.Conf(RUNTIME, mdb.HASH, "") // 启动目录 boot m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), kit.Env("HOSTNAME")) @@ -47,9 +49,9 @@ func _runtime_init(m *ice.Message) { m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1) bin := _system_find(m, os.Args[0]) m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), bin) - if s, e := os.Stat(bin); e == nil { + if s, e := nfs.StatFile(m, bin); e == nil { m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), kit.FmtSize(s.Size())) - if f, e := os.Open(bin); e == nil { + if f, e := nfs.OpenFile(m, bin); e == nil { defer f.Close() m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), kit.Hashs(f)) } diff --git a/base/cli/system.go b/base/cli/system.go index 11160678..73f74b41 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -42,7 +42,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd { // 运行目录 if cmd.Dir = m.Option(CMD_DIR); len(cmd.Dir) > 0 { - if m.Logs(mdb.EXPORT, CMD_DIR, cmd.Dir); !kit.FileExists(cmd.Dir) { + if m.Logs(mdb.EXPORT, CMD_DIR, cmd.Dir); !nfs.ExistsFile(m, cmd.Dir) { file.MkdirAll(cmd.Dir, ice.MOD_DIR) } } @@ -81,7 +81,7 @@ func _system_find(m *ice.Message, bin string, dir ...string) string { dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...) } for _, p := range dir { - if kit.FileExists(path.Join(p, bin)) { + if nfs.ExistsFile(m, path.Join(p, bin)) { return kit.Path(path.Join(p, bin)) } } diff --git a/base/ctx/command.go b/base/ctx/command.go index 18f9b90a..2533a128 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -158,7 +158,7 @@ func FileURI(dir string) string { if strings.HasPrefix(dir, ice.SRC) { return path.Join("/require", dir) } - if kit.FileExists(path.Join(ice.SRC, dir)) { + if nfs.ExistsFile(ice.Pulse, path.Join(ice.SRC, dir)) { return path.Join("/require/src/", dir) } return dir diff --git a/base/nfs/dir.go b/base/nfs/dir.go index aaf07f0e..7b7964ca 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -173,19 +173,13 @@ const DIR = "dir" func init() { Index.MergeCommands(ice.Commands{ - DIR: {Name: "dir path field auto upload what", Help: "目录", Actions: ice.Actions{ + DIR: {Name: "dir path field auto upload", Help: "目录", Actions: ice.Actions{ mdb.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.cache", "upload_watch", m.Option(PATH)) }}, TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(TRASH, mdb.CREATE, m.Option(PATH)) }}, - "what": {Name: "trash", Help: "what", Hand: func(m *ice.Message, arg ...string) { - m.Option(DIR_ROOT, "usr/volcanos/plugin/local/code/inner/") - m.Option(DIR_DEEP, "true") - m.Cmdy(DIR, PWD) - m.Sort("path") - }}, }, Hand: func(m *ice.Message, arg ...string) { if m.Option(DIR_ROOT) != "" { m.Logs(mdb.SELECT, DIR_ROOT, m.Option(DIR_ROOT)) diff --git a/base/nfs/tar.go b/base/nfs/tar.go index 114e85dc..252f0f79 100644 --- a/base/nfs/tar.go +++ b/base/nfs/tar.go @@ -37,7 +37,7 @@ func init() { m.Cmdy("cli.system", "tar", "zcvf", arg) return - file, err := os.Create(arg[0]) + file, _, err := CreateFile(m, arg[0]) m.Assert(err) defer file.Close() @@ -67,7 +67,7 @@ func init() { return } - file, err := os.Open(p) + file, err := OpenFile(m, p) if m.Warn(err) { return } diff --git a/base/web/_story.go b/base/web/_story.go index 7b75cd79..37be85ca 100644 --- a/base/web/_story.go +++ b/base/web/_story.go @@ -1,7 +1,6 @@ package web import ( - "os" "time" ice "shylinux.com/x/icebergs" @@ -127,7 +126,7 @@ func _story_write(m *ice.Message, scene, name, text string, arg ...string) { func _story_catch(m *ice.Message, scene, name string, arg ...string) { if last := m.Richs(STORY, HEAD, name, nil); last != nil { if t, e := time.ParseInLocation(ice.MOD_TIME, kit.Format(last[mdb.TIME]), time.Local); e == nil { - if s, e := os.Stat(name); e == nil && s.ModTime().Before(t) { + if s, e := nfs.StatFile(m, name); e == nil && s.ModTime().Before(t) { m.Push(name, last, []string{mdb.TIME, mdb.COUNT, mdb.KEY}) m.Logs("info", "file", "exists") m.Echo("%s", last[LIST]) diff --git a/base/web/dream.go b/base/web/dream.go index 1667db22..fe540f2c 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -49,14 +49,14 @@ func _dream_list(m *ice.Message) *ice.Message { func _dream_show(m *ice.Message, name string) { if !strings.Contains(name, "-") || !strings.HasPrefix(name, "20") { - name = m.Time("20060102-") + kit.ReplaceAll(name, "-", "_") + name = m.Time("20060102-") + name } defer m.ProcessOpen(MergePod(m, m.Option(mdb.NAME, name))) defer m.Echo(MergePod(m, m.Option(mdb.NAME, name))) // defer m.PushRefresh() p := path.Join(ice.USR_LOCAL_WORK, name) - if pid := m.Cmdx(nfs.CAT, path.Join(p, ice.Info.PidPath)); pid != "" && kit.FileExists("/proc/"+pid) { + if pid := m.Cmdx(nfs.CAT, path.Join(p, ice.Info.PidPath)); pid != "" && nfs.ExistsFile(m, "/proc/"+pid) { m.Info("already exists %v", pid) return // 已经启动 } else if m.Cmd(SPACE, name).Length() > 0 { @@ -117,18 +117,25 @@ const DREAM = "dream" func init() { Index.MergeCommands(ice.Commands{ - DREAM: {Name: "dream name path auto start", Help: "梦想家", Actions: ice.MergeActions(ice.Actions{ + DREAM: {Name: "dream name path auto create", Help: "梦想家", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Config(nfs.SCRIPT, _dream_script) }}, mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { switch arg[0] { case nfs.REPOS: + m.Cmd("web.code.git.server", func(value ice.Maps) { + m.Push(nfs.PATH, MergeLink(m, path.Join("/x/", value[nfs.PATH]+".git"))) + }) + m.Sort(nfs.PATH) default: _dream_list(m).Cut("name,status,time") } }}, - cli.START: {Name: "start name=hi repos", Help: "启动", Hand: func(m *ice.Message, arg ...string) { + mdb.CREATE: {Name: "create name=hi repos", Help: "创建", Hand: func(m *ice.Message, arg ...string) { _dream_show(m, m.Option(mdb.NAME, kit.Select(path.Base(m.Option(nfs.REPOS)), m.Option(mdb.NAME)))) }}, + cli.START: {Name: "start", Help: "启动", Hand: func(m *ice.Message, arg ...string) { + _dream_show(m, m.Option(mdb.NAME)) + }}, cli.OPEN: {Name: "open", Help: "打开", Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen(MergePod(m, m.Option(mdb.NAME), "", "")) }}, @@ -141,7 +148,7 @@ func init() { cli.STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) { m.Cmd(SPACE, mdb.MODIFY, m.OptionSimple(mdb.NAME), mdb.STATUS, cli.STOP) m.Cmd(SPACE, m.Option(mdb.NAME), ice.EXIT) - m.ProcessRefresh30ms() + m.ProcessRefresh3s() }}, DREAM_STOP: {Name: "dream.stop type name", Help: "停止", Hand: func(m *ice.Message, arg ...string) { if m.CmdAppend(SPACE, m.Option(mdb.NAME), mdb.STATUS) == cli.STOP { diff --git a/base/web/spide.go b/base/web/spide.go index e2808de7..9b4b527c 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -8,7 +8,6 @@ import ( "mime/multipart" "net/http" "net/url" - "os" "path" "strings" "time" @@ -141,7 +140,7 @@ func _spide_body(m *ice.Message, method string, arg ...string) (io.Reader, ice.M head[ContentType] = ContentJSON case SPIDE_FILE: - if f, e := os.Open(arg[1]); m.Assert(e) { + if f, e := nfs.OpenFile(m, arg[1]); m.Assert(e) { defer f.Close() body, arg = f, arg[2:] } diff --git a/conf.go b/conf.go index 3e7d2d48..b2c0fd2d 100644 --- a/conf.go +++ b/conf.go @@ -93,6 +93,7 @@ const ( // DIR PAGE = "page" PANEL = "panel" PLUGIN = "plugin" + STORY = "story" FAVICON = "favicon.ico" PROTO_JS = "proto.js" diff --git a/core/chat/cmd.go b/core/chat/cmd.go index c7d33777..a0c2d31b 100644 --- a/core/chat/cmd.go +++ b/core/chat/cmd.go @@ -38,7 +38,7 @@ func _cmd_file(m *ice.Message, arg ...string) bool { web.RenderCmd(m, "can.parse", m.Cmdx(nfs.CAT, p)) default: - if p = strings.TrimPrefix(p, ice.SRC+ice.PS); kit.FileExists(path.Join(ice.SRC, p)) { + if p = strings.TrimPrefix(p, ice.SRC+ice.PS); nfs.ExistsFile(m, path.Join(ice.SRC, p)) { if msg := m.Cmd(mdb.RENDER, kit.Ext(p)); msg.Length() > 0 { m.Cmdy(mdb.RENDER, kit.Ext(p), p, ice.SRC+ice.PS).RenderResult() break diff --git a/core/chat/topic.go b/core/chat/topic.go index ee41d93a..e89a86f9 100644 --- a/core/chat/topic.go +++ b/core/chat/topic.go @@ -131,7 +131,7 @@ body.{{.Option "topic"}} fieldset.panel.Header>div.output div:hover { background }) m.PushAction("choose", "form", mdb.REMOVE) } else { - if p := "src/website/topic/" + arg[0]; kit.FileExists(p) { + if p := "src/website/topic/" + arg[0]; nfs.ExistsFile(m, p) { m.Cmdy(nfs.CAT, p) } else { m.Tables(func(value ice.Maps) { @@ -141,7 +141,7 @@ body.{{.Option "topic"}} fieldset.panel.Header>div.output div:hover { background } }}, "/topic/": {Name: "/topic/", Help: "主题", Hand: func(m *ice.Message, arg ...string) { - if p := "src/website/topic/" + arg[0]; kit.FileExists(p) { + if p := "src/website/topic/" + arg[0]; nfs.ExistsFile(m, p) { m.RenderDownload(p) return } diff --git a/core/code/binpack.go b/core/code/binpack.go index b38acb3a..5ca0a6b3 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -62,6 +62,7 @@ func _binpack_ctx(m *ice.Message, w io.Writer) { _binpack_dir(m, w, ice.SRC) } func _binpack_all(m *ice.Message) { + nfs.OptionFiles(m, nfs.DiskFile) if w, p, e := nfs.CreateFile(m, ice.SRC_BINPACK_GO); m.Assert(e) { defer w.Close() defer m.Echo(p) @@ -79,6 +80,7 @@ func init() { defer fmt.Fprintln(w, `}`) defer fmt.Fprintln(w, ` + nfs.PackFile.RemoveAll(ice.SRC) for k, v := range pack { if b, e := base64.StdEncoding.DecodeString(v); e == nil { nfs.PackFile.WriteFile(k, b) diff --git a/core/code/c.go b/core/code/c.go index 19c99e82..d12f4b2a 100644 --- a/core/code/c.go +++ b/core/code/c.go @@ -12,7 +12,7 @@ import ( ) func _c_tags(m *ice.Message, key string) { - if !kit.FileExists(path.Join(m.Option(cli.CMD_DIR), TAGS)) { + if !nfs.ExistsFile(m, path.Join(m.Option(cli.CMD_DIR), TAGS)) { m.Cmd(cli.SYSTEM, "ctags", "-R", "-f", TAGS, nfs.PWD) } _go_tags(m, key) diff --git a/core/code/go.go b/core/code/go.go index 7d24502b..abff02db 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -17,7 +17,7 @@ import ( ) func _go_tags(m *ice.Message, key string) { - if s, e := os.Stat(path.Join(m.Option(cli.CMD_DIR), TAGS)); os.IsNotExist(e) || s.ModTime().Before(time.Now().Add(kit.Duration("-72h"))) { + if s, e := nfs.StatFile(m, path.Join(m.Option(cli.CMD_DIR), TAGS)); os.IsNotExist(e) || s.ModTime().Before(time.Now().Add(kit.Duration("-72h"))) { m.Cmd(cli.SYSTEM, "gotags", "-R", "-f", TAGS, nfs.PWD) } @@ -36,7 +36,7 @@ func _go_tags(m *ice.Message, key string) { text := strings.TrimSuffix(strings.TrimPrefix(ls[0], "/^"), "$/") line := kit.Int(text) - f, e := os.Open(path.Join(m.Option(cli.CMD_DIR), file)) + f, e := nfs.OpenFile(m, path.Join(m.Option(cli.CMD_DIR), file)) m.Assert(e) defer f.Close() diff --git a/core/code/install.go b/core/code/install.go index 9f9ae2f0..2bbfcf6c 100644 --- a/core/code/install.go +++ b/core/code/install.go @@ -32,8 +32,8 @@ func _install_download(m *ice.Message) { file := path.Join(kit.Select(ice.USR_INSTALL, m.Option(nfs.PATH)), name) if nfs.ExistsFile(m, file) { - web.ToastSuccess(m) m.Cmdy(nfs.DIR, file) + web.ToastSuccess(m) return // 文件存在 } diff --git a/core/code/publish.go b/core/code/publish.go index 773fd7c8..5e6f4e01 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -24,7 +24,7 @@ func _publish_file(m *ice.Message, file string, arg ...string) string { } else if s, e := nfs.StatFile(m, file); m.Assert(e) && s.IsDir() { file = m.Cmdx(nfs.TAR, mdb.IMPORT, path.Base(file), file) - defer func() { os.Remove(file) }() + defer func() { nfs.Remove(m, file) }() } // 发布文件 @@ -43,7 +43,7 @@ func _publish_bin_list(m *ice.Message, dir string) { p := m.Option(cli.CMD_DIR, dir) for _, ls := range strings.Split(strings.TrimSpace(m.Cmd(cli.SYSTEM, "bash", "-c", "ls |xargs file |grep executable").Append(cli.CMD_OUT)), ice.NL) { if file := strings.TrimSpace(strings.Split(ls, ":")[0]); file != "" { - if s, e := os.Stat(path.Join(p, file)); e == nil { + if s, e := nfs.StatFile(m, path.Join(p, file)); e == nil { m.Push(mdb.TIME, s.ModTime()) m.Push(nfs.SIZE, kit.FmtSize(s.Size())) m.Push(nfs.FILE, file) diff --git a/core/code/py.go b/core/code/py.go index 5efdf7d6..8333127f 100644 --- a/core/code/py.go +++ b/core/code/py.go @@ -31,6 +31,12 @@ func init() { Index.Merge(&ice.Context{Commands: ice.Commands{ PY: {Name: "py path auto", Help: "脚本", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + m.Go(func() { + m.Sleep300ms() // after runtime init + cli.IsAlpine(m, "python", "python2") + cli.IsAlpine(m, "python2") + cli.IsAlpine(m, "python3") + }) m.Cmd(mdb.ENGINE, mdb.CREATE, PY, m.PrefixKey()) m.Cmd(mdb.RENDER, mdb.CREATE, PY, m.PrefixKey()) }}, diff --git a/core/code/vimer.go b/core/code/vimer.go index ce2b2643..1c0443d2 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -26,7 +26,7 @@ chapter "hi" print "hello world" `, nfs.JS, ` -Volcanos("onimport", {help: "导入数据", _init: function(can, msg) { +Volcanos(chat.ONIMPORT, {help: "导入数据", _init: function(can, msg) { msg.Echo("hello world") msg.Dump(can) }}) diff --git a/core/code/xterm.go b/core/code/xterm.go index e297dbb6..f301708d 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -29,7 +29,9 @@ func _xterm_get(m *ice.Message, h string, must bool) *os.File { return nil } - cmd := exec.Command(cli.SystemFind(m, kit.Select("sh", m.Option(mdb.TYPE)))) + ls := kit.Split(kit.Select("sh", m.Option(mdb.TYPE))) + m.Debug("what %v", kit.Format(ls)) + cmd := exec.Command(cli.SystemFind(m, ls[0]), ls[1:]...) cmd.Env = append(os.Environ(), "TERM=xterm") m.Option(mdb.HASH, h) diff --git a/core/wiki/field.go b/core/wiki/field.go index d62050eb..f55ee944 100644 --- a/core/wiki/field.go +++ b/core/wiki/field.go @@ -66,7 +66,7 @@ func _field_show(m *ice.Message, name, text string, arg ...string) { meta[arg[i]] = arg[i+1] case SPARK: - if arg[i+1][0] == '@' && kit.FileExists(arg[i+1][1:]) { + if arg[i+1][0] == '@' && nfs.ExistsFile(m, arg[i+1][1:]) { msg.Cmdy(nfs.CAT, arg[i+1][1:]) } else { msg.Echo(strings.TrimSpace(arg[i+1])) diff --git a/core/wiki/word.go b/core/wiki/word.go index 7221e6aa..035bc7bc 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -74,11 +74,12 @@ func init() { }}, mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.DIR, "src/", kit.Dict(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, ".*\\.shy"), nfs.DIR_CLI_FIELDS) - m.Cmdy(nfs.DIR, "src/help/", kit.Dict(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, ".*\\.shy"), nfs.DIR_CLI_FIELDS) + for _, p := range []string{"src/", "src/help/", "usr/icebergs/"} { + m.Cmdy(nfs.DIR, p, kit.Dict(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, ".*\\.shy"), nfs.DIR_CLI_FIELDS) + } }}, - "story": {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(arg[0], ctx.ACTION, ice.RUN, arg[2:]) + ice.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(arg[0], ice.RUN, arg[2:]) }}, ice.PLAY: {Name: "play", Help: "演示"}, }, ctx.CmdAction(), mdb.HashAction()), Hand: func(m *ice.Message, arg ...string) { @@ -87,7 +88,7 @@ func init() { arg = append(arg, "src/") } if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, m.CommandKey(), arg...) { - if !kit.FileExists(arg[0]) && kit.FileExists(path.Join("src", arg[0])) { + if !nfs.ExistsFile(m, arg[0]) && nfs.ExistsFile(m, path.Join("src", arg[0])) { arg[0] = path.Join("src/", arg[0]) } ctx.DisplayLocal(m, "") diff --git a/go.mod b/go.mod index adc66cfb..596d17cd 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.11 require ( shylinux.com/x/creackpty v0.0.1 shylinux.com/x/go-qrcode v0.0.1 + shylinux.com/x/ice v1.0.7 shylinux.com/x/toolkits v0.6.6 shylinux.com/x/websocket v0.0.1 ) diff --git a/go.sum b/go.sum index 8569e2e1..185924f9 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,10 @@ shylinux.com/x/creackpty v0.0.1 h1:o+qDE39jFsHLZB9BRAm0EI6qScjw5PuvdkROqhTcupM= shylinux.com/x/creackpty v0.0.1/go.mod h1:d7DnPv3oGc23WlzrN8hW7p88wNLPAO/XG4ICVEq96i0= shylinux.com/x/go-qrcode v0.0.1 h1:/eOGqMj1qtgs9Ymd12zTUa1gcJZs9S92kj2lb0QzKsE= shylinux.com/x/go-qrcode v0.0.1/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po= +shylinux.com/x/ice v1.0.7 h1:prm2IiOJ7nevt9pSmTEXGHq/Vjeo1n+gDfo54G5OPtI= +shylinux.com/x/ice v1.0.7/go.mod h1:9ErxoqjwAzbcOkJAD7+OPuRrQ12/kduO7arHipUCry0= +shylinux.com/x/icebergs v1.3.0/go.mod h1:HhX/7lagVsvO80yYbfpf7FW4ddLOFv8kUwjBr8STRUQ= +shylinux.com/x/toolkits v0.6.5/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA= shylinux.com/x/toolkits v0.6.6 h1:OcuGs4PLj9qynf14o8UE1wndT3+tnum0wpOo0KFq/tM= shylinux.com/x/toolkits v0.6.6/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA= shylinux.com/x/websocket v0.0.1 h1:OBc21DxqsGlQ2+Pz76xqLyDNo1LV+PUUqfWi+1PZPDE= diff --git a/logs.go b/logs.go index 3f7bb008..27dcd90c 100644 --- a/logs.go +++ b/logs.go @@ -195,7 +195,7 @@ func (m *Message) FormatStack(s, n int) string { name := kit.Slice(kit.Split(frame.Function, PS, PS), -1)[0] switch ls := kit.Split(name, PT, PT); kit.Select("", ls, 0) { - // case "reflect", "runtime", "http", "task", "icebergs": + case "reflect", "runtime", "http", "task", "icebergs": default: list = append(list, kit.Format("%s:%d\t%s", file, frame.Line, name)) } diff --git a/meta.go b/meta.go index 152c3c00..5eb8aa43 100644 --- a/meta.go +++ b/meta.go @@ -159,7 +159,11 @@ func (m *Message) Push(key string, value Any, arg ...Any) *Message { // 追加数据 switch v := kit.Format(v); key { case FIELDS_DETAIL: - m.Add(MSG_APPEND, KEY, k) + switch k { + case "_target": + continue + } + m.Add(MSG_APPEND, KEY, strings.TrimPrefix(k, "extra.")) m.Add(MSG_APPEND, VALUE, v) default: m.Add(MSG_APPEND, k, v) diff --git a/misc/alpha/alpha.go b/misc/alpha/alpha.go index 71ee2a46..2b43c3f2 100644 --- a/misc/alpha/alpha.go +++ b/misc/alpha/alpha.go @@ -1,7 +1,6 @@ package alpha import ( - "os" "path" "strings" @@ -34,7 +33,7 @@ func (a alpha) Load(m *ice.Message, arg ...string) { name := m.Option(mdb.NAME) // 清空数据 meta := m.Confm(m.PrefixKey(), mdb.META) - m.Assert(os.RemoveAll(path.Join(kit.Format(meta[mdb.STORE]), name))) + m.Assert(nfs.RemoveAll(m.Message, path.Join(kit.Format(meta[mdb.STORE]), name))) m.Conf(m.PrefixKey(), name, "") // 缓存配置 diff --git a/misc/bash/trash.go b/misc/bash/trash.go index 805f07ed..c0d38c8a 100644 --- a/misc/bash/trash.go +++ b/misc/bash/trash.go @@ -1,8 +1,6 @@ package bash import ( - "os" - ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/cli" @@ -39,7 +37,7 @@ func init() { }}, mdb.PRUNES: {Name: "prunes before@date", Help: "清理", Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunes(m, func(value ice.Maps) bool { - os.RemoveAll(value[TO]) + nfs.RemoveAll(m, value[TO]) return true }) }}, diff --git a/misc/coder/coder.shy b/misc/coder/coder.shy index 7932b0c9..baacc58d 100644 --- a/misc/coder/coder.shy +++ b/misc/coder/coder.shy @@ -1,15 +1,18 @@ -chapter "codeserver" +section "code-server" refer ` -https://coder.com/ -https://github.com/coder/code-server/ -https://github.com/microsoft/vscode -https://code.visualstudio.com/ -https://geek-docs.com/vscode/vscode-tutorials/what-is-vscode.html +官网 https://coder.com/ +源码 https://github.com/coder/code-server/ ` spark shell ` wget https://github.com/coder/code-server/releases/download/v4.4.0/code-server-4.4.0-linux-amd64.tar.gz -tar xvf code-server-4.4.0-linux-amd64.tar.gz -cd code-server-4.4.0-linux-amd64 +tar xvf code-server-4.4.0-linux-amd64.tar.gz && cd code-server-4.4.0-linux-amd64 ./bin/code-server ` +field web.code.coder.server + +refer ` +官网 https://code.visualstudio.com/ +源码 https://github.com/microsoft/vscode +入门 https://geek-docs.com/vscode/vscode-tutorials/what-is-vscode.html +` diff --git a/misc/git/repos.go b/misc/git/repos.go index 8fea6b99..f53d39b0 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -1,7 +1,6 @@ package git import ( - "os" "path" "strings" @@ -23,7 +22,7 @@ func _repos_path(name string) string { return kit.Select(path.Join(ice.USR, name)+ice.PS, nfs.PWD, name == path.Base(kit.Pwd())) } func _repos_insert(m *ice.Message, name string, dir string) { - if s, e := os.Stat(m.Option(cli.CMD_DIR, path.Join(dir, ".git"))); e == nil && s.IsDir() { + if s, e := nfs.StatFile(m, m.Option(cli.CMD_DIR, path.Join(dir, ".git"))); e == nil && s.IsDir() { ls := strings.SplitN(strings.Trim(m.Cmdx(cli.SYSTEM, GIT, "log", "-n1", `--pretty=format:"%ad %s"`, "--date=iso"), `"`), ice.SP, 4) mdb.Rich(m, REPOS, nil, kit.Data(mdb.NAME, name, nfs.PATH, dir, COMMIT, kit.Select("", ls, 3), mdb.TIME, strings.Join(ls[:2], ice.SP), @@ -71,12 +70,12 @@ func init() { // } _repos_insert(m, m.Option(mdb.NAME), m.Option(nfs.PATH)) - if s, e := os.Stat(path.Join(m.Option(nfs.PATH), ".git")); e == nil && s.IsDir() { + if s, e := nfs.StatFile(m, path.Join(m.Option(nfs.PATH), ".git")); e == nil && s.IsDir() { return } // 下载仓库 - if s, e := os.Stat(m.Option(nfs.PATH)); e == nil && s.IsDir() { + if s, e := nfs.StatFile(m, m.Option(nfs.PATH)); e == nil && s.IsDir() { m.Option(cli.CMD_DIR, m.Option(nfs.PATH)) m.Cmd(cli.SYSTEM, GIT, INIT) m.Cmd(cli.SYSTEM, GIT, REMOTE, ADD, ORIGIN, m.Option(REPOS)) diff --git a/misc/git/server.go b/misc/git/server.go index 159224b2..d62bcedc 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -155,7 +155,7 @@ func init() { web.RenderStatus(m.W, 401, err.Error()) return // 没有权限 } - if !kit.FileExists(path.Join(repos)) { + if !nfs.ExistsFile(m, path.Join(repos)) { m.Cmd(cli.SYSTEM, GIT, INIT, "--bare", repos) // 创建仓库 m.Logs(mdb.CREATE, REPOS, repos) } @@ -164,7 +164,7 @@ func init() { if kit.Select("", arg, 1) == "info" && m.Cmd(web.DREAM, arg[0]).Length() > 0 { m.Cmd(web.SPACE, arg[0], "web.code.git.status", "submit", web.MergeURL2(m, "/x/")+arg[0]) } - if !kit.FileExists(path.Join(repos)) { + if !nfs.ExistsFile(m, path.Join(repos)) { web.RenderStatus(m.W, 404, kit.Format("not found: %s", arg[0])) return } diff --git a/misc/git/total.go b/misc/git/total.go index cd20200c..f35d8bf7 100644 --- a/misc/git/total.go +++ b/misc/git/total.go @@ -1,7 +1,6 @@ package git import ( - "os" "path" "strings" "sync" @@ -88,10 +87,10 @@ func init() { }}, "_sum": {Name: "_sum [path] [total] [count|date] args...", Help: "统计量", Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 { - if s, e := os.Stat(path.Join(arg[0], ".git")); e == nil && s.IsDir() { + if s, e := nfs.StatFile(m, path.Join(arg[0], ".git")); e == nil && s.IsDir() { m.Option(cli.CMD_DIR, arg[0]) arg = arg[1:] - } else if s, e := os.Stat(path.Join(arg[0], "refs")); e == nil && s.IsDir() { + } else if s, e := nfs.StatFile(m, path.Join(arg[0], "refs")); e == nil && s.IsDir() { m.Option(cli.CMD_DIR, arg[0]) arg = arg[1:] } diff --git a/misc/input/input.go b/misc/input/input.go index 5b83ad86..2716af50 100644 --- a/misc/input/input.go +++ b/misc/input/input.go @@ -5,7 +5,6 @@ import ( "bytes" "encoding/csv" "fmt" - "os" "path" "strings" @@ -34,12 +33,12 @@ type input struct { } func (i input) Load(m *ice.Message, arg ...string) { - if f, e := os.Open(m.Option(nfs.FILE)); m.Assert(e) { + if f, e := nfs.OpenFile(m.Message, m.Option(nfs.FILE)); m.Assert(e) { defer f.Close() // 清空数据 lib := kit.Select(path.Base(m.Option(nfs.FILE)), m.Option(mdb.ZONE)) - m.Assert(os.RemoveAll(path.Join(m.Config(mdb.STORE), lib))) + m.Assert(nfs.RemoveAll(m.Message, path.Join(m.Config(mdb.STORE), lib))) m.Cmd(mdb.DELETE, m.PrefixKey(), "", mdb.HASH, mdb.ZONE, lib) prefix := kit.Keys(mdb.HASH, mdb.Rich(m.Message, m.PrefixKey(), "", kit.Data( mdb.STORE, path.Join(m.Config(mdb.STORE), lib), diff --git a/misc/java/server.go b/misc/java/compile.go similarity index 53% rename from misc/java/server.go rename to misc/java/compile.go index 6482a27c..1eb7d67b 100644 --- a/misc/java/server.go +++ b/misc/java/compile.go @@ -10,27 +10,40 @@ import ( ) const ( + MVN = "mvn" JAVA = "java" JAVAC = "javac" ) -type server struct { +type compile struct { ice.Code regexp string `data:".*.java"` linux string `data:"https://mirrors.tencent.com/repository/generic/konajdk/8/0/10/linux-x86_64/b1/TencentKona8.0.10.b1_jdk_linux-x86_64_8u332.tar.gz"` - list string `name:"list path auto listScript order install" help:"编译执行"` + list string `name:"list path auto listScript order install" help:"编译器"` } -func (s server) Order(m *ice.Message) { +func (s compile) Init(m *ice.Message) { + m.Go(func() { + m.Sleep300ms() // after runtime init + 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") + }) +} +func (s compile) Order(m *ice.Message) { s.Code.Order(m, "", ice.BIN) } -func (s server) List(m *ice.Message, arg ...string) { +func (s compile) List(m *ice.Message, arg ...string) { s.Code.Source(m, "", arg...) } -func (s server) RunScript(m *ice.Message) { +func (s compile) RunScript(m *ice.Message) { if s.Code.System(m, nfs.PWD, JAVAC, "-d", ice.BIN, m.Option(nfs.PATH)); cli.IsSuccess(m.Message) { s.Code.System(m, nfs.PWD, JAVA, "-cp", kit.Path(ice.BIN), strings.TrimPrefix(strings.TrimSuffix(m.Option(nfs.PATH), ".java"), "src/")) } } -func init() { ice.CodeCtxCmd(server{}) } +func init() { ice.CodeCtxCmd(compile{}) } diff --git a/misc/java/compile.shy b/misc/java/compile.shy new file mode 100644 index 00000000..9f267ef7 --- /dev/null +++ b/misc/java/compile.shy @@ -0,0 +1,9 @@ +section "java" +refer ` +官网 https://www.java.com/ +文档 https://docs.oracle.com/javase/tutorial/ +源码 https://github.com/openjdk/jdk +开源 https://openjdk.org/ +` +field web.code.java.compile + diff --git a/misc/java/spring.shy b/misc/java/spring.shy index 9a7fe7c8..cc67a1ec 100644 --- a/misc/java/spring.shy +++ b/misc/java/spring.shy @@ -1,9 +1,10 @@ section "spring" refer ` 官网 https://spring.io/projects/spring-boot +源码 https://github.com/spring-projects/spring-boot 入门 https://spring.io/quickstart 向导 https://start.spring.io/ 参数 https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html 接口 https://spring.io/guides/gs/rest-service/ 数据 https://spring.io/guides/gs/accessing-data-mysql/ -` \ No newline at end of file +` diff --git a/misc/node/compile.go b/misc/node/compile.go new file mode 100644 index 00000000..e40b6fcd --- /dev/null +++ b/misc/node/compile.go @@ -0,0 +1,37 @@ +package node + +import ( + "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/cli" +) + +const ( + NPM = "npm" + NODE = "node" +) + +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"` + list string `name:"list path auto xterm listScript order install" help:"编译器"` +} + +func (s compile) Init(m *ice.Message) { + m.Go(func() { + m.Sleep300ms() // after runtime init + cli.IsAlpine(m.Message, NPM) + cli.IsAlpine(m.Message, NODE, "nodejs") + }) +} +func (s compile) Order(m *ice.Message) { + s.Code.Order(m, "", ice.BIN) +} +func (s compile) Xterm(m *ice.Message, arg ...string) { + s.Code.Xterm(m, NODE, arg...) +} +func (s compile) List(m *ice.Message, arg ...string) { + s.Code.Source(m, "", arg...) +} + +func init() { ice.CodeCtxCmd(compile{}) } diff --git a/misc/node/compile.shy b/misc/node/compile.shy new file mode 100644 index 00000000..40f38df7 --- /dev/null +++ b/misc/node/compile.shy @@ -0,0 +1,8 @@ +section "node" +refer ` +官网 https://nodejs.org/ +文档 https://nodejs.org/docs/latest-v6.x/api/ +源码 https://github.com/nodejs/node +` +field web.code.node.compile + diff --git a/misc/node/server.go b/misc/node/server.go deleted file mode 100644 index e466787c..00000000 --- a/misc/node/server.go +++ /dev/null @@ -1,22 +0,0 @@ -package node - -import ( - "shylinux.com/x/ice" -) - -type server struct { - ice.Code - command string `data:"node"` - regexp string `data:".*.js"` - linux string `data:"https://mirrors.tencent.com/nodejs-release/v16.15.1/node-v16.15.1-linux-x64.tar.xz"` - list string `name:"list path auto listScript order install" help:"编译执行"` -} - -func (s server) Order(m *ice.Message) { - s.Code.Order(m, "", ice.BIN) -} -func (s server) List(m *ice.Message, arg ...string) { - s.Code.Source(m, "", arg...) -} - -func init() { ice.CodeCtxCmd(server{}) } diff --git a/misc/node/vue.shy b/misc/node/vue.shy index 1b5a816c..5ab9ac30 100644 --- a/misc/node/vue.shy +++ b/misc/node/vue.shy @@ -1,5 +1,6 @@ section "vue" refer ` 官网 https://vuejs.org/ +源码 https://github.com/vuejs/vue 入门 https://vuejs.org/guide/quick-start.html -` \ No newline at end of file +` diff --git a/misc/ssh/connect.go b/misc/ssh/connect.go index 8c198790..930a40df 100644 --- a/misc/ssh/connect.go +++ b/misc/ssh/connect.go @@ -45,17 +45,17 @@ func _ssh_open(m *ice.Message, arg ...string) { } func _ssh_dial(m *ice.Message, cb func(net.Conn), arg ...string) { p := path.Join(kit.Env(cli.HOME), ".ssh/", fmt.Sprintf("%s@%s:%s", m.Option(aaa.USERNAME), m.Option(tcp.HOST), m.Option(tcp.PORT))) - if kit.FileExists(p) { + if nfs.FileExists(m, p) { if c, e := net.Dial("unix", p); e == nil { cb(c) // 会话连接 return } - os.Remove(p) + nfs.Remove(m, p) } _ssh_conn(m, func(client *ssh.Client) { if l, e := net.Listen("unix", p); m.Assert(e) { - defer func() { os.Remove(p) }() + defer func() { nfs.Remove(m, p) }() defer l.Close() m.Go(func() { diff --git a/misc/tmux/session.go b/misc/tmux/session.go index f526042c..12291d68 100644 --- a/misc/tmux/session.go +++ b/misc/tmux/session.go @@ -79,18 +79,14 @@ func init() { } else { // 创建会话 m.Option(cli.CMD_DIR, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME))) - ls := kit.Split(m.Option(mdb.NAME), "-_") + ls := kit.Split(strings.TrimSuffix(m.Option(mdb.NAME), "-story"), "-") name := ls[len(ls)-1] m.Cmdy(cli.SYSTEM, TMUX, "new-session", "-ds", m.Option(mdb.NAME), "-n", name) name = _tmux_key(m.Option(mdb.NAME), ls[len(ls)-1]) - m.Cmdy(cli.SYSTEM, TMUX, "split-window", "-t", kit.Keys(name, "1"), "-p", "20") - m.Cmdy(cli.SYSTEM, TMUX, "split-window", "-t", kit.Keys(name, "2"), "-h") - - m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "3"), "ish_miss_log", "Enter") - // m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "2"), "ish_miss_space", "Enter") - m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "2"), "ish_miss_space") + m.Cmd(cli.SYSTEM, TMUX, "split-window", "-t", kit.Keys(name, "1"), "-p", "40") + m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "2"), "ish_miss_log", "Enter") m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "1"), "vi etc/miss.sh", "Enter") m.Cmdy(cli.SYSTEM, TMUX, "link-window", "-s", name, "-t", "miss:")