mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt website
This commit is contained in:
parent
82e7ec5a13
commit
2d03bdbbef
@ -12,6 +12,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -31,6 +32,16 @@ func _runtime_init(m *ice.Message) {
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOOS), runtime.GOOS)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, "pid"), os.Getpid())
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, HOME), os.Getenv(HOME))
|
||||
osid := ""
|
||||
m.Cmd(nfs.CAT, "/etc/os-release", func(text string) {
|
||||
if ls := kit.Split(text, "="); len(ls) > 1 {
|
||||
switch ls[0] {
|
||||
case "ID", "ID_LIKE":
|
||||
osid = strings.TrimSpace(osid + ice.SP + ls[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, OSID), osid)
|
||||
|
||||
// 启动信息 boot
|
||||
if name, e := os.Hostname(); e == nil {
|
||||
@ -112,6 +123,11 @@ const (
|
||||
LINUX = "linux"
|
||||
DARWIN = "darwin"
|
||||
WINDOWS = "windows"
|
||||
|
||||
OSID = "OSID"
|
||||
CENTOS = "centos"
|
||||
UBUNTU = "ubuntu"
|
||||
ALPINE = "alpine"
|
||||
)
|
||||
const (
|
||||
USER = "USER"
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -30,12 +31,12 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
for i := 0; i < len(env)-1; i += 2 {
|
||||
cmd.Env = append(cmd.Env, kit.Format("%s=%s", env[i], env[i+1]))
|
||||
if env[i] == PATH {
|
||||
for _, p := range strings.Split(env[i+1], ice.DF) {
|
||||
if _, err := os.Stat(path.Join(p, arg[0])); err == nil {
|
||||
cmd.Path = path.Join(p, arg[0])
|
||||
m.Debug("what %v", cmd.Path)
|
||||
break
|
||||
}
|
||||
// if strings.Contains(m.Cmdx(RUNTIME, "host.OSID"), ALPINE) {
|
||||
// continue
|
||||
// }
|
||||
if file := _system_find(m, arg[0], strings.Split(env[i+1], ice.DF)...); file != "" {
|
||||
cmd.Path = file
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,6 +70,17 @@ func _system_out(m *ice.Message, out string) io.Writer {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func _system_find(m *ice.Message, bin string, dir ...string) string {
|
||||
if len(dir) == 0 {
|
||||
dir = append(dir, strings.Split(os.Getenv(PATH), ice.DF)...)
|
||||
}
|
||||
for _, p := range dir {
|
||||
if _, err := os.Stat(path.Join(p, bin)); err == nil {
|
||||
return path.Join(p, bin)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
// 输入流
|
||||
if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok {
|
||||
@ -122,7 +134,11 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
SYSTEM: {Name: SYSTEM, Help: "系统命令", Value: kit.Data(mdb.FIELD, "time,id,cmd")},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
SYSTEM: {Name: "system cmd run:button", Help: "系统命令", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
SYSTEM: {Name: "system cmd run:button", Help: "系统命令", Action: map[string]*ice.Action{
|
||||
nfs.FIND: {Name: "find", Help: "查找", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_system_find(m, arg[0], arg[1:]...))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
mdb.ListSelect(m, arg...)
|
||||
return
|
||||
|
@ -159,7 +159,7 @@ func init() {
|
||||
m.Option(TRANS, kit.Format(kit.Value(c.Commands[cmd].Meta, "_trans")))
|
||||
m.Option(MENUS, m.Config(MENUS))
|
||||
m.Echo(m.Config(TITLE))
|
||||
m.Cmdy(WEBSITE)
|
||||
// m.Cmdy(WEBSITE)
|
||||
}},
|
||||
HEADER: {Name: "header", Help: "标题栏", Action: map[string]*ice.Action{
|
||||
GRANT: {Name: "grant space", Help: "授权", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -100,8 +100,8 @@ func init() {
|
||||
}, Commands: map[string]*ice.Command{
|
||||
WEBSITE: {Name: "website path auto create import", Help: "网站", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, "txt", m.PrefixKey())
|
||||
m.Cmd(mdb.ENGINE, mdb.CREATE, "txt", m.PrefixKey())
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, nfs.TXT, m.PrefixKey())
|
||||
m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.TXT, m.PrefixKey())
|
||||
|
||||
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
|
||||
if ok := true; m.Richs(WEBSITE, nil, r.URL.Path, func(key string, value map[string]interface{}) {
|
||||
@ -162,7 +162,7 @@ func init() {
|
||||
nfs.PATH, ice.PS+strings.TrimPrefix(p, SRC_WEBSITE),
|
||||
mdb.TYPE, kit.Ext(p), mdb.NAME, path.Base(p), mdb.TEXT, m.Cmdx(nfs.CAT, p),
|
||||
), kit.Split(m.Config(mdb.FIELD))).PushButton("")
|
||||
m.PushAnchor(m.MergeLink(path.Join(CHAT_WEBSITE, p)))
|
||||
m.PushAnchor(m.MergeLink(path.Join(CHAT_WEBSITE, strings.TrimPrefix(p, SRC_WEBSITE))))
|
||||
}).Sort(nfs.PATH)
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,9 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, m.Config(nfs.PATH))
|
||||
return
|
||||
}
|
||||
if m.Cmdx(cli.SYSTEM, nfs.FIND, "go") == "" {
|
||||
m.Cmd(INSTALL, COMPILE)
|
||||
}
|
||||
|
||||
// 交叉编译
|
||||
main, file := ice.SRC_MAIN_GO, ""
|
||||
|
@ -155,7 +155,7 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
INSTALL: {Name: INSTALL, Help: "安装", Value: kit.Data(mdb.SHORT, mdb.NAME, nfs.PATH, ice.USR_INSTALL)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
INSTALL: {Name: "install name port path auto download", Help: "安装", Meta: kit.Dict(), Action: map[string]*ice.Action{
|
||||
INSTALL: {Name: "install name port path auto download compile", Help: "安装", Meta: kit.Dict(), Action: map[string]*ice.Action{
|
||||
web.DOWNLOAD: {Name: "download link path", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_download(m)
|
||||
}},
|
||||
@ -176,6 +176,21 @@ func init() {
|
||||
defer m.StatusTime(nfs.PATH, m.Option(nfs.DIR_ROOT))
|
||||
m.Cmdy(nfs.DIR, m.Option(nfs.PATH))
|
||||
}},
|
||||
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")
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch len(arg) {
|
||||
case 0: // 源码列表
|
||||
|
Loading…
x
Reference in New Issue
Block a user