diff --git a/base.go b/base.go index da1dddd4..b54bb3d1 100644 --- a/base.go +++ b/base.go @@ -3,6 +3,7 @@ package ice import ( "github.com/shylinux/toolkits" + "fmt" "os" "strings" "sync" @@ -36,7 +37,7 @@ func (f *Frame) Start(m *Message, arg ...string) bool { m.Cap(CTX_STREAM, strings.Split(m.Time(), " ")[1]) m.root.Cost("start") - m.Cmd("init", arg) + m.Cmdy("init", arg) return true } func (f *Frame) Close(m *Message, arg ...string) bool { @@ -86,19 +87,19 @@ var Index = &Context{Name: "ice", Help: "冰山模块", m.root.Cost("_init") m.target.root.wg = &sync.WaitGroup{} - for _, k := range []string{"log", "gdb", "ssh"} { + for _, k := range kit.Split(os.Getenv("ctx_mod")) { m.Start(k) } - m.Cmd("ssh.scan", "init.shy", "启动配置", "etc/init.shy") - m.Cmd(arg) + m.Cmd(SSH_SOURCE, "etc/init.shy", "init.shy", "启动配置") + m.Cmdy(arg) }}, "help": {Name: "help", Help: "帮助", Hand: func(m *Message, c *Context, cmd string, arg ...string) { m.Echo(strings.Join(kit.Simple(m.Confv("help", "index")), "\n")) }}, "exit": {Name: "exit", Help: "结束", Hand: func(m *Message, c *Context, cmd string, arg ...string) { m.root.target.server.(*Frame).code = kit.Int(kit.Select("0", arg, 0)) - m.Cmd("ssh.scan", "exit.shy", "退出配置", "etc/exit.shy") + m.Cmd(SSH_SOURCE, "etc/exit.shy", "exit.shy", "退出配置") m.root.Cmd(ICE_EXIT) m.root.Cost("_exit") @@ -134,18 +135,23 @@ func Run(arg ...string) string { arg = os.Args[1:] } if len(arg) == 0 { - arg = append(arg, WEB_SERVE) + // arg = append(arg, WEB_SERVE) + arg = append(arg, WEB_SPACE, "connect", "self") } frame := &Frame{} Index.server = frame Pulse.Option("begin_time", Pulse.Time()) - if frame.Begin(Pulse.Spawns(), arg...).Start(Pulse.Spawns(), arg...) { + if frame.Begin(Pulse.Spawns(), arg...).Start(Pulse, arg...) { frame.Close(Pulse.Spawns(), arg...) } - time.Sleep(time.Second) + if Pulse.Result() == "" { + Pulse.Table() + } + fmt.Printf(Pulse.Result()) + // time.Sleep(time.Second) os.Exit(frame.code) - return Pulse.Result() + return "" } diff --git a/base/cli/cli.go b/base/cli/cli.go index 3800c793..25ded52d 100644 --- a/base/cli/cli.go +++ b/base/cli/cli.go @@ -42,7 +42,6 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块", } if user, e := user.Current(); e == nil { m.Conf(ice.CLI_RUNTIME, "boot.username", path.Base(kit.Select(user.Name, os.Getenv("USER")))) - m.Cmd(ice.AAA_ROLE, "root", m.Conf(ice.CLI_RUNTIME, "boot.username")) } if name, e := os.Getwd(); e == nil { @@ -77,6 +76,9 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块", cmd.Dir = m.Option("cmd_dir") if len(cmd.Dir) > 0 { m.Info("dir: %s", cmd.Dir) + if _, e := os.Stat(cmd.Dir); e != nil && os.IsNotExist(e) { + os.MkdirAll(cmd.Dir, 0777) + } } // 环境变量 diff --git a/base/ctx/ctx.go b/base/ctx/ctx.go index 85b0fdf0..0728b445 100644 --- a/base/ctx/ctx.go +++ b/base/ctx/ctx.go @@ -137,6 +137,9 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块", switch arg[0] { case "save": // 保存配置 + if m.Cap(ice.CTX_STATUS) != ice.ICE_START { + break + } arg[1] = path.Join(msg.Conf(ice.CTX_CONFIG, "meta.path"), arg[1]) if f, p, e := kit.Create(arg[1]); m.Assert(e) { data := map[string]interface{}{} diff --git a/base/gdb/gdb.go b/base/gdb/gdb.go index b612a842..23fedb58 100644 --- a/base/gdb/gdb.go +++ b/base/gdb/gdb.go @@ -86,10 +86,11 @@ var Index = &ice.Context{Name: "gdb", Help: "事件模块", }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if os.Getenv("ctx_mod") != "" { + m.Cmd("nfs.save", kit.Select(m.Conf(ice.GDB_SIGNAL, "meta.pid"), + m.Conf(ice.CLI_RUNTIME, "conf.ctx_pid")), m.Conf(ice.CLI_RUNTIME, "host.pid")) + } // 进程标识 - m.Cmd("nfs.save", kit.Select(m.Conf(ice.GDB_SIGNAL, "meta.pid"), - m.Conf(ice.CLI_RUNTIME, "conf.ctx_pid")), m.Conf(ice.CLI_RUNTIME, "host.pid")) - if f, ok := m.Target().Server().(*Frame); ok { // 注册信号 f.s = make(chan os.Signal, ice.ICE_CHAN) diff --git a/base/log/log.go b/base/log/log.go index fa26c268..206b7e22 100644 --- a/base/log/log.go +++ b/base/log/log.go @@ -92,14 +92,16 @@ var Index = &ice.Context{Name: "log", Help: "日志模块", }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Confm("file", nil, func(key string, value map[string]interface{}) { - // 日志文件 - if f, p, e := kit.Create(kit.Format(value["path"])); m.Assert(e) { - m.Cap(ice.CTX_STREAM, path.Base(p)) - m.Log("create", "%s: %s", key, p) - value["file"] = f - } - }) + if os.Getenv("ctx_mod") != "" { + m.Confm("file", nil, func(key string, value map[string]interface{}) { + // 日志文件 + if f, p, e := kit.Create(kit.Format(value["path"])); m.Assert(e) { + m.Cap(ice.CTX_STREAM, path.Base(p)) + m.Log("create", "%s: %s", key, p) + value["file"] = f + } + }) + } }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if f, ok := m.Target().Server().(*Frame); ok { diff --git a/base/ssh/ssh.go b/base/ssh/ssh.go index 71bc0411..b08790c9 100644 --- a/base/ssh/ssh.go +++ b/base/ssh/ssh.go @@ -240,11 +240,11 @@ var Index = &ice.Context{Name: "ssh", Help: "终端模块", f.parse(m, kit.Format(value["line"])) }) }}, - "scan": {Name: "scan name help file", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "source": {Name: "source file", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { buf := bytes.NewBuffer(make([]byte, 0, 4096)) m.Optionv(ice.MSG_STDOUT, buf) - m.Starts(strings.Replace(arg[0], ".", "_", -1), arg[1], arg[2:]...) + m.Starts(strings.Replace(arg[0], ".", "_", -1), arg[0], arg[0:]...) m.Echo(buf.String()) }}, "print": {Name: "print", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/base/web/web.go b/base/web/web.go index dcf635d9..2af07e5c 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -35,6 +35,18 @@ type Frame struct { send map[string]*ice.Message } +func Refresh(msg *ice.Message, n int) string { + return fmt.Sprintf(` + + + + + + 请稍后,系统初始化中... + + `, n) +} + func Redirect(msg *ice.Message, url string, arg ...interface{}) *ice.Message { msg.Push("_output", "redirect") msg.Echo(kit.MergeURL(url, arg...)) @@ -317,15 +329,28 @@ func (web *Frame) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if index && kit.Right(m.Conf(ice.WEB_SERVE, "meta.logheaders")) { + // 请求参数 for k, v := range r.Header { m.Info("%s: %v", k, kit.Format(v)) } m.Info(" ") } - web.ServeMux.ServeHTTP(w, r) + if r.URL.Path == "/" && m.Conf(ice.WEB_SERVE, "meta.init") != "true" { + if _, e := os.Stat(m.Conf(ice.WEB_SERVE, "meta.volcanos.path")); e == nil { + // 初始化成功 + m.Conf(ice.WEB_SERVE, "meta.init", "true") + } else { + // 系统初始化 + w.Write([]byte(Refresh(m, 10))) + m.Event(ice.SYSTEM_INIT) + } + } else { + web.ServeMux.ServeHTTP(w, r) + } if index && kit.Right(m.Conf(ice.WEB_SERVE, "meta.logheaders")) { + // 响应参数 for k, v := range w.Header() { m.Info("%s: %v", k, kit.Format(v)) } @@ -401,13 +426,14 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", "/static/volcanos/": "usr/volcanos/", "/publish/": "usr/publish/", }, - "volcanos", kit.Dict("path", "usr/volcanos", + "volcanos", kit.Dict("path", "usr/volcanos", "branch", "master", "repos", "https://github.com/shylinux/volcanos", - "branch", "master"), + ), "template", map[string]interface{}{"path": "usr/template", "list": []interface{}{ `{{define "raw"}}{{.Result}}{{end}}`, }}, "logheaders", "false", + "init", "false", )}, ice.WEB_SPACE: {Name: "space", Help: "空间站", Value: kit.Data(kit.MDB_SHORT, "name", "redial.a", 3000, "redial.b", 1000, "redial.c", 1000, @@ -448,6 +474,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", if m.Richs(ice.WEB_SPIDE, nil, "shy", nil) == nil { m.Cmd(ice.WEB_SPIDE, "add", "shy", kit.Select("https://shylinux.com:443", m.Conf(ice.CLI_RUNTIME, "conf.ctx_shy"))) } + m.Watch(ice.SYSTEM_INIT, "web.code.git.repos", "volcanos", m.Conf(ice.WEB_SERVE, "meta.volcanos.path"), + m.Conf(ice.WEB_SERVE, "meta.volcanos.repos"), m.Conf(ice.WEB_SERVE, "meta.volcanos.branch")) }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { p := m.Conf(ice.WEB_CACHE, "meta.store") @@ -458,7 +486,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", } }) // m.Conf(ice.WEB_CACHE, "hash", kit.Dict()) - m.Save(ice.WEB_SPIDE, ice.WEB_FAVOR, ice.WEB_CACHE, ice.WEB_STORY, ice.WEB_SHARE) + m.Save(ice.WEB_FAVOR, ice.WEB_CACHE, ice.WEB_STORY, ice.WEB_SHARE, + ice.WEB_SPIDE, ice.WEB_SERVE) m.Done() m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) { @@ -716,8 +745,6 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", default: // 启动服务 m.Target().Start(m, "self") - // 系统初始化 - m.Event(ice.SYSTEM_INIT) } }}, ice.WEB_SPACE: {Name: "space", Help: "空间站", Meta: kit.Dict("exports", []string{"pod", "name"}), List: kit.List( @@ -887,6 +914,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Option("cmd_dir", p) m.Option("cmd_type", "daemon") m.Option("cmd_env", "ctx_log", "boot.log") + m.Option("cmd_env", "PATH", kit.Path(path.Join(p, "bin"))+":"+os.Getenv("PATH")) m.Cmd(m.Confv(ice.WEB_DREAM, "meta.cmd"), "self", arg[0]) time.Sleep(time.Second * 3) m.Event(ice.DREAM_START, arg...) @@ -1272,11 +1300,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", os.Rename(name, kit.Keys(name, "bak")) if msg.Append("file") != "" { p := path.Dir(name) - e := os.MkdirAll(p, 0777) - m.Log("what", "%v", e) + os.MkdirAll(p, 0777) - e = os.Link(msg.Append("file"), name) - m.Log("what", "%v", e) + os.Link(msg.Append("file"), name) m.Log(ice.LOG_EXPORT, "%s: %s", msg.Append("file"), name) } else { if f, p, e := kit.Create(name); m.Assert(e) { diff --git a/conf.go b/conf.go index 01bb4ca5..656b1c1c 100644 --- a/conf.go +++ b/conf.go @@ -109,6 +109,9 @@ const ( // LOG LOG_ERROR = "error" LOG_TRACE = "trace" ) +const ( // SSH + SSH_SOURCE = "source" +) const ( // GDB GDB_SIGNAL = "signal" GDB_TIMER = "timer" @@ -193,6 +196,7 @@ var Alias = map[string]string{ CLI_RUNTIME: "cli.runtime", CLI_SYSTEM: "cli.system", + SSH_SOURCE: "ssh.source", AAA_ROLE: "aaa.role", AAA_USER: "aaa.user", diff --git a/core/chat/chat.go b/core/chat/chat.go index 10b7a3ca..ba3191e1 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -109,7 +109,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", } // 前端框架 - m.Cmd("web.code.git.check", m.Conf(ice.CHAT_RIVER, "meta.fe")) + m.Cmd("web.code.git.repos", m.Conf(ice.CHAT_RIVER, "meta.fe")) m.Cap(ice.CTX_STREAM, m.Conf(ice.CHAT_RIVER, "meta.fe")) m.Cap(ice.CTX_STATUS, "start") }}, diff --git a/core/code/code.go b/core/code/code.go index 4bda19cc..4f01be45 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -8,58 +8,44 @@ import ( "io/ioutil" "os" - "os/exec" "path" "strings" - "time" ) -var Dockfile = ` -FROM {{options . "base"}} - -WORKDIR /home/{{options . "user"}}/context -Env ctx_dev {{options . "host"}} - -RUN wget -q -O - $ctx_dev/publish/boot.sh | sh -s install - -CMD sh bin/boot.sh - -` - var Index = &ice.Context{Name: "code", Help: "编程中心", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ - "login": {Name: "login", Help: "登录", Value: kit.Data()}, - "compile": {Name: "compile", Help: "编译", Value: kit.Data("path", "usr/publish")}, "publish": {Name: "publish", Help: "发布", Value: kit.Data("path", "usr/publish")}, "upgrade": {Name: "upgrade", Help: "升级", Value: kit.Dict(kit.MDB_HASH, kit.Dict( "system", kit.Dict(kit.MDB_LIST, kit.List( - kit.MDB_INPUT, "bin", "file", "ice.sh", "path", "bin/ice.sh", kit.MDB_INPUT, "bin", "file", "ice.bin", "path", "bin/ice.bin", + kit.MDB_INPUT, "bin", "file", "ice.sh", "path", "bin/ice.sh", )), ))}, + + "login": {Name: "login", Help: "登录", Value: kit.Data()}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() - m.Watch(ice.SYSTEM_INIT, "compile", "linux") - m.Watch(ice.SYSTEM_INIT, "publish", "bin/ice.sh") - - if m.Richs(ice.WEB_FAVOR, nil, "auto.init", nil) == nil { - m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "下载脚本", `curl -s "$ctx_dev/publish/auto.sh" -o auto.sh`) - m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "加载脚本", `source auto.sh`) - } - if m.Richs(ice.WEB_FAVOR, nil, "ice.init", nil) == nil { - m.Cmd(ice.WEB_FAVOR, "ice.init", ice.TYPE_SHELL, "一键启动", `curl -s "$ctx_dev/publish/ice.sh" |sh`) - } + // m.Watch(ice.SYSTEM_INIT, "compile", "linux") + // m.Watch(ice.SYSTEM_INIT, "publish", "bin/ice.sh") + // + // if m.Richs(ice.WEB_FAVOR, nil, "auto.init", nil) == nil { + // m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "下载脚本", `curl -s "$ctx_dev/publish/auto.sh" -o auto.sh`) + // m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "加载脚本", `source auto.sh`) + // } + // if m.Richs(ice.WEB_FAVOR, nil, "ice.init", nil) == nil { + // m.Cmd(ice.WEB_FAVOR, "ice.init", ice.TYPE_SHELL, "一键启动", `curl -s "$ctx_dev/publish/ice.sh" |sh`) + // } }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save("login") }}, - "compile": {Name: "compile", Help: "编译", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "compile": {Name: "compile [os [arch]]", Help: "编译", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { // 目录列表 m.Cmdy("nfs.dir", m.Conf("publish", "meta.path"), "time size path") @@ -73,20 +59,18 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", file := path.Join(m.Conf("compile", "meta.path"), kit.Keys("ice", goos, arch)) // 编译参数 - m.Add("option", "cmd_env", "GOCACHE", os.Getenv("GOCACHE")) - m.Add("option", "cmd_env", "GOARCH", arch, "GOOS", goos) - m.Add("option", "cmd_env", "HOME", os.Getenv("HOME")) - m.Add("option", "cmd_env", "CGO_ENABLED", "0") - m.Cmd("cli.system", "go", "build", "-o", file, main) + m.Optionv("cmd_env", "GOCACHE", os.Getenv("GOCACHE"), "HOME", os.Getenv("HOME"), + "GOARCH", arch, "GOOS", goos, "CGO_ENABLED", "0") + m.Cmd(ice.CLI_SYSTEM, "go", "build", "-o", file, main) // 编译记录 - m.Cmdy(ice.WEB_STORY, "catch", "bin", file) + m.Cmdy(ice.WEB_STORY, ice.STORY_CATCH, "bin", file) m.Log(ice.LOG_EXPORT, "%s: %s", main, file) }}, "publish": {Name: "publish", Help: "发布", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { // 目录列表 - m.Cmdy("nfs.dir", "", m.Conf("publish", "meta.path"), "time size path") + m.Cmdy("nfs.dir", m.Conf("publish", "meta.path"), "time size path") return } @@ -94,7 +78,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", if s, e := os.Stat(arg[0]); m.Assert(e) && s.IsDir() { // 发布目录 p = path.Base(arg[0]) + ".tar.gz" - m.Cmd("cli.system", "tar", "-zcf", p, arg[0]) + m.Cmd(ice.CLI_SYSTEM, "tar", "-zcf", p, arg[0]) defer func() { os.Remove(p) }() arg[0] = p } @@ -105,7 +89,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", os.Link(arg[0], target) // 发布记录 - m.Cmdy(ice.WEB_STORY, "catch", "bin", p) + m.Cmdy(ice.WEB_STORY, ice.STORY_CATCH, "bin", p) m.Log(ice.LOG_EXPORT, "%s: %s", arg[0], target) }}, "upgrade": {Name: "upgrade", Help: "升级", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -120,12 +104,10 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", exit = false return } - m.Cmd(ice.WEB_STORY, "add", "bin", value["path"], h) - os.Rename(kit.Format(value["path"]), kit.Keys(value["path"], "bak")) - os.Link(m.Cmd(ice.WEB_STORY, "index", h).Append("file"), kit.Format(value["path"])) + m.Cmd(ice.WEB_STORY, "add", "bin", value["path"], h) + m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, h, value["path"]) os.Chmod(kit.Format(value["path"]), 777) - m.Log(ice.LOG_EXPORT, "%s: %s", h, value["path"]) }) if exit { @@ -314,280 +296,6 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", }) } }}, - - "_tmux": {Name: "tmux [session [window [pane cmd]]]", Help: "窗口", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - prefix := kit.Simple(m.Confv("prefix", "tmux")) - if len(arg) > 1 { - switch arg[1] { - case "cmd": - - case "favor": - env := m.Cmdx(prefix, "show-environment", "-g") + m.Cmdx(prefix, "show-environment", "-t", arg[0]) - for _, l := range strings.Split(env, "\n") { - if strings.HasPrefix(l, "ctx_") { - v := strings.SplitN(l, "=", 2) - m.Option(v[0], v[1]) - } - } - m.Option("ctx_dev", m.Option("ctx_self")) - - m.Confm("tmux", "favor."+kit.Select("index", arg, 4), func(index int, value string) { - if index == 0 { - keys := strings.Split(value, " ") - value = "export" - for _, k := range keys { - value += " " + k + "=" + m.Option(k) - } - - } - m.Cmdy(prefix, "send-keys", "-t", arg[0], value, "Enter") - time.Sleep(100 * time.Millisecond) - }) - m.Echo(strings.TrimSpace(m.Cmdx(prefix, "capture-pane", "-pt", arg[0]))) - return - } - } - return - }}, - "_docker": {Name: "docker image|volume|network|container", Help: "容器", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { - prefix := kit.Simple(m.Confv("prefix", "docker")) - switch arg[0] { - case "image": - if prefix = append(prefix, "image"); len(arg) < 3 { - m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "IMAGE ID", "IMAGE_ID") - break - } - - switch arg[2] { - case "运行": - m.Cmdy(prefix[:2], "run", "-dt", m.Option("REPOSITORY")+":"+m.Option("TAG")) - case "清理": - m.Cmdy(prefix, "prune", "-f") - case "delete": - m.Cmdy(prefix, "rm", m.Option("IMAGE_ID")) - case "创建": - m.Option("base", m.Option("REPOSITORY")+":"+m.Option("TAG")) - app := m.Conf("runtime", "boot.ctx_app") - m.Option("name", app+":"+m.Time("20060102")) - m.Option("file", m.Conf("docker", "output")) - m.Option("user", m.Conf("runtime", "boot.username")) - m.Option("host", "http://"+m.Conf("runtime", "boot.hostname")+".local"+m.Conf("runtime", "boot.web_port")) - - if f, _, e := kit.Create(m.Option("file")); m.Assert(e) { - defer f.Close() - // if m.Assert(ctx.ExecuteStr(m, f, m.Conf("docker", "template."+app))) { - // m.Cmdy(prefix, "build", "-f", m.Option("file"), "-t", m.Option("name"), ".") - // } - } - - default: - if len(arg) == 3 { - m.Cmdy(prefix, "pull", arg[1]+":"+arg[2]) - break - } - } - - case "volume": - if prefix = append(prefix, "volume"); len(arg) == 1 { - m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "VOLUME NAME", "VOLUME_NAME") - break - } - - case "network": - if prefix = append(prefix, "network"); len(arg) == 1 { - m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "NETWORK ID", "NETWORK_ID") - break - } - - kit.Fetch(kit.Value(kit.UnMarshal(m.Cmdx(prefix, "inspect", arg[1])), "0.Containers"), func(key string, value map[string]interface{}) { - m.Push("CONTAINER_ID", key[:12]) - m.Push("name", value["Name"]) - m.Push("IPv4", value["IPv4Address"]) - m.Push("IPv6", value["IPV4Address"]) - m.Push("Mac", value["MacAddress"]) - }) - m.Table() - - case "container": - if prefix = append(prefix, "container"); len(arg) > 1 { - switch arg[2] { - case "进入": - m.Cmdy(m.Confv("prefix", "tmux"), "new-window", "-t", "", "-n", m.Option("CONTAINER_NAME"), - "-PF", "#{session_name}:#{window_name}.1", "docker exec -it "+arg[1]+" sh") - return - - case "停止": - m.Cmd(prefix, "stop", arg[1]) - - case "启动": - m.Cmd(prefix, "start", arg[1]) - - case "重启": - m.Cmd(prefix, "restart", arg[1]) - - case "清理": - m.Cmd(prefix, "prune", "-f") - - case "modify": - switch arg[3] { - case "NAMES": - m.Cmd(prefix, "rename", arg[1], arg[4:]) - } - - case "delete": - m.Cmdy(prefix, "rm", arg[1]) - - default: - if len(arg) == 2 { - m.Cmdy(prefix, "inspect", arg[1]) - return - } - m.Cmdy(prefix, "exec", arg[1], arg[2:]) - return - } - } - m.Cmdy(prefix, "ls", "-a", "cmd_parse", "cut", "cmd_headers", "CONTAINER ID", "CONTAINER_ID") - - case "command": - switch arg[3] { - case "base": - m.Echo("\n0[%s]$ %s %s\n", time.Now().Format("15:04:05"), arg[2], m.Conf("package", arg[2]+".update")) - m.Cmdy(prefix, "exec", arg[1], arg[2], strings.Split(m.Conf("package", arg[2]+".update"), " ")) - m.Confm("package", []string{arg[2], arg[3]}, func(index int, value string) { - m.Echo("\n%d[%s]$ %s %s %s\n", index+1, time.Now().Format("15:04:05"), arg[2], m.Conf("package", arg[2]+".install"), value) - m.Cmdy(prefix, "exec", arg[1], arg[2], strings.Split(m.Conf("package", arg[2]+".install"), " "), value) - }) - } - - default: - m.Cmdy(prefix, arg) - } - return - }}, - "_git": {Name: "git init|diff|status|commit|branch|remote|pull|push|sum", Help: "版本", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { - prefix, arg := append(kit.Simple(m.Confv("prefix", "git")), "cmd_dir", kit.Select(".", arg[0])), arg[1:] - - switch arg[0] { - case "init": - if _, e := os.Stat(path.Join(prefix[len(prefix)-1], ".git")); e != nil { - m.Cmdy(prefix, "init") - } - if len(arg) > 1 { - m.Cmdy(prefix, "remote", "add", "-f", kit.Select("origin", arg, 2), arg[1]) - m.Cmdy(prefix, "pull", kit.Select("origin", arg, 2), kit.Select("master", arg, 3)) - } - - m.Confm("git", "alias", func(key string, value string) { - m.Cmdy(prefix, "config", "alias."+key, value) - }) - - case "diff": - m.Cmdy(prefix, "diff") - case "status": - m.Cmdy(prefix, "status", "-sb", "cmd_parse", "cut", " ", "2", "tags file") - case "commit": - if len(arg) > 1 && m.Cmdy(prefix, "commit", "-am", arg[1]).Result() == "" { - break - } - m.Cmdy(prefix, "log", "--stat", "-n", "3") - case "branch": - if len(arg) > 1 { - m.Cmd(prefix, "branch", arg[1]) - m.Cmd(prefix, "checkout", arg[1]) - } - for _, v := range strings.Split(m.Cmdx(prefix, "branch", "-v"), "\n") { - if len(v) > 0 { - m.Push("tags", v[:2]) - vs := strings.SplitN(strings.TrimSpace(v[2:]), " ", 2) - m.Push("branch", vs[0]) - vs = strings.SplitN(strings.TrimSpace(vs[1]), " ", 2) - m.Push("hash", vs[0]) - m.Push("note", strings.TrimSpace(vs[1])) - } - } - m.Table() - case "remote": - m.Cmdy(prefix, "remote", "-v", "cmd_parse", "cut", " ", "3", "remote url tag") - - case "push": - m.Cmdy(prefix, "push") - case "sum": - total := false - if len(arg) > 1 && arg[1] == "total" { - total, arg = true, arg[1:] - } - - args := []string{"log", "--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse"} - if len(arg) > 1 { - args = append(args, kit.Select("-n", "--since", strings.Contains(arg[1], "-"))) - if strings.Contains(arg[1], "-") && !strings.Contains(arg[1], ":") { - arg[1] = arg[1] + " 00:00:00" - } - args = append(args, arg[1:]...) - } else { - args = append(args, "-n", "30") - } - - var total_day time.Duration - count, count_add, count_del := 0, 0, 0 - if out, e := exec.Command("git", args...).CombinedOutput(); e == nil { - for i, v := range strings.Split(string(out), "commit: ") { - if i > 0 { - l := strings.Split(v, "\n") - hs := strings.Split(l[0], " ") - - add, del := "0", "0" - if len(l) > 3 { - fs := strings.Split(strings.TrimSpace(l[3]), ", ") - if adds := strings.Split(fs[1], " "); len(fs) > 2 { - dels := strings.Split(fs[2], " ") - add = adds[0] - del = dels[0] - } else if adds[1] == "insertions(+)" { - add = adds[0] - } else { - del = adds[0] - } - } - - if total { - if count++; i == 1 { - if t, e := time.Parse(ice.ICE_DATE, hs[0]); e == nil { - total_day = time.Now().Sub(t) - m.Append("from", hs[0]) - } - } - count_add += kit.Int(add) - count_del += kit.Int(del) - continue - } - - m.Push("date", hs[0]) - m.Push("adds", add) - m.Push("dels", del) - m.Push("rest", kit.Int(add)-kit.Int(del)) - m.Push("note", l[1]) - m.Push("hour", strings.Split(hs[1], ":")[0]) - m.Push("time", hs[1]) - } - } - if total { - m.Append("days", int(total_day.Hours())/24) - m.Append("commit", count) - m.Append("adds", count_add) - m.Append("dels", count_del) - m.Append("rest", count_add-count_del) - } - m.Table() - } else { - m.Log("warn", "%v", string(out)) - } - - default: - m.Cmdy(prefix, arg) - } - return - }}, }, } diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index 55a771b6..13fefc97 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -459,7 +459,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Optionv("title", map[string]int{}) m.Optionv("menu", map[string]interface{}{"list": []interface{}{}}) m.Optionv(ice.MSG_ALIAS, m.Confv("word", "meta.alias")) - m.Set("result").Cmdy("ssh.scan", arg[0], arg[0], path.Join(m.Conf(cmd, "meta.path"), arg[0])) + m.Set("result").Cmdy(ice.SSH_SOURCE, path.Join(m.Conf(cmd, "meta.path"), arg[0])) }}, "feel": {Name: "feel", Help: "影音媒体", Meta: kit.Dict("remote", "pod", "display", "wiki/feel", "detail", []string{"标签", "删除"}), List: kit.List( kit.MDB_INPUT, "text", "name", "name", @@ -564,7 +564,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Cmd("word", "action", "追加", arg) m.Option("scan_mode", "scan") - m.Cmdy("ssh.scan", "some", "some", path.Join(m.Conf("word", "meta.path"), arg[0])) + m.Cmdy(ice.SSH_SOURCE, path.Join(m.Conf("word", "meta.path"), arg[0])) }}, }, } diff --git a/misc/docker/docker.go b/misc/docker/docker.go index 05b90e64..adbcb875 100644 --- a/misc/docker/docker.go +++ b/misc/docker/docker.go @@ -4,9 +4,25 @@ import ( "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/core/code" "github.com/shylinux/toolkits" + "os" + "os/exec" + "path" "strings" + "time" ) +var Dockfile = ` +FROM {{options . "base"}} + +WORKDIR /home/{{options . "user"}}/context +Env ctx_dev {{options . "host"}} + +RUN wget -q -O - $ctx_dev/publish/boot.sh | sh -s install + +CMD sh bin/boot.sh + +` + var Index = &ice.Context{Name: "docker", Help: "虚拟机", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ @@ -14,11 +30,11 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机", }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if m.Richs(ice.WEB_FAVOR, nil, "alpine.init", nil) == nil { - m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "镜像源", `sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories`) - m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "软件包", `apk add bash`) - m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "软件包", `apk add curl`) - } + // if m.Richs(ice.WEB_FAVOR, nil, "alpine.init", nil) == nil { + // m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "镜像源", `sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories`) + // m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "软件包", `apk add bash`) + // m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "软件包", `apk add curl`) + // } }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, @@ -92,6 +108,280 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机", prefix := []string{ice.CLI_SYSTEM, "docker", "container"} m.Cmdy(prefix, "exec", arg[0], arg[1:]).Set("append") }}, + + "_tmux": {Name: "tmux [session [window [pane cmd]]]", Help: "窗口", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + prefix := kit.Simple(m.Confv("prefix", "tmux")) + if len(arg) > 1 { + switch arg[1] { + case "cmd": + + case "favor": + env := m.Cmdx(prefix, "show-environment", "-g") + m.Cmdx(prefix, "show-environment", "-t", arg[0]) + for _, l := range strings.Split(env, "\n") { + if strings.HasPrefix(l, "ctx_") { + v := strings.SplitN(l, "=", 2) + m.Option(v[0], v[1]) + } + } + m.Option("ctx_dev", m.Option("ctx_self")) + + m.Confm("tmux", "favor."+kit.Select("index", arg, 4), func(index int, value string) { + if index == 0 { + keys := strings.Split(value, " ") + value = "export" + for _, k := range keys { + value += " " + k + "=" + m.Option(k) + } + + } + m.Cmdy(prefix, "send-keys", "-t", arg[0], value, "Enter") + time.Sleep(100 * time.Millisecond) + }) + m.Echo(strings.TrimSpace(m.Cmdx(prefix, "capture-pane", "-pt", arg[0]))) + return + } + } + return + }}, + "_docker": {Name: "docker image|volume|network|container", Help: "容器", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { + prefix := kit.Simple(m.Confv("prefix", "docker")) + switch arg[0] { + case "image": + if prefix = append(prefix, "image"); len(arg) < 3 { + m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "IMAGE ID", "IMAGE_ID") + break + } + + switch arg[2] { + case "运行": + m.Cmdy(prefix[:2], "run", "-dt", m.Option("REPOSITORY")+":"+m.Option("TAG")) + case "清理": + m.Cmdy(prefix, "prune", "-f") + case "delete": + m.Cmdy(prefix, "rm", m.Option("IMAGE_ID")) + case "创建": + m.Option("base", m.Option("REPOSITORY")+":"+m.Option("TAG")) + app := m.Conf("runtime", "boot.ctx_app") + m.Option("name", app+":"+m.Time("20060102")) + m.Option("file", m.Conf("docker", "output")) + m.Option("user", m.Conf("runtime", "boot.username")) + m.Option("host", "http://"+m.Conf("runtime", "boot.hostname")+".local"+m.Conf("runtime", "boot.web_port")) + + if f, _, e := kit.Create(m.Option("file")); m.Assert(e) { + defer f.Close() + // if m.Assert(ctx.ExecuteStr(m, f, m.Conf("docker", "template."+app))) { + // m.Cmdy(prefix, "build", "-f", m.Option("file"), "-t", m.Option("name"), ".") + // } + } + + default: + if len(arg) == 3 { + m.Cmdy(prefix, "pull", arg[1]+":"+arg[2]) + break + } + } + + case "volume": + if prefix = append(prefix, "volume"); len(arg) == 1 { + m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "VOLUME NAME", "VOLUME_NAME") + break + } + + case "network": + if prefix = append(prefix, "network"); len(arg) == 1 { + m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "NETWORK ID", "NETWORK_ID") + break + } + + kit.Fetch(kit.Value(kit.UnMarshal(m.Cmdx(prefix, "inspect", arg[1])), "0.Containers"), func(key string, value map[string]interface{}) { + m.Push("CONTAINER_ID", key[:12]) + m.Push("name", value["Name"]) + m.Push("IPv4", value["IPv4Address"]) + m.Push("IPv6", value["IPV4Address"]) + m.Push("Mac", value["MacAddress"]) + }) + m.Table() + + case "container": + if prefix = append(prefix, "container"); len(arg) > 1 { + switch arg[2] { + case "进入": + m.Cmdy(m.Confv("prefix", "tmux"), "new-window", "-t", "", "-n", m.Option("CONTAINER_NAME"), + "-PF", "#{session_name}:#{window_name}.1", "docker exec -it "+arg[1]+" sh") + return + + case "停止": + m.Cmd(prefix, "stop", arg[1]) + + case "启动": + m.Cmd(prefix, "start", arg[1]) + + case "重启": + m.Cmd(prefix, "restart", arg[1]) + + case "清理": + m.Cmd(prefix, "prune", "-f") + + case "modify": + switch arg[3] { + case "NAMES": + m.Cmd(prefix, "rename", arg[1], arg[4:]) + } + + case "delete": + m.Cmdy(prefix, "rm", arg[1]) + + default: + if len(arg) == 2 { + m.Cmdy(prefix, "inspect", arg[1]) + return + } + m.Cmdy(prefix, "exec", arg[1], arg[2:]) + return + } + } + m.Cmdy(prefix, "ls", "-a", "cmd_parse", "cut", "cmd_headers", "CONTAINER ID", "CONTAINER_ID") + + case "command": + switch arg[3] { + case "base": + m.Echo("\n0[%s]$ %s %s\n", time.Now().Format("15:04:05"), arg[2], m.Conf("package", arg[2]+".update")) + m.Cmdy(prefix, "exec", arg[1], arg[2], strings.Split(m.Conf("package", arg[2]+".update"), " ")) + m.Confm("package", []string{arg[2], arg[3]}, func(index int, value string) { + m.Echo("\n%d[%s]$ %s %s %s\n", index+1, time.Now().Format("15:04:05"), arg[2], m.Conf("package", arg[2]+".install"), value) + m.Cmdy(prefix, "exec", arg[1], arg[2], strings.Split(m.Conf("package", arg[2]+".install"), " "), value) + }) + } + + default: + m.Cmdy(prefix, arg) + } + return + }}, + "_git": {Name: "git init|diff|status|commit|branch|remote|pull|push|sum", Help: "版本", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { + prefix, arg := append(kit.Simple(m.Confv("prefix", "git")), "cmd_dir", kit.Select(".", arg[0])), arg[1:] + + switch arg[0] { + case "init": + if _, e := os.Stat(path.Join(prefix[len(prefix)-1], ".git")); e != nil { + m.Cmdy(prefix, "init") + } + if len(arg) > 1 { + m.Cmdy(prefix, "remote", "add", "-f", kit.Select("origin", arg, 2), arg[1]) + m.Cmdy(prefix, "pull", kit.Select("origin", arg, 2), kit.Select("master", arg, 3)) + } + + m.Confm("git", "alias", func(key string, value string) { + m.Cmdy(prefix, "config", "alias."+key, value) + }) + + case "diff": + m.Cmdy(prefix, "diff") + case "status": + m.Cmdy(prefix, "status", "-sb", "cmd_parse", "cut", " ", "2", "tags file") + case "commit": + if len(arg) > 1 && m.Cmdy(prefix, "commit", "-am", arg[1]).Result() == "" { + break + } + m.Cmdy(prefix, "log", "--stat", "-n", "3") + case "branch": + if len(arg) > 1 { + m.Cmd(prefix, "branch", arg[1]) + m.Cmd(prefix, "checkout", arg[1]) + } + for _, v := range strings.Split(m.Cmdx(prefix, "branch", "-v"), "\n") { + if len(v) > 0 { + m.Push("tags", v[:2]) + vs := strings.SplitN(strings.TrimSpace(v[2:]), " ", 2) + m.Push("branch", vs[0]) + vs = strings.SplitN(strings.TrimSpace(vs[1]), " ", 2) + m.Push("hash", vs[0]) + m.Push("note", strings.TrimSpace(vs[1])) + } + } + m.Table() + case "remote": + m.Cmdy(prefix, "remote", "-v", "cmd_parse", "cut", " ", "3", "remote url tag") + + case "push": + m.Cmdy(prefix, "push") + case "sum": + total := false + if len(arg) > 1 && arg[1] == "total" { + total, arg = true, arg[1:] + } + + args := []string{"log", "--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse"} + if len(arg) > 1 { + args = append(args, kit.Select("-n", "--since", strings.Contains(arg[1], "-"))) + if strings.Contains(arg[1], "-") && !strings.Contains(arg[1], ":") { + arg[1] = arg[1] + " 00:00:00" + } + args = append(args, arg[1:]...) + } else { + args = append(args, "-n", "30") + } + + var total_day time.Duration + count, count_add, count_del := 0, 0, 0 + if out, e := exec.Command("git", args...).CombinedOutput(); e == nil { + for i, v := range strings.Split(string(out), "commit: ") { + if i > 0 { + l := strings.Split(v, "\n") + hs := strings.Split(l[0], " ") + + add, del := "0", "0" + if len(l) > 3 { + fs := strings.Split(strings.TrimSpace(l[3]), ", ") + if adds := strings.Split(fs[1], " "); len(fs) > 2 { + dels := strings.Split(fs[2], " ") + add = adds[0] + del = dels[0] + } else if adds[1] == "insertions(+)" { + add = adds[0] + } else { + del = adds[0] + } + } + + if total { + if count++; i == 1 { + if t, e := time.Parse(ice.ICE_DATE, hs[0]); e == nil { + total_day = time.Now().Sub(t) + m.Append("from", hs[0]) + } + } + count_add += kit.Int(add) + count_del += kit.Int(del) + continue + } + + m.Push("date", hs[0]) + m.Push("adds", add) + m.Push("dels", del) + m.Push("rest", kit.Int(add)-kit.Int(del)) + m.Push("note", l[1]) + m.Push("hour", strings.Split(hs[1], ":")[0]) + m.Push("time", hs[1]) + } + } + if total { + m.Append("days", int(total_day.Hours())/24) + m.Append("commit", count) + m.Append("adds", count_add) + m.Append("dels", count_del) + m.Append("rest", count_add-count_del) + } + m.Table() + } else { + m.Log("warn", "%v", string(out)) + } + + default: + m.Cmdy(prefix, arg) + } + return + }}, }, } diff --git a/misc/git/git.go b/misc/git/git.go index 2985ab82..538e5559 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -30,7 +30,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库", "total": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true"))}, }, Commands: map[string]*ice.Command{ - ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "init": {Name: "init", Help: "init", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { // 系统项目 wd, _ := os.Getwd() add(m, path.Base(wd), wd) @@ -45,7 +45,6 @@ var Index = &ice.Context{Name: "git", Help: "代码库", add(m, value["name"], value["path"]) }) }}, - ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, "repos": {Name: "repos [name [path [remote [branch]]]]", Help: "仓库", List: kit.List( kit.MDB_INPUT, "text", "name", "name", "action", "auto", @@ -53,7 +52,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 1 { - if _, e := os.Stat(m.Option("cmd_dir", path.Join(arg[1], ".git"))); e != nil && os.IsNotExist(e) { + if _, e := os.Stat(path.Join(arg[1], ".git")); e != nil && os.IsNotExist(e) { // 下载仓库 m.Cmd(ice.CLI_SYSTEM, "git", "clone", "-b", kit.Select("master", arg, 3), kit.Select(m.Conf("repos", "meta.owner")+"/"+arg[0], arg, 2), arg[1]) diff --git a/misc/input/input.go b/misc/input/input.go index 31760c77..7988d556 100644 --- a/misc/input/input.go +++ b/misc/input/input.go @@ -25,7 +25,6 @@ var Index = &ice.Context{Name: "input", Help: "输入法", Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() - m.Cmd("web.code.git.repos", m.Conf("input", "meta.repos")) }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save("input") diff --git a/misc/tmux/tmux.go b/misc/tmux/tmux.go index 1fe33a92..95ef85f4 100644 --- a/misc/tmux/tmux.go +++ b/misc/tmux/tmux.go @@ -52,14 +52,10 @@ var Index = &ice.Context{Name: "tmux", Help: "命令行", )}, }, Commands: map[string]*ice.Command{ - ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Watch(ice.SYSTEM_INIT, "web.code.tmux.init") + "init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Watch(ice.DREAM_START, "web.code.tmux.auto") m.Watch(ice.FAVOR_START, "web.code.tmux.auto") - }}, - ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - }}, - "init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + for _, v := range []string{"auto.sh", "auto.vim"} { p := path.Join(m.Conf("web.code.publish", "meta.path"), v) if _, e := os.Stat(p); e != nil && os.IsNotExist(e) { diff --git a/template.sh b/template.sh index e73d01be..b5b86c79 100755 --- a/template.sh +++ b/template.sh @@ -4,6 +4,7 @@ ice_sh="bin/ice.sh" ice_bin="bin/ice.bin" ice_mod="${PWD##**/}" init_shy="etc/init.shy" +local_shy="etc/local.shy" exit_shy="etc/exit.shy" main_go="src/main.go" readme="README.md" @@ -42,6 +43,16 @@ END [ -d etc ] || mkdir etc [ -f ${init_shy} ] || cat >> ${init_shy} <> ${local_shy} <> "${exit_shy}" <> ${ice_sh} <\$ctx_log && echo -e "\n\nrestarting..." || break done } -serve() { - prepare && shutdown && start \$@ -} restart() { [ -e \$ctx_pid ] && kill -2 \`cat \$ctx_pid\` || echo } shutdown() { [ -e \$ctx_pid ] && kill -3 \`cat \$ctx_pid\` || echo } +serve() { + prepare && shutdown && start \$@ +} cmd=\$1 && [ -n "\$cmd" ] && shift || cmd=serve \$cmd \$* @@ -97,14 +109,24 @@ build() { export CGO_ENABLED=0 export GOPRIVATE=github.com export GOPROXY=https://goproxy.cn - go build -o ${ice_bin} ${main_go} && chmod u+x ${ice_bin} && ./${ice_sh} restart miss=./ && [ "$1" != "" ] && miss=$1 && shift && mkdir $miss - cd $miss && prepare && go build -o ${ice_bin} ${main_go} && chmod u+x ${ice_bin} && ./${ice_sh} start serve dev + cd $miss && prepare && go build -o ${ice_bin} ${main_go} && chmod u+x ${ice_bin} && ./${ice_sh} start serve } tutor() { [ -d $1 ] || mkdir $1 + [ -f "$1/$1.js" ] || cat >> "$1/$1.js" <> "$1/$1.shy" <%s", m.source.Name, m.target.Name), - prefix, level, str, suffix) + if os.Getenv("ctx_mod") != "" { + // 输出日志 + fmt.Fprintf(os.Stderr, "%s %02d %9s %s%s %s%s\n", + m.time.Format(ICE_TIME), m.code, fmt.Sprintf("%s->%s", m.source.Name, m.target.Name), + prefix, level, str, suffix) + } return m } func (m *Message) Cost(str string, arg ...interface{}) *Message {