forked from x/icebergs
add mirror
This commit is contained in:
parent
1976d83a49
commit
1ba3a0fa62
@ -6,4 +6,4 @@ const CLI = "cli"
|
|||||||
|
|
||||||
var Index = &ice.Context{Name: CLI, Help: "命令模块"}
|
var Index = &ice.Context{Name: CLI, Help: "命令模块"}
|
||||||
|
|
||||||
func init() { ice.Index.Register(Index, nil, RUNTIME, QRCODE, SYSTEM, DAEMON, FOREVER) }
|
func init() { ice.Index.Register(Index, nil, RUNTIME, QRCODE, MIRROR, SYSTEM, DAEMON, FOREVER) }
|
||||||
|
57
base/cli/mirrors.go
Normal file
57
base/cli/mirrors.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ice "shylinux.com/x/icebergs"
|
||||||
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
|
kit "shylinux.com/x/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func IsAlpine(m *ice.Message, arg ...string) bool {
|
||||||
|
if strings.Contains(m.Conf(RUNTIME, "host.OSID"), ALPINE) {
|
||||||
|
if len(arg) > 0 {
|
||||||
|
m.Cmd(MIRROR, mdb.CREATE, "cli", arg[0], "cmd", arg[1])
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
OSID = "OSID"
|
||||||
|
ALPINE = "alpine"
|
||||||
|
CENTOS = "centos"
|
||||||
|
UBUNTU = "ubuntu"
|
||||||
|
)
|
||||||
|
|
||||||
|
const MIRROR = "mirror"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
|
MIRROR: {Name: "mirror cli auto", Help: "软件镜像", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Go(func() {
|
||||||
|
m.Sleep("1s")
|
||||||
|
IsAlpine(m, "curl", "system apk add curl")
|
||||||
|
IsAlpine(m, "make", "system apk add make")
|
||||||
|
IsAlpine(m, "gcc", "system apk add gcc")
|
||||||
|
IsAlpine(m, "vim", "system apk add vim")
|
||||||
|
IsAlpine(m, "tmux", "system apk add tmux")
|
||||||
|
|
||||||
|
if IsAlpine(m, "git", "system apk add git"); !IsAlpine(m, "go", "system apk add git go") {
|
||||||
|
m.Cmd(MIRROR, mdb.CREATE, kit.SimpleKV("cli,cmd", "go", "install download https://golang.google.cn/dl/go1.15.5.linux-amd64.tar.gz usr/local"))
|
||||||
|
}
|
||||||
|
|
||||||
|
IsAlpine(m, "node", "system apk add nodejs")
|
||||||
|
IsAlpine(m, "java", "system apk add openjdk8")
|
||||||
|
IsAlpine(m, "javac", "system apk add openjdk8")
|
||||||
|
IsAlpine(m, "python", "system apk add python2")
|
||||||
|
IsAlpine(m, "python2", "system apk add python2")
|
||||||
|
IsAlpine(m, "python3", "system apk add python3")
|
||||||
|
})
|
||||||
|
}},
|
||||||
|
mdb.CREATE: {Name: "create cli cmd", Help: "创建"},
|
||||||
|
}, mdb.HashAction(mdb.SHORT, "cli", mdb.FIELD, "time,cli,cmd"))},
|
||||||
|
}})
|
||||||
|
}
|
@ -112,11 +112,6 @@ const (
|
|||||||
LINUX = "linux"
|
LINUX = "linux"
|
||||||
DARWIN = "darwin"
|
DARWIN = "darwin"
|
||||||
WINDOWS = "windows"
|
WINDOWS = "windows"
|
||||||
|
|
||||||
OSID = "OSID"
|
|
||||||
ALPINE = "alpine"
|
|
||||||
CENTOS = "centos"
|
|
||||||
UBUNTU = "ubuntu"
|
|
||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
SHELL = "SHELL"
|
SHELL = "SHELL"
|
||||||
|
@ -15,6 +15,34 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||||
|
// 定制目录
|
||||||
|
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
|
||||||
|
if file := _system_find(m, arg[0], strings.Split(text, ice.NL)...); file != "" {
|
||||||
|
m.Debug("cmd: %v", file)
|
||||||
|
arg[0] = file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 环境变量
|
||||||
|
env := kit.Simple(m.Optionv(CMD_ENV))
|
||||||
|
for i := 0; i < len(env)-1; i += 2 {
|
||||||
|
if env[i] == PATH {
|
||||||
|
if file := _system_find(m, arg[0], strings.Split(env[i+1], ice.DF)...); file != "" {
|
||||||
|
m.Debug("cmd: %v", file)
|
||||||
|
arg[0] = file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 自动安装
|
||||||
|
if _system_find(m, arg[0]) == "" {
|
||||||
|
if cmds := m.Cmd(MIRROR, arg[0]).Append("cmd"); cmds != "" {
|
||||||
|
m.Cmd(kit.Split(cmds))
|
||||||
|
if file := _system_find(m, arg[0]); file != "" {
|
||||||
|
m.Debug("cmd: %v", file)
|
||||||
|
arg[0] = file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command(arg[0], arg[1:]...)
|
cmd := exec.Command(arg[0], arg[1:]...)
|
||||||
|
|
||||||
// 运行目录
|
// 运行目录
|
||||||
@ -23,29 +51,10 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
|||||||
nfs.MkdirAll(m, cmd.Dir)
|
nfs.MkdirAll(m, cmd.Dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 环境变量
|
// 环境变量
|
||||||
env := kit.Simple(m.Optionv(CMD_ENV))
|
|
||||||
for i := 0; i < len(env)-1; i += 2 {
|
for i := 0; i < len(env)-1; i += 2 {
|
||||||
if cmd.Env = append(cmd.Env, kit.Format("%s=%s", env[i], env[i+1])); env[i] == PATH {
|
cmd.Env = append(cmd.Env, kit.Format("%s=%s", env[i], env[i+1]))
|
||||||
if file := _system_find(m, arg[0], strings.Split(env[i+1], ice.DF)...); file != "" {
|
|
||||||
m.Debug("cmd: %v", file)
|
|
||||||
cmd.Path = file
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定制目录
|
|
||||||
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
|
|
||||||
if file := _system_find(m, arg[0], strings.Split(text, ice.NL)...); file != "" {
|
|
||||||
m.Debug("cmd: %v", file)
|
|
||||||
cmd.Path = file
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _system_find(m, cmd.Path) == "" {
|
|
||||||
}
|
|
||||||
m.Debug("cmd: %v", cmd.Path)
|
|
||||||
|
|
||||||
if len(cmd.Env) > 0 {
|
if len(cmd.Env) > 0 {
|
||||||
m.Log_EXPORT(CMD_ENV, cmd.Env)
|
m.Log_EXPORT(CMD_ENV, cmd.Env)
|
||||||
}
|
}
|
||||||
@ -157,7 +166,6 @@ func init() {
|
|||||||
if strings.HasSuffix(arg[0], ".sh") {
|
if strings.HasSuffix(arg[0], ".sh") {
|
||||||
arg = []string{"sh", path.Join("src", arg[0])}
|
arg = []string{"sh", path.Join("src", arg[0])}
|
||||||
}
|
}
|
||||||
m.Debug("arg %v", arg)
|
|
||||||
_system_exec(m, _system_cmd(m, arg...))
|
_system_exec(m, _system_cmd(m, arg...))
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
|
@ -2,14 +2,12 @@ package code
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/cli"
|
"shylinux.com/x/icebergs/base/cli"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
"shylinux.com/x/icebergs/base/tcp"
|
"shylinux.com/x/icebergs/base/tcp"
|
||||||
"shylinux.com/x/icebergs/base/web"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,10 +51,9 @@ func init() {
|
|||||||
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, `.*\.go$`)).Sort(nfs.PATH)
|
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, `.*\.go$`)).Sort(nfs.PATH)
|
||||||
}},
|
}},
|
||||||
INSTALL: {Name: "compile", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
INSTALL: {Name: "compile", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||||
if strings.Contains(m.Cmdx(cli.RUNTIME, kit.Keys(tcp.HOST, cli.OSID)), cli.ALPINE) {
|
if cli.IsAlpine(m) {
|
||||||
cli.PushStream(m)
|
cli.PushStream(m)
|
||||||
m.Cmd(cli.SYSTEM, "apk", "add", GIT, GO)
|
m.Cmd(cli.SYSTEM, "apk", "add", GIT, GO)
|
||||||
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m.Cmdx(cli.SYSTEM, nfs.FIND, GIT) == "" {
|
if m.Cmdx(cli.SYSTEM, nfs.FIND, GIT) == "" {
|
||||||
@ -64,7 +61,6 @@ func init() {
|
|||||||
m.Echo(ice.FALSE)
|
m.Echo(ice.FALSE)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.Cmd(INSTALL, web.DOWNLOAD, "https://golang.google.cn/dl/go1.15.5.linux-amd64.tar.gz", ice.USR_LOCAL)
|
|
||||||
}},
|
}},
|
||||||
BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(AUTOGEN, BINPACK)
|
m.Cmdy(AUTOGEN, BINPACK)
|
||||||
@ -73,10 +69,6 @@ func init() {
|
|||||||
m.Cmd(COMPILE, ice.SRC_RELAY_GO, path.Join(ice.USR_PUBLISH, RELAY))
|
m.Cmd(COMPILE, ice.SRC_RELAY_GO, path.Join(ice.USR_PUBLISH, RELAY))
|
||||||
}},
|
}},
|
||||||
}, 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 m.Cmdx(cli.SYSTEM, nfs.FIND, GO) == "" && m.Cmdx(COMPILE, INSTALL) == ice.FALSE {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 下载依赖
|
// 下载依赖
|
||||||
_autogen_version(m.Spawn())
|
_autogen_version(m.Spawn())
|
||||||
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
||||||
|
@ -57,9 +57,6 @@ func init() {
|
|||||||
m.ProcessCommand(kit.Select("can.code.inner.plugin", key), kit.Simple())
|
m.ProcessCommand(kit.Select("can.code.inner.plugin", key), kit.Simple())
|
||||||
}},
|
}},
|
||||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
if !InstallSoftware(m.Spawn(), NODE, m.Configv(INSTALL)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.Cmdy(cli.SYSTEM, NODE, "-e", kit.Join(_js_main_script(m, arg...), ice.NL)).SetAppend()
|
m.Cmdy(cli.SYSTEM, NODE, "-e", kit.Join(_js_main_script(m, arg...), ice.NL)).SetAppend()
|
||||||
m.Echo(ice.NL)
|
m.Echo(ice.NL)
|
||||||
}},
|
}},
|
||||||
|
@ -15,19 +15,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
PY: {Name: "py", Help: "脚本", Value: kit.Data(INSTALL, kit.List(kit.Dict(
|
|
||||||
cli.OSID, cli.ALPINE, ice.CMD, kit.List("apk", "add", PYTHON2),
|
|
||||||
)))},
|
|
||||||
}, Commands: map[string]*ice.Command{
|
|
||||||
PY: {Name: "py", Help: "脚本", Action: map[string]*ice.Action{
|
PY: {Name: "py", Help: "脚本", Action: map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(mdb.ENGINE, mdb.CREATE, PY, m.PrefixKey())
|
m.Cmd(mdb.ENGINE, mdb.CREATE, PY, m.PrefixKey())
|
||||||
}},
|
}},
|
||||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
if !InstallSoftware(m.Spawn(), PYTHON2, m.Configv(INSTALL)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if kit.FileExists(kit.Path(arg[2], arg[1])) {
|
if kit.FileExists(kit.Path(arg[2], arg[1])) {
|
||||||
m.Cmdy(cli.SYSTEM, PYTHON2, kit.Path(arg[2], arg[1]))
|
m.Cmdy(cli.SYSTEM, PYTHON2, kit.Path(arg[2], arg[1]))
|
||||||
} else if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && len(b) > 0 {
|
} else if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && len(b) > 0 {
|
||||||
|
1
go.sum
1
go.sum
@ -1,3 +1,4 @@
|
|||||||
|
shylinux.com/x/go-qrcode v0.0.1 h1:/eOGqMj1qtgs9Ymd12zTUa1gcJZs9S92kj2lb0QzKsE=
|
||||||
shylinux.com/x/go-qrcode v0.0.1/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po=
|
shylinux.com/x/go-qrcode v0.0.1/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po=
|
||||||
shylinux.com/x/toolkits v0.5.3 h1:DuMHEKiPbaoU+0PEw9CtZldaM8bLLaQ6Dx0Qaqfz3SY=
|
shylinux.com/x/toolkits v0.5.3 h1:DuMHEKiPbaoU+0PEw9CtZldaM8bLLaQ6Dx0Qaqfz3SY=
|
||||||
shylinux.com/x/toolkits v0.5.3/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
|
shylinux.com/x/toolkits v0.5.3/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
|
||||||
|
@ -33,4 +33,4 @@ var Index = &ice.Context{Name: GIT, Help: "代码库", Configs: map[string]*ice.
|
|||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
func init() { code.Index.Register(Index, &web.Frame{}, REPOS, GIT) }
|
func init() { code.Index.Register(Index, &web.Frame{}, REPOS) }
|
||||||
|
@ -59,6 +59,7 @@ func init() {
|
|||||||
m.Cmd(nfs.DIR, ice.USR, "name,path").Table(func(index int, value map[string]string, head []string) {
|
m.Cmd(nfs.DIR, ice.USR, "name,path").Table(func(index int, value map[string]string, head []string) {
|
||||||
_repos_insert(m, value[mdb.NAME], value[nfs.PATH])
|
_repos_insert(m, value[mdb.NAME], value[nfs.PATH])
|
||||||
})
|
})
|
||||||
|
cli.IsAlpine(m, "git", "apk add git")
|
||||||
}},
|
}},
|
||||||
mdb.CREATE: {Name: "create repos branch name path", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
mdb.CREATE: {Name: "create repos branch name path", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Option(mdb.NAME, kit.Select(strings.TrimSuffix(path.Base(m.Option(REPOS)), ".git"), m.Option(mdb.NAME)))
|
m.Option(mdb.NAME, kit.Select(strings.TrimSuffix(path.Base(m.Option(REPOS)), ".git"), m.Option(mdb.NAME)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user