1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

opt boot.sh

This commit is contained in:
shylinux 2019-06-16 10:40:53 +08:00
parent ad59a74939
commit 227b3475d1
12 changed files with 130 additions and 96 deletions

View File

@ -4,8 +4,8 @@ ctx_log=${ctx_log:="var/log"}
ctx_app=${ctx_app:="bench"}
ctx_bin=${ctx_app} && [ -f bin/${ctx_app} ] && ctx_bin=$(pwd)/bin/${ctx_app}
# ctx_box=
ctx_dev=${ctx_dev:="https://shylinux.com"}
# ctx_cas=
ctx_dev=${ctx_dev:="https://shylinux.com"}
ctx_root=${ctx_root:=/usr/local/context}
ctx_home=${ctx_home:=~/context}
# web_port=
@ -13,7 +13,8 @@ ctx_home=${ctx_home:=~/context}
# HOSTNAME=
# USER=
# PWD=
export ctx_log ctx_app ctx_bin ctx_dev ctx_root ctx_home
export ctx_log ctx_app ctx_bin ctx_box ctx_cas ctx_dev
export ctx_root ctx_home web_port ssh_port
log() {
echo -e $*
@ -30,8 +31,7 @@ install() {
esac
wget -O ${ctx_app} "$ctx_dev/publish/${ctx_app}?GOOS=$GOOS&GOARCH=$GOARCH" && chmod a+x ${ctx_app} \
&& ./${ctx_app} upgrade system \
&& ${md5} ${ctx_app} \
&& ./${ctx_app} upgrade system && ${md5} ${ctx_app} \
&& mv ${ctx_app} bin/${ctx_app}
}
main() {

View File

@ -1,9 +1,9 @@
~wiki
config save tmp/wiki.json wiki_visit
config save var/tmp/wiki.json wiki_visit
~ssh
config save tmp/cert.json work flow trust
config save var/tmp/cert.json work flow trust
~aaa
config save tmp/auth.json auth
config save var/tmp/auth.json auth
~cli
config save tmp/runtime.json runtime
config save var/tmp/runtime.json runtime

View File

@ -1,15 +1,13 @@
~cli
config load tmp/runtime.json runtime
config load var/tmp/runtime.json runtime
~aaa
config load tmp/auth.json auth
config load var/tmp/auth.json auth
~ssh
config load tmp/cert.json work flow trust
config load var/tmp/cert.json work flow trust
~wiki
config load tmp/wiki.json wiki_visit
config load var/tmp/wiki.json wiki_visit
source etc/common.shy
~ssh
remote auto
~cli
plugin sort.go sort
source local.shy

View File

@ -541,10 +541,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
switch arg[0] {
case "access": // 查看用户
h := m.Cmdx("aaa.auth", "access", kit.Hashs(m.Option("remote_ip"), m.Option("username")))
m.Cmd("aaa.auth", h, "data",
"remote_ip", m.Option("remote_ip"),
"username", m.Option("username"),
)
m.Cmd("aaa.auth", h, "data", "remote_ip", m.Option("remote_ip"), "username", m.Option("username"))
m.Echo(h)
return

View File

@ -502,7 +502,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"compile": &ctx.Command{Name: "compile [OS [ARCH]]", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) > 0 && arg[0] == "self" {
if m.Cmdy("cli.system", "go", "install", m.Cmdx("nfs.path", m.Conf("compile", "bench"))); m.Result(0) == "" {
m.Cmdy("cli.quit", 1)
m.Cmdy("cli.quit", 2)
}
return
}
@ -521,7 +521,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
if len(arg) > 0 {
goos := kit.Select(m.Conf("runtime", "host.GOOS"), arg, 0)
arch := kit.Select(m.Conf("runtime", "host.GOARCH"), arg, 1)
name := strings.Join([]string{"bench", goos, arch}, ".")
name := strings.Join([]string{"bench", goos, arch}, "_")
wd, _ := os.Getwd()
env := []string{"cmd_env", "GOOS", goos, "cmd_env", "GOARCH", arch, "cmd_env",
@ -593,9 +593,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Echo("term")
case "2":
if m.Option("cli.modal") != "action" {
m.Cmd("cli.source", m.Conf("system", "script.exit"))
m.Echo("restart")
}
}
m.Append("directory", "")
m.Echo(", wait 1s")
m.GoFunc(m, func(m *ctx.Message) {

View File

@ -40,13 +40,15 @@ func (ctx *CTX) Begin(m *Message, arg ...string) Server {
func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Cmd("ctx._init")
if m.Optionv("ps_target", Index); len(arg) == 0 {
Pulse.Option("log.disable", false)
m.Option("cli.modal", "active")
m.Option("log.disable", false)
m.Cap("stream", "shy")
m.Cmd("log._init")
m.Cmd("yac._init")
m.Cmd("gdb._init")
m.Cmd("cli.source", m.Conf("system", "script.init")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("system", "script.exit"))
} else {
m.Option("cli.modal", "action")
m.Cmd("yac._init")
for _, v := range m.Spawn().Cmd(arg).Meta["result"] {
fmt.Printf("%s", v)
@ -1416,6 +1418,7 @@ func Start(args ...string) bool {
kit.DisableLog = true
if len(args) > 0 && args[0] == "daemon" {
Pulse.Options("cli.modal", "daemon")
Pulse.Options("daemon", true)
args = args[1:]
}

View File

@ -149,6 +149,7 @@ var Index = &ctx.Context{Name: "gdb", Help: "调试中心",
// "11": "SEGV",
// "17": "STOP",
// "23": "IO",
// "29": "INFO",
"5": "TRAP",
"18": "TSTP",
@ -172,7 +173,6 @@ var Index = &ctx.Context{Name: "gdb", Help: "调试中心",
"25": "XFSZ",
"26": "VTALRM",
"27": "PROF",
"29": "INFO",
}, Help: "信号"},
"debug": &ctx.Config{Name: "debug", Value: map[string]interface{}{"value": map[string]interface{}{"enable": false},
"trace": map[string]interface{}{"value": map[string]interface{}{"enable": true}},

View File

@ -15,8 +15,8 @@ type LOG struct {
*ctx.Context
}
func (log *LOG) Value(msg *ctx.Message, arg ...interface{}) map[string]interface{} {
args := append(kit.Trans(arg...), "value")
func (log *LOG) Value(msg *ctx.Message, arg ...interface{}) []string {
args := append(kit.Trans(arg...))
if value, ok := kit.Chain(log.Configs["output"].Value, args).(map[string]interface{}); ok {
if kit.Right(value["source"]) && kit.Format(value["source"]) != msg.Source().Name {
@ -26,9 +26,7 @@ func (log *LOG) Value(msg *ctx.Message, arg ...interface{}) map[string]interface
if kit.Right(value["target"]) && kit.Format(value["target"]) != msg.Target().Name {
return nil
}
// kit.Log("error", "value %v %v", kit.Format(args), kit.Format(value))
return value
return kit.Trans(value["value"])
}
return nil
}
@ -61,10 +59,10 @@ func (log *LOG) Start(m *ctx.Message, arg ...string) bool {
kit.Log("error", "make log dir %s", m.Conf("logdir"))
log.queue = make(chan map[string]interface{}, 1024)
for _, v := range []string{"error", "bench", "debug"} {
log.Log(m, v, "hello world\n")
log.Log(m, v, "hello world")
}
// for _, v := range []string{"error", "bench", "debug"} {
// log.Log(m, v, "hello world\n")
// log.Log(m, v, "hello world")
// }
m.Cap("stream", m.Conf("output", []string{"bench", "value", "file"}))
for {
@ -77,10 +75,18 @@ func (log *LOG) Start(m *ctx.Message, arg ...string) bool {
loop:
for _, v := range []string{kit.Format(l["action"]), "bench"} {
for i := len(args); i >= 0; i-- {
if value := log.Value(m, append([]string{v}, args[:i]...)); kit.Right(value) && kit.Right(value["file"]) {
value := log.Value(msg, append([]string{v}, args[:i]...))
if !kit.Right(value) {
continue
}
p := kit.Chains(log.Configs["output"].Value, []string{"file", value[0]})
if p == "" {
continue
}
file, ok := os.Stdout, true
if kit.Format(value["file"]) != "stdout" {
name := path.Join(m.Conf("logdir"), kit.Format(value["file"]))
if p != "stdout" {
name := path.Join(m.Conf("logdir"), p)
file, ok = log.file[name]
if !ok {
if f, e := os.Create(name); e == nil {
@ -93,14 +99,17 @@ func (log *LOG) Start(m *ctx.Message, arg ...string) bool {
}
}
fmt.Fprintln(file, fmt.Sprintf("%d %s %s%s %s%s", m.Capi("nout", 1), msg.Format(value["meta"].([]interface{})...),
kit.Format(value["color_begin"]), kit.Format(l["action"]), fmt.Sprintf(kit.Format(l["str"]), l["arg"].([]interface{})...), kit.Format(value["color_end"])))
font := m.Conf("output", []string{"font", kit.Select("", value, 1)})
meta := msg.Format(m.Confv("output", []string{"meta", kit.Select("short", value, 2)}).([]interface{})...)
fmt.Fprintln(file, fmt.Sprintf("%d %s %s%s %s%s", m.Capi("nout", 1), meta, font,
kit.Format(l["action"]), fmt.Sprintf(kit.Format(l["str"]), l["arg"].([]interface{})...),
kit.Select("", "\033[0m", font != "")))
break loop
}
}
}
}
}
return false
}
func (log *LOG) Close(m *ctx.Message, arg ...string) bool {
@ -119,40 +128,53 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
Configs: map[string]*ctx.Config{
"logdir": &ctx.Config{Name: "logdir", Value: "var/log", Help: ""},
"output": &ctx.Config{Name: "output", Value: map[string]interface{}{
"error": map[string]interface{}{"value": map[string]interface{}{"file": "error.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"trace": map[string]interface{}{"value": map[string]interface{}{"file": "error.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[32m", "color_end": "\033[0m"}},
"debug": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}}},
"search": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}}},
"call": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}}},
"back": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}}},
"file": map[string]interface{}{
"bench": "bench.log",
"debug": "debug.log",
"error": "error.log",
"right": "right.log",
},
"font": map[string]interface{}{
"red": "\033[31m",
"green": "\033[32m",
"blue": "\033[34m",
"yellow": "\033[33m",
},
"meta": map[string]interface{}{
"short": []interface{}{"time", "ship"},
"long": []interface{}{"time", "ship"},
},
"sync": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}}},
"recv": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}}},
"send": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}}},
"error": map[string]interface{}{"value": []interface{}{"error", "red"}},
"trace": map[string]interface{}{"value": []interface{}{"error", "red"}},
"debug": map[string]interface{}{"value": []interface{}{"debug"}},
"search": map[string]interface{}{"value": []interface{}{"debug"}},
"call": map[string]interface{}{"value": []interface{}{"debug"}},
"back": map[string]interface{}{"value": []interface{}{"debug"}},
"send": map[string]interface{}{"value": []interface{}{"debug"}},
"bench": map[string]interface{}{"value": map[string]interface{}{"file": "bench.log", "meta": []interface{}{"time", "ship"}}},
"begin": map[string]interface{}{"value": map[string]interface{}{"file": "bench.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"start": map[string]interface{}{"value": map[string]interface{}{"file": "bench.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"close": map[string]interface{}{"value": map[string]interface{}{"file": "bench.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"warn": map[string]interface{}{"value": map[string]interface{}{"file": "bench.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[33m", "color_end": "\033[0m"}},
"bench": map[string]interface{}{"value": []interface{}{"bench"}},
"begin": map[string]interface{}{"value": []interface{}{"bench", "red"}},
"start": map[string]interface{}{"value": []interface{}{"bench", "red"}},
"close": map[string]interface{}{"value": []interface{}{"bench", "red"}},
"warn": map[string]interface{}{"value": []interface{}{"bench", "yellow"}},
"right": map[string]interface{}{"value": map[string]interface{}{"file": "right.log", "meta": []interface{}{"time", "ship"}}},
"cmd": map[string]interface{}{"value": map[string]interface{}{"file": "bench.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[32m", "color_end": "\033[0m"},
"lex": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[32m", "color_end": "\033[0m"}},
"yac": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[32m", "color_end": "\033[0m"}},
"cmd": map[string]interface{}{"value": []interface{}{"bench", "green"},
"lex": map[string]interface{}{"value": []interface{}{"debug", "green"}},
"yac": map[string]interface{}{"value": []interface{}{"debug", "green"}},
"cli": map[string]interface{}{
"cmd": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"cmd": map[string]interface{}{"value": []interface{}{"debug", "red"}},
},
"mdb": map[string]interface{}{
"note": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"note": map[string]interface{}{"value": []interface{}{"debug", "red"}},
},
"aaa": map[string]interface{}{
"auth": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"hash": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"rsa": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
"auth": map[string]interface{}{"value": []interface{}{"debug", "red"}},
"hash": map[string]interface{}{"value": []interface{}{"debug", "red"}},
"rsa": map[string]interface{}{"value": []interface{}{"debug", "red"}},
},
},
"right": map[string]interface{}{"value": []interface{}{"right"}},
}, Help: "日志输出配置"},
},
Commands: map[string]*ctx.Command{

View File

@ -22,9 +22,9 @@ func (tcp *TCP) Fuck(address []string, action func(address string) (net.Conn, er
m := tcp.Message()
fuck := make(chan bool, 3)
for i := 0; i < m.Confi("retry", "counts"); i++ {
for _, p := range address {
m.Cap("address", p)
for i := 0; i < m.Confi("retry", "counts"); i++ {
m.GoFunc(m, func(m *ctx.Message) {
p := m.Cap("address")
if c, e := action(p); e == nil {

View File

@ -96,7 +96,7 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
// return true
// }
defer func() {
msg.Option("access", msg.Cmdx("aaa.sess", "access"))
msg.Log("info", "access: %s", msg.Option("access", msg.Cmdx("aaa.sess", "access")))
}()
if msg.Confs("login", "cas") {
if !cas.IsAuthenticated(r) {
@ -136,14 +136,13 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
return false
}
if msg.Options("sessid") {
msg.Log("info", "sessid: %s", msg.Option("sessid"))
msg.Log("info", "username: %s", msg.Option("username", msg.Cmd("aaa.sess", "user").Append("meta")))
msg.Log("info", "nickname: %s", msg.Option("nickname", msg.Cmdx("aaa.auth", "username", msg.Option("username"), "data", "nickname")))
if !msg.Options("nickname") {
if msg.Log("info", "sessid: %s", msg.Option("sessid")); msg.Options("sessid") {
if msg.Log("info", "username: %s", msg.Option("username", msg.Cmd("aaa.sess", "user").Append("meta"))); msg.Options("username") {
if msg.Log("info", "nickname: %s", msg.Option("nickname", msg.Cmdx("aaa.auth", "username", msg.Option("username"), "data", "nickname"))); !msg.Options("nickname") {
msg.Option("nickname", msg.Option("username"))
}
}
}
if !msg.Options("username") && msg.Options("relay") {
if relay := msg.Cmd("aaa.relay", "check", msg.Option("relay")); relay.Appends("username") {
@ -169,7 +168,7 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
msg.Option("accept", r.Header.Get("Accept"))
msg.Option("method", r.Method)
msg.Option("path", r.URL.Path)
msg.Optionv("debug", false)
msg.Option("sessid", "")
// 请求环境
msg.Option("dir_root", msg.Cap("directory"))
@ -742,7 +741,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
*/
default:
if m.Options("save") {
if res.StatusCode == http.StatusOK && m.Options("save") {
dir := path.Dir(m.Option("save"))
if _, e = os.Stat(dir); e != nil {
m.Assert(os.MkdirAll(dir, 0777))
@ -1156,10 +1155,10 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
if strings.HasSuffix(key, "bench") {
key = key + "." + m.Option("GOOS") + "." + m.Option("GOARCH")
}
key = strings.Replace(key, ".", "_", -1)
p := m.Cmdx("nfs.path", path.Join(m.Conf("publish", "path"), key))
if p == "" {
p = m.Cmdx("nfs.path", m.Conf("publish", []string{"list", strings.Replace(key, ".", "_", -1)}))
p = m.Cmdx("nfs.path", m.Conf("publish", []string{"list", key}))
}
m.Log("info", "publish %s %s", kit.Hashs(p), p)

View File

@ -110,7 +110,7 @@ var page = Page({
])
if (true||kit.isWeiXin) {
if (kit.isWeiXin) {
pane.Run(["weixin"], function(msg) {
// if (!ctx.Search("state")) {
// location.href = msg["auth2.0"][0]

View File

@ -1,15 +1,28 @@
## context
context is not only context
context是一种新的应用框架,通过模块化、集群化、自动化,实现软件的快速开发,快速共享,快速使用。
### 下载安装
#### 简易版
在Mac或Linux上可以直接用脚本下载
在Linux或Mac上可以直接用脚本下载在Windows上可以先安装[GitBash](https://www.git-scm.com/download/),然后下载。
```
$ mkdir context && cd context
$ curl https://shylinux.com/code/upgrade/boot_sh | bash -s install
$ curl https://shylinux.com/publish/boot.sh | bash -s install
```
### 使用方式
context内部实现了很多功能模块每个模块下有很多命令每条命令就是一种应用。
#### 命令模式
```
$ bin/bench dir
```
#### 交互模式
#### 集群模式
#### 完整版
如果对源码有兴趣,使用更丰富的功能,可以直接下载源码,
```