diff --git a/base/aaa/user.go b/base/aaa/user.go index fb8c8bca..05c3f8b9 100644 --- a/base/aaa/user.go +++ b/base/aaa/user.go @@ -45,13 +45,10 @@ func _user_search(m *ice.Message, name, text string) { func UserRoot(m *ice.Message, arg ...string) { // password username userrole userrole := kit.Select(ROOT, arg, 2) - username := kit.Select(kit.Select("shy", ice.Info.UserName), arg, 1) + username := kit.Select(kit.Select("root", ice.Info.UserName), arg, 1) m.Option(ice.MSG_USERROLE, userrole) m.Option(ice.MSG_USERNAME, username) - - if !_user_exists(m, username) { - _user_create(m, userrole, username, kit.Select("", arg, 0)) - } + _user_create(m, userrole, username, kit.Select("", arg, 0)) } func UserRole(m *ice.Message, username interface{}) (role string) { if role = VOID; username == ice.Info.UserName { diff --git a/base/cli/cli.go b/base/cli/cli.go index 2d9855af..1230c1de 100644 --- a/base/cli/cli.go +++ b/base/cli/cli.go @@ -6,4 +6,4 @@ const CLI = "cli" var Index = &ice.Context{Name: CLI, Help: "命令模块"} -func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE) } +func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE, FOREVER) } diff --git a/base/cli/forever.go b/base/cli/forever.go new file mode 100644 index 00000000..9884d6cb --- /dev/null +++ b/base/cli/forever.go @@ -0,0 +1,39 @@ +package cli + +import ( + "os" + + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/aaa" + "shylinux.com/x/icebergs/base/nfs" + kit "shylinux.com/x/toolkits" +) + +const FOREVER = "forever" + +func init() { + const SERVE = "serve" + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + FOREVER: {Name: "forever", Help: "启动", Action: map[string]*ice.Action{ + SERVE: {Name: "serve", Help: "服务", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(FOREVER, os.Args[0], SERVE, START, ice.DEV, "", aaa.USERNAME, aaa.ROOT, aaa.PASSWORD, aaa.ROOT, arg) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + for { + if arg[1] == SERVE { + if _, e := os.Stat(ice.BIN_ICE_BIN); e == nil { + arg[0] = nfs.PWD + ice.BIN_ICE_BIN + } + } + println(kit.Format("%s run %s", kit.Now(), kit.Join(arg, ice.SP))) + switch msg := m.Cmd(SYSTEM, arg); msg.Append(CODE) { + case "0": + println(kit.Format("%s exit", kit.Now())) + return + default: + m.Sleep("1s") + } + } + }}}, + }) +} diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 810eccac..6baa7c10 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -37,7 +37,7 @@ func _runtime_init(m *ice.Message) { if ls := kit.Split(text, "="); len(ls) > 1 { switch ls[0] { case "ID", "ID_LIKE": - osid = strings.TrimSpace(osid + ice.SP + ls[1]) + osid = strings.TrimSpace(ls[1] + ice.SP + osid) } } }) diff --git a/base/web/serve.go b/base/web/serve.go index 6a58c14a..bb89e99e 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -180,7 +180,6 @@ func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWr if msg.Option(ice.MSG_USERNAME) == "" && msg.Config(tcp.LOCALHOST) == ice.TRUE && tcp.IsLocalHost(msg, msg.Option(ice.MSG_USERIP)) { aaa.UserRoot(msg) // 主机认证 - msg.Debug("what %v", msg.FormatMeta()) } if msg.Option(ice.MSG_USERNAME) == "" && msg.Option(SHARE) != "" { diff --git a/core/code/compile.go b/core/code/compile.go index 290f2454..2b8e5342 100644 --- a/core/code/compile.go +++ b/core/code/compile.go @@ -63,8 +63,6 @@ func init() { // 执行编译 _autogen_version(m.Spawn()) m.Optionv(cli.CMD_ENV, kit.Simple(m.Configv(cli.ENV), cli.HOME, os.Getenv(cli.HOME), cli.PATH, os.Getenv(cli.PATH), cli.GOOS, goos, cli.GOARCH, arch)) - m.Debug("what %v", os.Getenv(cli.PATH)) - m.Debug("what %v", m.FormatMeta()) if msg := m.Cmd(cli.SYSTEM, "go", "build", "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) { m.Copy(msg) return @@ -73,8 +71,12 @@ func init() { // 编译成功 m.Log_EXPORT(nfs.SOURCE, main, nfs.TARGET, file) m.Cmdy(nfs.DIR, file, "time,path,size,link,action") + name := path.Base(m.Append(nfs.PATH)) + m.EchoScript(kit.Format("# 下载启动\ncurl -fOL %s && chmod u+x %s\n./%s forever serve dev %s\ntail -f var/log/bench.log", + m.MergeURL2(kit.Format("/publish/%s", name)), name, name, m.MergeURL2(ice.PS))) m.Cmd(PUBLISH, mdb.CREATE, ice.BIN_ICE_SH) - m.Cmd(PUBLISH, ice.CONTEXTS, ice.CORE) + m.Cmdy(PUBLISH, ice.CONTEXTS, ice.CORE) + m.Cmdy(PUBLISH, ice.CONTEXTS, "binary") m.StatusTimeCount() }}, }}) diff --git a/core/code/install.go b/core/code/install.go index 285894a8..257bdc49 100644 --- a/core/code/install.go +++ b/core/code/install.go @@ -179,17 +179,15 @@ func init() { COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) { web.PushStream(m) defer m.ProcessHold() - defer m.ToastSuccess() osid := m.Cmdx(cli.RUNTIME, "host.OSID") switch { - case strings.Contains(osid, cli.CENTOS): - m.Cmd(cli.SYSTEM, "yum", "install", "-y", "git", "golang") - case strings.Contains(osid, cli.UBUNTU): - m.Cmd(cli.SYSTEM, "apt", "install", "-y", "git", "golang") case strings.Contains(osid, cli.ALPINE): m.Cmd(cli.SYSTEM, "apk", "add", "git", "go") + default: + m.Toast("please install git and go") } + m.ToastSuccess() }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch len(arg) { diff --git a/core/code/publish.go b/core/code/publish.go index 2e5668a5..f39fd3f3 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -102,7 +102,7 @@ echo "hello world" m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(u.Host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ":"), 1))) if len(arg) == 0 { - arg = append(arg, "misc", "core", "base", "project", "binary", "source") + arg = append(arg, "core", "binary") } for _, k := range arg { if buf, err := kit.Render(m.Config(kit.Keys(ice.CONTEXTS, k)), m); m.Assert(err) { @@ -159,20 +159,21 @@ echo "hello world" } var _contexts = kit.Dict( + "binary", `# 官方启动 +ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp binary +`, + "core", `# 脚本启动 +export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp app +`, + "source", `# 下载源码 ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp source -`, - "binary", `# 安装应用 -ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp binary `, "project", `# 创建项目 ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp project `, "base", `# 开发环境 export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp dev -`, - "core", `# 生产环境 -export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp app `, "misc", `# 终端环境 export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp diff --git a/misc/git/status.go b/misc/git/status.go index 75eac3d7..d8710b27 100644 --- a/misc/git/status.go +++ b/misc/git/status.go @@ -189,6 +189,7 @@ const ( COMMIT = "commit" COMMENT = "comment" VERSION = "version" + STASH = "stash" ) const STATUS = "status" @@ -227,6 +228,10 @@ func init() { _repos_cmd(m, m.Option(REPOS), TAG, m.Option(VERSION)) _repos_cmd(m, m.Option(REPOS), PUSH, "--tags") }}, + STASH: {Name: "stash", Help: "缓存", Hand: func(m *ice.Message, arg ...string) { + _status_each(m, STASH, cli.SYSTEM, GIT, STASH) + m.ProcessHold() + }}, ADD: {Name: "add", Help: "添加", Hand: func(m *ice.Message, arg ...string) { _repos_cmd(m, m.Option(REPOS), ADD, m.Option(nfs.FILE)) }}, OPT: {Name: "opt", Help: "优化"}, PRO: {Name: "pro", Help: "升级"},