forked from x/icebergs
opt some
This commit is contained in:
parent
01f43866c7
commit
00aea9d1c9
@ -96,8 +96,9 @@ func UserRoot(m *ice.Message, arg ...string) *ice.Message {
|
||||
username := kit.Select(ice.Info.Username, arg, 0)
|
||||
usernick := kit.Select(UserNick(m, username), arg, 1)
|
||||
userrole := kit.Select(ROOT, arg, 2)
|
||||
userzone := kit.Select("", arg, 3)
|
||||
if len(arg) > 0 {
|
||||
m.Cmd(USER, mdb.CREATE, username, "", usernick, "", userrole)
|
||||
m.Cmd(USER, mdb.CREATE, username, "", usernick, userzone, userrole)
|
||||
ice.Info.Username = username
|
||||
}
|
||||
return SessAuth(m, kit.Dict(USERNAME, username, USERNICK, usernick, USERROLE, userrole))
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -79,13 +80,14 @@ func _qrcode_cli(m *ice.Message, text string) {
|
||||
}
|
||||
m.Echo(text).Echo(ice.NL)
|
||||
}
|
||||
func _qrcode_web(m *ice.Message, text string) {
|
||||
func _qrcode_web(m *ice.Message, text string) string {
|
||||
qr, _ := qrcode.New(text, qrcode.Medium)
|
||||
qr.ForegroundColor = _parse_color(m.Option(FG))
|
||||
qr.BackgroundColor = _parse_color(m.Option(BG))
|
||||
if data, err := qr.PNG(kit.Int(m.Option(SIZE))); m.Assert(err) {
|
||||
m.Echo(`<img src="data:image/png;base64,%s" title='%s'>`, base64.StdEncoding.EncodeToString(data), text)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
const (
|
||||
@ -133,8 +135,7 @@ func init() {
|
||||
_qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0))
|
||||
} else {
|
||||
m.Option(SIZE, kit.Select(kit.Format(kit.Max(240, kit.Min(480, kit.Int(m.Option(ice.MSG_HEIGHT)), kit.Int(m.Option(ice.MSG_WIDTH))))), arg, 3))
|
||||
_qrcode_web(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
||||
m.StatusTime(mdb.LINK, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
||||
m.StatusTime(mdb.LINK, _qrcode_web(m, tcp.PublishLocalhost(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))))
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
@ -19,6 +19,7 @@ func _runtime_init(m *ice.Message) {
|
||||
kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Make)), func(key string, value ice.Any) {
|
||||
m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(key)), value)
|
||||
})
|
||||
aaa.UserRoot(ice.Pulse, ice.Info.Make.Username, "", aaa.TECH, ice.DEV)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOARCH), runtime.GOARCH)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOOS), runtime.GOOS)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, OSID), release(m))
|
||||
@ -48,7 +49,7 @@ func _runtime_init(m *ice.Message) {
|
||||
ice.Info.Hostname = m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME))
|
||||
ice.Info.Pathname = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME))
|
||||
ice.Info.Username = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME))
|
||||
aaa.UserRoot(ice.Pulse, ice.Info.Username)
|
||||
aaa.UserRoot(ice.Pulse, ice.Info.Username, "", "", ice.OPS)
|
||||
msg := m.Cmd(nfs.DIR, _system_find(m, os.Args[0]), "time,path,size,hash")
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), msg.Append(nfs.PATH))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), msg.Append(nfs.SIZE))
|
||||
|
@ -104,7 +104,7 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di
|
||||
m.Push(mdb.HASH, kit.Select(h[:6], h[:], field == mdb.HASH))
|
||||
case mdb.LINK:
|
||||
if strings.Contains(p, "ice.windows.") {
|
||||
m.PushDownload(mdb.LINK, kit.Select("", f.Name(), !isDir)+".exe", p)
|
||||
m.PushDownload(mdb.LINK, "ice.exe", p)
|
||||
} else {
|
||||
m.PushDownload(mdb.LINK, kit.Select("", f.Name(), !isDir), p)
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -184,13 +183,23 @@ func init() {
|
||||
_serve_start(m)
|
||||
}},
|
||||
SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if domain := m.Cmdx(SPACE, DOMAIN); ice.Info.Colors && m.Option(ice.DEV) == "" {
|
||||
m.Sleep30ms().Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, "\r"+ice.Render(m, ice.RENDER_QRCODE, domain))).Cmd(ssh.PROMPT)
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case cli.WINDOWS:
|
||||
m.Cmd(cli.SYSTEM, "explorer.exe", "http://localhost:"+m.Option(tcp.PORT))
|
||||
}
|
||||
m.Go(func() {
|
||||
opened := false
|
||||
m.Sleep("1s").Cmd(SPACE, func(values ice.Maps) {
|
||||
if values[mdb.TYPE] == CHROME {
|
||||
opened = true
|
||||
}
|
||||
})
|
||||
if opened {
|
||||
return
|
||||
}
|
||||
switch host := "http://localhost:" + m.Option(tcp.PORT); runtime.GOOS {
|
||||
case cli.WINDOWS:
|
||||
m.Cmd(cli.SYSTEM, "explorer.exe", host)
|
||||
case cli.DARWIN:
|
||||
m.Cmd(cli.SYSTEM, "open", host)
|
||||
}
|
||||
})
|
||||
}},
|
||||
SERVE_REWRITE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] != http.MethodGet {
|
||||
|
@ -32,7 +32,7 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
m.Cmd(tcp.CLIENT, tcp.DIAL, args, func(c net.Conn) {
|
||||
if conn, _, e := websocket.NewClient(c, uri, nil, kit.Int(redial["r"]), kit.Int(redial["w"])); !m.Warn(e, tcp.DIAL, dev, SPACE, uri.String()) {
|
||||
defer mdb.HashCreateDeferRemove(m, kit.SimpleKV("", MASTER, dev, msg.Append(tcp.HOSTNAME)), kit.Dict(mdb.TARGET, conn))()
|
||||
if !prints {
|
||||
if !prints && ice.Info.Colors {
|
||||
m.Go(func() {
|
||||
m.Sleep30ms().Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, "\r"+ice.Render(m, ice.RENDER_QRCODE, m.CmdAppend(SPACE, dev, cli.PWD, mdb.LINK)))).Cmd(ssh.PROMPT)
|
||||
})
|
||||
@ -197,7 +197,14 @@ func init() {
|
||||
m.Cmd(SPACE, arg[0], ice.MSG_SESSID, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME)))
|
||||
}},
|
||||
DOMAIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_space_domain(m)) }},
|
||||
OPEN: {Hand: func(m *ice.Message, arg ...string) { ctx.ProcessOpen(m, MergePod(m, m.Option(mdb.NAME), arg)) }},
|
||||
OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case MASTER:
|
||||
ctx.ProcessOpen(m, m.Cmd(SPIDE, m.Option(mdb.NAME)).Append(CLIENT_ORIGIN))
|
||||
default:
|
||||
ctx.ProcessOpen(m, MergePod(m, m.Option(mdb.NAME), arg))
|
||||
}
|
||||
}},
|
||||
ice.PS: {Hand: func(m *ice.Message, arg ...string) { _space_fork(m) }},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text", ctx.ACTION, OPEN,
|
||||
REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000), TIMEOUT, kit.Dict("c", "10s"),
|
||||
|
1
conf.go
1
conf.go
@ -5,6 +5,7 @@ const (
|
||||
SP = " "
|
||||
DF = ":"
|
||||
EQ = "="
|
||||
QS = "?"
|
||||
AT = "@"
|
||||
PS = "/"
|
||||
PT = "."
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const FOOTER = "footer"
|
||||
@ -20,8 +21,8 @@ func init() {
|
||||
}
|
||||
}
|
||||
}},
|
||||
}, ctx.CmdAction(TITLE, `<a href="mailto:shylinuxc@gmail.com">shylinuxc@gmail.com</a>`), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Result(m.Configv(TITLE))
|
||||
}, ctx.CmdAction(), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Result(kit.Select(m.Config(TITLE), ice.Info.Make.Email))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func init() {
|
||||
m.Option(k, web.SHARE_LOCAL+k)
|
||||
}
|
||||
}
|
||||
m.Echo(m.Config(TITLE)).OptionFromConfig(MENUS)
|
||||
m.Echo(kit.Select(kit.Select("", strings.SplitN(ice.Info.Make.Remote, "://", 2), 1), m.Config(TITLE))).OptionFromConfig(MENUS)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func _autogen_version(m *ice.Message) {
|
||||
}
|
||||
m.Cmd(nfs.DEFS, ".gitignore", _git_ignore)
|
||||
m.Cmd(nfs.DEFS, ice.SRC_BINPACK_GO, `package main`+ice.NL)
|
||||
m.Cmd(nfs.SAVE, ice.SRC_VERSION_GO, kit.Format(_version_template, _autogen_gits(m, nfs.MODULE, _autogen_mod(m, ice.GO_MOD), tcp.HOSTNAME, ice.Info.Hostname, aaa.USERNAME, ice.Info.Username)))
|
||||
m.Cmd(nfs.SAVE, ice.SRC_VERSION_GO, kit.Format(_version_template, _autogen_gits(m, nfs.MODULE, _autogen_mod(m, ice.GO_MOD), tcp.HOSTNAME, ice.Info.Hostname)))
|
||||
m.Cmd(cli.SYSTEM, "gofmt", "-w", ice.SRC_VERSION_GO)
|
||||
m.Cmdy(nfs.DIR, ice.SRC_BINPACK_GO)
|
||||
m.Cmdy(nfs.DIR, ice.SRC_VERSION_GO)
|
||||
@ -77,7 +77,9 @@ func _autogen_git(m *ice.Message, arg ...string) ice.Map {
|
||||
nfs.REMOTE, m.Cmdx(cli.SYSTEM, GIT, "config", "remote.origin.url"),
|
||||
nfs.BRANCH, m.Cmdx(cli.SYSTEM, GIT, "rev-parse", "--abbrev-ref", "HEAD"),
|
||||
nfs.VERSION, m.Cmdx(cli.SYSTEM, GIT, "describe", "--tags"),
|
||||
web.DOMAIN, tcp.PublishLocalhost(m, kit.Split(m.Option(ice.MSG_USERWEB), "?")[0]),
|
||||
aaa.EMAIL, m.Cmdx(cli.SYSTEM, GIT, "config", "user.email"),
|
||||
aaa.USERNAME, kit.Select(ice.Info.Username, m.Cmdx(cli.SYSTEM, GIT, "config", "user.name")),
|
||||
web.DOMAIN, tcp.PublishLocalhost(m, kit.Split(m.Option(ice.MSG_USERWEB), ice.QS)[0]),
|
||||
)
|
||||
}
|
||||
func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
|
@ -62,7 +62,7 @@ func _publish_contexts(m *ice.Message, arg ...string) {
|
||||
for _, k := range kit.Default(arg, ice.MISC) {
|
||||
switch k {
|
||||
case INSTALL:
|
||||
m.Echo(kit.Renders(`export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; ctx_temp=$(mktemp); wget -O $ctx_temp -q $ctx_dev; source $ctx_temp app username {{.Option "user.name"}} usernick {{.Option "user.nick"}}`, m))
|
||||
m.Echo(kit.Renders(strings.TrimSpace(m.Config(kit.Keys(ice.CONTEXTS, ice.MISC))), m))
|
||||
return
|
||||
case ice.MISC:
|
||||
_publish_file(m, ice.ICE_BIN)
|
||||
@ -118,27 +118,12 @@ func init() {
|
||||
|
||||
var _contexts = kit.Dict(
|
||||
ice.MISC, `
|
||||
# 下载应用 wget Alpine / Busybox
|
||||
export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; temp=$(mktemp); wget -O $temp -q $ctx_dev; source $temp app username {{.Option "user.name"}} usernick {{.Option "user.nick"}}
|
||||
|
||||
# 下载应用 curl Centos / MacOS
|
||||
export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; temp=$(mktemp); curl -o $temp -fsSL $ctx_dev; source $temp app username {{.Option "user.name"}} usernick {{.Option "user.nick"}}
|
||||
export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi; source $temp app username {{.Option "user.name"}} usernick {{.Option "user.nick"}}
|
||||
`,
|
||||
ice.CORE, `
|
||||
# 下载命令 wget Busybox
|
||||
temp=$(mktemp); wget -O $temp -q http://contexts.com.cn; source $temp binary
|
||||
|
||||
# 下载命令 wget Alpine
|
||||
temp=$(mktemp); wget -O $temp -q {{.Option "domain"}}; source $temp binary
|
||||
|
||||
# 下载命令 curl Centos / MacOS
|
||||
temp=$(mktemp); curl -o $temp -fsSL {{.Option "domain"}}; source $temp binary
|
||||
temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL {{.Option "domain"}}; else wget -O $temp -q {{.Option "domain"}}; fi; source $temp binary
|
||||
`,
|
||||
ice.BASE, `
|
||||
# 下载源码 wget Alpine
|
||||
temp=$(mktemp); wget -O $temp -q {{.Option "domain"}}; source $temp source
|
||||
|
||||
# 下载源码 curl Centos / MacOS
|
||||
temp=$(mktemp); curl -o $temp -fsSL {{.Option "domain"}}; source $temp source
|
||||
temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL {{.Option "domain"}}; else wget -O $temp -q {{.Option "domain"}}; fi; source $temp source
|
||||
`,
|
||||
)
|
||||
|
1
info.go
1
info.go
@ -11,6 +11,7 @@ type MakeInfo struct {
|
||||
Version string
|
||||
Hostname string
|
||||
Username string
|
||||
Email string
|
||||
}
|
||||
|
||||
var Info = struct {
|
||||
|
5
init.go
5
init.go
@ -93,9 +93,7 @@ func Run(arg ...string) string {
|
||||
arg = kit.Simple(os.Args[1:], kit.Split(kit.Env(CTX_ARG)))
|
||||
}
|
||||
if len(arg) == 0 && runtime.GOOS == "windows" {
|
||||
arg = append(arg, SERVE, START, DEV, SHY)
|
||||
logs.Disable(true)
|
||||
os.Stderr.Close()
|
||||
arg = append(arg, SERVE, START, DEV, DEV)
|
||||
}
|
||||
Pulse.meta[MSG_DETAIL] = arg
|
||||
kit.Fetch(kit.Sort(os.Environ()), func(env string) {
|
||||
@ -110,6 +108,7 @@ func Run(arg ...string) string {
|
||||
case SERVE, SPACE:
|
||||
if os.Getenv("ctx_log") == "" {
|
||||
logs.Disable(true)
|
||||
os.Stderr.Close()
|
||||
}
|
||||
if Index.Start(Pulse, arg...) {
|
||||
conf.Wait()
|
||||
|
Loading…
x
Reference in New Issue
Block a user