forked from x/icebergs
opt boot
This commit is contained in:
parent
476d82cf19
commit
6277c5536d
26
base.go
26
base.go
@ -3,6 +3,7 @@ package ice
|
|||||||
import (
|
import (
|
||||||
"github.com/shylinux/toolkits"
|
"github.com/shylinux/toolkits"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -36,7 +37,7 @@ func (f *Frame) Start(m *Message, arg ...string) bool {
|
|||||||
m.Cap(CTX_STREAM, strings.Split(m.Time(), " ")[1])
|
m.Cap(CTX_STREAM, strings.Split(m.Time(), " ")[1])
|
||||||
m.root.Cost("start")
|
m.root.Cost("start")
|
||||||
|
|
||||||
m.Cmd("init", arg)
|
m.Cmdy("init", arg)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (f *Frame) Close(m *Message, arg ...string) bool {
|
func (f *Frame) Close(m *Message, arg ...string) bool {
|
||||||
@ -86,19 +87,19 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
|
|||||||
m.root.Cost("_init")
|
m.root.Cost("_init")
|
||||||
|
|
||||||
m.target.root.wg = &sync.WaitGroup{}
|
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.Start(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Cmd("ssh.scan", "init.shy", "启动配置", "etc/init.shy")
|
m.Cmd(SSH_SOURCE, "etc/init.shy", "init.shy", "启动配置")
|
||||||
m.Cmd(arg)
|
m.Cmdy(arg)
|
||||||
}},
|
}},
|
||||||
"help": {Name: "help", Help: "帮助", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
"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"))
|
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) {
|
"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.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.Cmd(ICE_EXIT)
|
||||||
m.root.Cost("_exit")
|
m.root.Cost("_exit")
|
||||||
@ -134,18 +135,23 @@ func Run(arg ...string) string {
|
|||||||
arg = os.Args[1:]
|
arg = os.Args[1:]
|
||||||
}
|
}
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
arg = append(arg, WEB_SERVE)
|
// arg = append(arg, WEB_SERVE)
|
||||||
|
arg = append(arg, WEB_SPACE, "connect", "self")
|
||||||
}
|
}
|
||||||
|
|
||||||
frame := &Frame{}
|
frame := &Frame{}
|
||||||
Index.server = frame
|
Index.server = frame
|
||||||
Pulse.Option("begin_time", Pulse.Time())
|
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...)
|
frame.Close(Pulse.Spawns(), arg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
if Pulse.Result() == "" {
|
||||||
os.Exit(frame.code)
|
Pulse.Table()
|
||||||
return Pulse.Result()
|
}
|
||||||
|
fmt.Printf(Pulse.Result())
|
||||||
|
// time.Sleep(time.Second)
|
||||||
|
os.Exit(frame.code)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
|||||||
}
|
}
|
||||||
if user, e := user.Current(); e == nil {
|
if user, e := user.Current(); e == nil {
|
||||||
m.Conf(ice.CLI_RUNTIME, "boot.username", path.Base(kit.Select(user.Name, os.Getenv("USER"))))
|
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"))
|
m.Cmd(ice.AAA_ROLE, "root", m.Conf(ice.CLI_RUNTIME, "boot.username"))
|
||||||
}
|
}
|
||||||
if name, e := os.Getwd(); e == nil {
|
if name, e := os.Getwd(); e == nil {
|
||||||
@ -77,6 +76,9 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
|||||||
cmd.Dir = m.Option("cmd_dir")
|
cmd.Dir = m.Option("cmd_dir")
|
||||||
if len(cmd.Dir) > 0 {
|
if len(cmd.Dir) > 0 {
|
||||||
m.Info("dir: %s", cmd.Dir)
|
m.Info("dir: %s", cmd.Dir)
|
||||||
|
if _, e := os.Stat(cmd.Dir); e != nil && os.IsNotExist(e) {
|
||||||
|
os.MkdirAll(cmd.Dir, 0777)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 环境变量
|
// 环境变量
|
||||||
|
@ -137,6 +137,9 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
|||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case "save":
|
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])
|
arg[1] = path.Join(msg.Conf(ice.CTX_CONFIG, "meta.path"), arg[1])
|
||||||
if f, p, e := kit.Create(arg[1]); m.Assert(e) {
|
if f, p, e := kit.Create(arg[1]); m.Assert(e) {
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
|
@ -86,10 +86,11 @@ var Index = &ice.Context{Name: "gdb", Help: "事件模块",
|
|||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
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.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.Conf(ice.CLI_RUNTIME, "conf.ctx_pid")), m.Conf(ice.CLI_RUNTIME, "host.pid"))
|
||||||
|
}
|
||||||
|
// 进程标识
|
||||||
if f, ok := m.Target().Server().(*Frame); ok {
|
if f, ok := m.Target().Server().(*Frame); ok {
|
||||||
// 注册信号
|
// 注册信号
|
||||||
f.s = make(chan os.Signal, ice.ICE_CHAN)
|
f.s = make(chan os.Signal, ice.ICE_CHAN)
|
||||||
|
@ -92,6 +92,7 @@ var Index = &ice.Context{Name: "log", Help: "日志模块",
|
|||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if os.Getenv("ctx_mod") != "" {
|
||||||
m.Confm("file", nil, func(key string, value map[string]interface{}) {
|
m.Confm("file", nil, func(key string, value map[string]interface{}) {
|
||||||
// 日志文件
|
// 日志文件
|
||||||
if f, p, e := kit.Create(kit.Format(value["path"])); m.Assert(e) {
|
if f, p, e := kit.Create(kit.Format(value["path"])); m.Assert(e) {
|
||||||
@ -100,6 +101,7 @@ var Index = &ice.Context{Name: "log", Help: "日志模块",
|
|||||||
value["file"] = f
|
value["file"] = f
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}},
|
}},
|
||||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if f, ok := m.Target().Server().(*Frame); ok {
|
if f, ok := m.Target().Server().(*Frame); ok {
|
||||||
|
@ -240,11 +240,11 @@ var Index = &ice.Context{Name: "ssh", Help: "终端模块",
|
|||||||
f.parse(m, kit.Format(value["line"]))
|
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))
|
buf := bytes.NewBuffer(make([]byte, 0, 4096))
|
||||||
m.Optionv(ice.MSG_STDOUT, buf)
|
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())
|
m.Echo(buf.String())
|
||||||
}},
|
}},
|
||||||
"print": {Name: "print", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"print": {Name: "print", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
@ -35,6 +35,18 @@ type Frame struct {
|
|||||||
send map[string]*ice.Message
|
send map[string]*ice.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Refresh(msg *ice.Message, n int) string {
|
||||||
|
return fmt.Sprintf(`<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="Refresh" content="%d">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
请稍后,系统初始化中...
|
||||||
|
</body>
|
||||||
|
`, n)
|
||||||
|
}
|
||||||
|
|
||||||
func Redirect(msg *ice.Message, url string, arg ...interface{}) *ice.Message {
|
func Redirect(msg *ice.Message, url string, arg ...interface{}) *ice.Message {
|
||||||
msg.Push("_output", "redirect")
|
msg.Push("_output", "redirect")
|
||||||
msg.Echo(kit.MergeURL(url, arg...))
|
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")) {
|
if index && kit.Right(m.Conf(ice.WEB_SERVE, "meta.logheaders")) {
|
||||||
|
// 请求参数
|
||||||
for k, v := range r.Header {
|
for k, v := range r.Header {
|
||||||
m.Info("%s: %v", k, kit.Format(v))
|
m.Info("%s: %v", k, kit.Format(v))
|
||||||
}
|
}
|
||||||
m.Info(" ")
|
m.Info(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
web.ServeMux.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
if index && kit.Right(m.Conf(ice.WEB_SERVE, "meta.logheaders")) {
|
if index && kit.Right(m.Conf(ice.WEB_SERVE, "meta.logheaders")) {
|
||||||
|
// 响应参数
|
||||||
for k, v := range w.Header() {
|
for k, v := range w.Header() {
|
||||||
m.Info("%s: %v", k, kit.Format(v))
|
m.Info("%s: %v", k, kit.Format(v))
|
||||||
}
|
}
|
||||||
@ -401,13 +426,14 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
|||||||
"/static/volcanos/": "usr/volcanos/",
|
"/static/volcanos/": "usr/volcanos/",
|
||||||
"/publish/": "usr/publish/",
|
"/publish/": "usr/publish/",
|
||||||
},
|
},
|
||||||
"volcanos", kit.Dict("path", "usr/volcanos",
|
"volcanos", kit.Dict("path", "usr/volcanos", "branch", "master",
|
||||||
"repos", "https://github.com/shylinux/volcanos",
|
"repos", "https://github.com/shylinux/volcanos",
|
||||||
"branch", "master"),
|
),
|
||||||
"template", map[string]interface{}{"path": "usr/template", "list": []interface{}{
|
"template", map[string]interface{}{"path": "usr/template", "list": []interface{}{
|
||||||
`{{define "raw"}}{{.Result}}{{end}}`,
|
`{{define "raw"}}{{.Result}}{{end}}`,
|
||||||
}},
|
}},
|
||||||
"logheaders", "false",
|
"logheaders", "false",
|
||||||
|
"init", "false",
|
||||||
)},
|
)},
|
||||||
ice.WEB_SPACE: {Name: "space", Help: "空间站", Value: kit.Data(kit.MDB_SHORT, "name",
|
ice.WEB_SPACE: {Name: "space", Help: "空间站", Value: kit.Data(kit.MDB_SHORT, "name",
|
||||||
"redial.a", 3000, "redial.b", 1000, "redial.c", 1000,
|
"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 {
|
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.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) {
|
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
p := m.Conf(ice.WEB_CACHE, "meta.store")
|
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.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.Done()
|
||||||
m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) {
|
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:
|
default:
|
||||||
// 启动服务
|
// 启动服务
|
||||||
m.Target().Start(m, "self")
|
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(
|
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_dir", p)
|
||||||
m.Option("cmd_type", "daemon")
|
m.Option("cmd_type", "daemon")
|
||||||
m.Option("cmd_env", "ctx_log", "boot.log")
|
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])
|
m.Cmd(m.Confv(ice.WEB_DREAM, "meta.cmd"), "self", arg[0])
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
m.Event(ice.DREAM_START, arg...)
|
m.Event(ice.DREAM_START, arg...)
|
||||||
@ -1272,11 +1300,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
|||||||
os.Rename(name, kit.Keys(name, "bak"))
|
os.Rename(name, kit.Keys(name, "bak"))
|
||||||
if msg.Append("file") != "" {
|
if msg.Append("file") != "" {
|
||||||
p := path.Dir(name)
|
p := path.Dir(name)
|
||||||
e := os.MkdirAll(p, 0777)
|
os.MkdirAll(p, 0777)
|
||||||
m.Log("what", "%v", e)
|
|
||||||
|
|
||||||
e = os.Link(msg.Append("file"), name)
|
os.Link(msg.Append("file"), name)
|
||||||
m.Log("what", "%v", e)
|
|
||||||
m.Log(ice.LOG_EXPORT, "%s: %s", msg.Append("file"), name)
|
m.Log(ice.LOG_EXPORT, "%s: %s", msg.Append("file"), name)
|
||||||
} else {
|
} else {
|
||||||
if f, p, e := kit.Create(name); m.Assert(e) {
|
if f, p, e := kit.Create(name); m.Assert(e) {
|
||||||
|
4
conf.go
4
conf.go
@ -109,6 +109,9 @@ const ( // LOG
|
|||||||
LOG_ERROR = "error"
|
LOG_ERROR = "error"
|
||||||
LOG_TRACE = "trace"
|
LOG_TRACE = "trace"
|
||||||
)
|
)
|
||||||
|
const ( // SSH
|
||||||
|
SSH_SOURCE = "source"
|
||||||
|
)
|
||||||
const ( // GDB
|
const ( // GDB
|
||||||
GDB_SIGNAL = "signal"
|
GDB_SIGNAL = "signal"
|
||||||
GDB_TIMER = "timer"
|
GDB_TIMER = "timer"
|
||||||
@ -193,6 +196,7 @@ var Alias = map[string]string{
|
|||||||
|
|
||||||
CLI_RUNTIME: "cli.runtime",
|
CLI_RUNTIME: "cli.runtime",
|
||||||
CLI_SYSTEM: "cli.system",
|
CLI_SYSTEM: "cli.system",
|
||||||
|
SSH_SOURCE: "ssh.source",
|
||||||
|
|
||||||
AAA_ROLE: "aaa.role",
|
AAA_ROLE: "aaa.role",
|
||||||
AAA_USER: "aaa.user",
|
AAA_USER: "aaa.user",
|
||||||
|
@ -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_STREAM, m.Conf(ice.CHAT_RIVER, "meta.fe"))
|
||||||
m.Cap(ice.CTX_STATUS, "start")
|
m.Cap(ice.CTX_STATUS, "start")
|
||||||
}},
|
}},
|
||||||
|
@ -8,58 +8,44 @@ import (
|
|||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"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: "编程中心",
|
var Index = &ice.Context{Name: "code", Help: "编程中心",
|
||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"login": {Name: "login", Help: "登录", Value: kit.Data()},
|
|
||||||
|
|
||||||
"compile": {Name: "compile", Help: "编译", Value: kit.Data("path", "usr/publish")},
|
"compile": {Name: "compile", Help: "编译", Value: kit.Data("path", "usr/publish")},
|
||||||
"publish": {Name: "publish", 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(
|
"upgrade": {Name: "upgrade", Help: "升级", Value: kit.Dict(kit.MDB_HASH, kit.Dict(
|
||||||
"system", kit.Dict(kit.MDB_LIST, kit.List(
|
"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.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{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Load()
|
m.Load()
|
||||||
|
|
||||||
m.Watch(ice.SYSTEM_INIT, "compile", "linux")
|
// m.Watch(ice.SYSTEM_INIT, "compile", "linux")
|
||||||
m.Watch(ice.SYSTEM_INIT, "publish", "bin/ice.sh")
|
// m.Watch(ice.SYSTEM_INIT, "publish", "bin/ice.sh")
|
||||||
|
//
|
||||||
if m.Richs(ice.WEB_FAVOR, nil, "auto.init", nil) == nil {
|
// 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, "下载脚本", `curl -s "$ctx_dev/publish/auto.sh" -o auto.sh`)
|
||||||
m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "加载脚本", `source 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 {
|
// 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.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) {
|
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Save("login")
|
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 {
|
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")
|
||||||
@ -73,20 +59,18 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
file := path.Join(m.Conf("compile", "meta.path"), kit.Keys("ice", goos, arch))
|
file := path.Join(m.Conf("compile", "meta.path"), kit.Keys("ice", goos, arch))
|
||||||
|
|
||||||
// 编译参数
|
// 编译参数
|
||||||
m.Add("option", "cmd_env", "GOCACHE", os.Getenv("GOCACHE"))
|
m.Optionv("cmd_env", "GOCACHE", os.Getenv("GOCACHE"), "HOME", os.Getenv("HOME"),
|
||||||
m.Add("option", "cmd_env", "GOARCH", arch, "GOOS", goos)
|
"GOARCH", arch, "GOOS", goos, "CGO_ENABLED", "0")
|
||||||
m.Add("option", "cmd_env", "HOME", os.Getenv("HOME"))
|
m.Cmd(ice.CLI_SYSTEM, "go", "build", "-o", file, main)
|
||||||
m.Add("option", "cmd_env", "CGO_ENABLED", "0")
|
|
||||||
m.Cmd("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)
|
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) {
|
"publish": {Name: "publish", Help: "发布", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) == 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +78,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
if s, e := os.Stat(arg[0]); m.Assert(e) && s.IsDir() {
|
if s, e := os.Stat(arg[0]); m.Assert(e) && s.IsDir() {
|
||||||
// 发布目录
|
// 发布目录
|
||||||
p = path.Base(arg[0]) + ".tar.gz"
|
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) }()
|
defer func() { os.Remove(p) }()
|
||||||
arg[0] = p
|
arg[0] = p
|
||||||
}
|
}
|
||||||
@ -105,7 +89,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
os.Link(arg[0], target)
|
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)
|
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) {
|
"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
|
exit = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.Cmd(ice.WEB_STORY, "add", "bin", value["path"], h)
|
|
||||||
|
|
||||||
os.Rename(kit.Format(value["path"]), kit.Keys(value["path"], "bak"))
|
m.Cmd(ice.WEB_STORY, "add", "bin", value["path"], h)
|
||||||
os.Link(m.Cmd(ice.WEB_STORY, "index", h).Append("file"), kit.Format(value["path"]))
|
m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, h, value["path"])
|
||||||
os.Chmod(kit.Format(value["path"]), 777)
|
os.Chmod(kit.Format(value["path"]), 777)
|
||||||
m.Log(ice.LOG_EXPORT, "%s: %s", h, value["path"])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if exit {
|
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
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
|||||||
m.Optionv("title", map[string]int{})
|
m.Optionv("title", map[string]int{})
|
||||||
m.Optionv("menu", map[string]interface{}{"list": []interface{}{}})
|
m.Optionv("menu", map[string]interface{}{"list": []interface{}{}})
|
||||||
m.Optionv(ice.MSG_ALIAS, m.Confv("word", "meta.alias"))
|
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(
|
"feel": {Name: "feel", Help: "影音媒体", Meta: kit.Dict("remote", "pod", "display", "wiki/feel", "detail", []string{"标签", "删除"}), List: kit.List(
|
||||||
kit.MDB_INPUT, "text", "name", "name",
|
kit.MDB_INPUT, "text", "name", "name",
|
||||||
@ -564,7 +564,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
|||||||
m.Cmd("word", "action", "追加", arg)
|
m.Cmd("word", "action", "追加", arg)
|
||||||
|
|
||||||
m.Option("scan_mode", "scan")
|
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]))
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,25 @@ import (
|
|||||||
"github.com/shylinux/icebergs"
|
"github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/core/code"
|
"github.com/shylinux/icebergs/core/code"
|
||||||
"github.com/shylinux/toolkits"
|
"github.com/shylinux/toolkits"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
"strings"
|
"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: "虚拟机",
|
var Index = &ice.Context{Name: "docker", Help: "虚拟机",
|
||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
@ -14,11 +30,11 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机",
|
|||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
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 {
|
// 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, "镜像源", `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 bash`)
|
||||||
m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "软件包", `apk add curl`)
|
// 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) {}},
|
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"}
|
prefix := []string{ice.CLI_SYSTEM, "docker", "container"}
|
||||||
m.Cmdy(prefix, "exec", arg[0], arg[1:]).Set("append")
|
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
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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"))},
|
"total": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true"))},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
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()
|
wd, _ := os.Getwd()
|
||||||
add(m, path.Base(wd), wd)
|
add(m, path.Base(wd), wd)
|
||||||
@ -45,7 +45,6 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
|
|||||||
add(m, value["name"], value["path"])
|
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(
|
"repos": {Name: "repos [name [path [remote [branch]]]]", Help: "仓库", List: kit.List(
|
||||||
kit.MDB_INPUT, "text", "name", "name", "action", "auto",
|
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",
|
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
|
||||||
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) > 1 {
|
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),
|
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])
|
kit.Select(m.Conf("repos", "meta.owner")+"/"+arg[0], arg, 2), arg[1])
|
||||||
|
@ -25,7 +25,6 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
|||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Load()
|
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) {
|
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Save("input")
|
m.Save("input")
|
||||||
|
@ -52,14 +52,10 @@ var Index = &ice.Context{Name: "tmux", Help: "命令行",
|
|||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {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) {
|
||||||
m.Watch(ice.SYSTEM_INIT, "web.code.tmux.init")
|
|
||||||
m.Watch(ice.DREAM_START, "web.code.tmux.auto")
|
m.Watch(ice.DREAM_START, "web.code.tmux.auto")
|
||||||
m.Watch(ice.FAVOR_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"} {
|
for _, v := range []string{"auto.sh", "auto.vim"} {
|
||||||
p := path.Join(m.Conf("web.code.publish", "meta.path"), v)
|
p := path.Join(m.Conf("web.code.publish", "meta.path"), v)
|
||||||
if _, e := os.Stat(p); e != nil && os.IsNotExist(e) {
|
if _, e := os.Stat(p); e != nil && os.IsNotExist(e) {
|
||||||
|
40
template.sh
40
template.sh
@ -4,6 +4,7 @@ ice_sh="bin/ice.sh"
|
|||||||
ice_bin="bin/ice.bin"
|
ice_bin="bin/ice.bin"
|
||||||
ice_mod="${PWD##**/}"
|
ice_mod="${PWD##**/}"
|
||||||
init_shy="etc/init.shy"
|
init_shy="etc/init.shy"
|
||||||
|
local_shy="etc/local.shy"
|
||||||
exit_shy="etc/exit.shy"
|
exit_shy="etc/exit.shy"
|
||||||
main_go="src/main.go"
|
main_go="src/main.go"
|
||||||
readme="README.md"
|
readme="README.md"
|
||||||
@ -42,6 +43,16 @@ END
|
|||||||
|
|
||||||
[ -d etc ] || mkdir etc
|
[ -d etc ] || mkdir etc
|
||||||
[ -f ${init_shy} ] || cat >> ${init_shy} <<END
|
[ -f ${init_shy} ] || cat >> ${init_shy} <<END
|
||||||
|
~web
|
||||||
|
|
||||||
|
# web.code.tmux.init
|
||||||
|
# web.code.git.init
|
||||||
|
|
||||||
|
~ssh
|
||||||
|
source etc/local.shy
|
||||||
|
END
|
||||||
|
[ -f ${local_shy} ] || cat >> ${local_shy} <<END
|
||||||
|
~web
|
||||||
END
|
END
|
||||||
[ -f ${exit_shy} ] || cat >> "${exit_shy}" <<END
|
[ -f ${exit_shy} ] || cat >> "${exit_shy}" <<END
|
||||||
END
|
END
|
||||||
@ -50,9 +61,10 @@ END
|
|||||||
[ -f ${ice_sh} ] || cat >> ${ice_sh} <<END
|
[ -f ${ice_sh} ] || cat >> ${ice_sh} <<END
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
export PATH=\${PWD}:\${PWD}/bin:\$PATH
|
export PATH=\${PWD}/bin:\${PWD}:\$PATH
|
||||||
export ctx_pid=\${ctx_pid:=var/run/ice.pid}
|
export ctx_pid=\${ctx_pid:=var/run/ice.pid}
|
||||||
export ctx_log=\${ctx_log:=bin/boot.log}
|
export ctx_log=\${ctx_log:=bin/boot.log}
|
||||||
|
export ctx_mod=\${ctx_mod:="ssh ctx log gdb"}
|
||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
[ -d bin ] || mkdir bin
|
[ -d bin ] || mkdir bin
|
||||||
@ -77,15 +89,15 @@ start() {
|
|||||||
date && ice.bin \$@ 2>\$ctx_log && echo -e "\n\nrestarting..." || break
|
date && ice.bin \$@ 2>\$ctx_log && echo -e "\n\nrestarting..." || break
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
serve() {
|
|
||||||
prepare && shutdown && start \$@
|
|
||||||
}
|
|
||||||
restart() {
|
restart() {
|
||||||
[ -e \$ctx_pid ] && kill -2 \`cat \$ctx_pid\` || echo
|
[ -e \$ctx_pid ] && kill -2 \`cat \$ctx_pid\` || echo
|
||||||
}
|
}
|
||||||
shutdown() {
|
shutdown() {
|
||||||
[ -e \$ctx_pid ] && kill -3 \`cat \$ctx_pid\` || echo
|
[ -e \$ctx_pid ] && kill -3 \`cat \$ctx_pid\` || echo
|
||||||
}
|
}
|
||||||
|
serve() {
|
||||||
|
prepare && shutdown && start \$@
|
||||||
|
}
|
||||||
|
|
||||||
cmd=\$1 && [ -n "\$cmd" ] && shift || cmd=serve
|
cmd=\$1 && [ -n "\$cmd" ] && shift || cmd=serve
|
||||||
\$cmd \$*
|
\$cmd \$*
|
||||||
@ -97,14 +109,24 @@ build() {
|
|||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
export GOPRIVATE=github.com
|
export GOPRIVATE=github.com
|
||||||
export GOPROXY=https://goproxy.cn
|
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
|
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() {
|
tutor() {
|
||||||
[ -d $1 ] || mkdir $1
|
[ -d $1 ] || mkdir $1
|
||||||
|
|
||||||
|
[ -f "$1/$1.js" ] || cat >> "$1/$1.js" <<END
|
||||||
|
Volcanos("onimport", {help: "导入数据", list: [],
|
||||||
|
"init": function(can, msg, cb, output, action, option) {},
|
||||||
|
})
|
||||||
|
Volcanos("onaction", {help: "控件菜单", list: []})
|
||||||
|
Volcanos("onchoice", {help: "控件交互", list: ["刷新"]
|
||||||
|
"刷新": function(event, can, value, cmd, target) {},
|
||||||
|
})
|
||||||
|
Volcanos("ondetail", {help: "控件详情", list: []})
|
||||||
|
Volcanos("onexport", {help: "导出数据", list: []})
|
||||||
|
END
|
||||||
[ -f "$1/$1.shy" ] || cat >> "$1/$1.shy" <<END
|
[ -f "$1/$1.shy" ] || cat >> "$1/$1.shy" <<END
|
||||||
title "$1"
|
title "$1"
|
||||||
END
|
END
|
||||||
@ -113,7 +135,7 @@ package $1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shylinux/icebergs"
|
"github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/core/wiki"
|
||||||
"github.com/shylinux/toolkits"
|
"github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -132,10 +154,10 @@ var Index = &ice.Context{Name: "$1", Help: "$1",
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { web.Index.Register(Index, nil) }
|
func init() { wiki.Index.Register(Index, nil) }
|
||||||
|
|
||||||
END
|
END
|
||||||
ls $1
|
ls -l $1
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd=build && [ "$1" != "" ] && cmd=$1 && shift
|
cmd=build && [ "$1" != "" ] && cmd=$1 && shift
|
||||||
|
4
type.go
4
type.go
@ -143,7 +143,9 @@ func (c *Context) Start(m *Message, arg ...string) bool {
|
|||||||
wait <- true
|
wait <- true
|
||||||
|
|
||||||
// 启动模块
|
// 启动模块
|
||||||
|
if c.server != nil {
|
||||||
c.server.Start(m, arg...)
|
c.server.Start(m, arg...)
|
||||||
|
}
|
||||||
if m.Done(); m.wait != nil {
|
if m.Done(); m.wait != nil {
|
||||||
m.wait <- true
|
m.wait <- true
|
||||||
}
|
}
|
||||||
@ -791,10 +793,12 @@ func (m *Message) Log(level string, str string, arg ...interface{}) *Message {
|
|||||||
prefix, suffix = "\033[31m", "\033[0m"
|
prefix, suffix = "\033[31m", "\033[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if os.Getenv("ctx_mod") != "" {
|
||||||
// 输出日志
|
// 输出日志
|
||||||
fmt.Fprintf(os.Stderr, "%s %02d %9s %s%s %s%s\n",
|
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),
|
m.time.Format(ICE_TIME), m.code, fmt.Sprintf("%s->%s", m.source.Name, m.target.Name),
|
||||||
prefix, level, str, suffix)
|
prefix, level, str, suffix)
|
||||||
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Cost(str string, arg ...interface{}) *Message {
|
func (m *Message) Cost(str string, arg ...interface{}) *Message {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user