From 1c43fdaab4bb7a3816d99b822493005d8d49793c Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 12 Sep 2019 23:00:31 +0800 Subject: [PATCH] opt boot.sh --- bin/boot.sh | 98 +++++++++++++++++-------------- bin/zone.sh | 2 +- src/contexts/cli/cli.go | 5 ++ src/contexts/cli/version.go | 2 +- src/contexts/nfs/nfs.go | 4 +- usr/local/wiki/自然/编程/index.md | 24 +++++++- 6 files changed, 87 insertions(+), 48 deletions(-) diff --git a/bin/boot.sh b/bin/boot.sh index c4e03a45..460ad30a 100755 --- a/bin/boot.sh +++ b/bin/boot.sh @@ -1,55 +1,56 @@ #! /bin/bash -# ctx_log_debug=false -# ctx_log_disable=false -# ctx_gdb_enable=false +# 日志配置 +export ctx_log=${ctx_log:="var/log"} +export ctx_log_debug=${ctx_log_debug:=false} +export ctx_log_disable=${ctx_log_disable:=false} +export ctx_gdb_enable=${ctx_gdb_enable:=false} -ctx_log=${ctx_log:="var/log"} -ctx_app=${ctx_app:="bench"} -ctx_bin=${ctx_bin:=`which ${ctx_app}`} && [ -f bin/${ctx_app} ] && ctx_bin=$(pwd)/bin/${ctx_app} -# ctx_cas= -# ctx_ups= -# ctx_box= -ctx_dev=${ctx_dev:="https://shylinux.com"} -ctx_root=${ctx_root:=/usr/local/context} -ctx_home=${ctx_home:=~/context} -# ctx_type= -# node_cert= -# node_key= -# web_port= -# ssh_port= -# HOSTNAME= -# USER= -# PWD= -export ctx_log ctx_app ctx_bin ctx_box ctx_cas ctx_dev -export ctx_root ctx_home web_port ssh_port +# 目录配置 +export ctx_app=${ctx_app:="bench"} +export ctx_bin=${ctx_bin:=$(pwd)/bin/${ctx_app}}; [ -e $ctx_bin ] || export ctx_bin=`which ${ctx_app}` +export ctx_root=${ctx_root:=/usr/local/context} +export ctx_home=${ctx_home:=~/context} + +# 网络配置 +export ctx_cas=${ctx_cas:=""} +export ctx_ups=${ctx_ups:=""} +export ctx_box=${ctx_box:=""} +export ctx_dev=${ctx_dev:="https://shylinux.com"} + +# 服务配置 +export ctx_type=${ctx_type:="node"} +export ssh_port=${ssh_port:=":9090"} +export web_port=${web_port:=":9095"} + +# 用户配置 +export node_cert=${node_cert:=""} +export node_key=${node_key:=""} +export HOSTNAME=${HOSTNAME:=""} +export USER=${USER:=""} +export PWD=${PWD:=""} -log() { - echo -e $* -} install() { - if [ -n "$1" ]; then - mkdir $1; cd $1 - fi + if [ -n "$1" ]; then mkdir $1; cd $1; shift; fi md5=md5sum case `uname -s` in - "Darwin") GOOS=darwin GOARCH=amd64 md5=md5;; - *) GOOS=linux GOARCH=386;; + "Darwin") GOOS=darwin md5=md5;; + "Linux") GOOS=linux;; + *) GOOS=windows;; esac case `uname -m` in "x86_64") GOARCH=amd64;; "armv7l") GOARCH=arm;; + *) GOARCH=386;; esac - target=system && [ -n "$2" ] && target=$2 + curl -o ${ctx_app} "$ctx_dev/publish/${ctx_app}?GOOS=$GOOS&GOARCH=$GOARCH" &>/dev/null && chmod a+x ${ctx_app} || return - wget -O ${ctx_app} "$ctx_dev/publish/${ctx_app}?GOOS=$GOOS&GOARCH=$GOARCH" && chmod a+x ${ctx_app} \ - && ${md5} ${ctx_app} && ./${ctx_app} upgrade ${target} && ./${ctx_app} upgrade portal \ - && mv ${ctx_app} bin/${ctx_app} -} -hup() { - echo "term hup" + target=install && [ -n "$1" ] && target=$1 + ${md5} ${ctx_app} && ./${ctx_app} upgrade ${target} || return + + mv ${ctx_app} bin/${ctx_app} && bin/boot.sh } main() { trap HUP hup @@ -63,17 +64,28 @@ action() { pid=$(cat var/run/bench.pid) log "kill" $1 $pid && kill -$1 ${pid} } +hup() { echo "term hup"; } +log() { echo -e $*; } - -dir=./ && [ -d "$1" ] && dir=$1 && shift -[ -d "${dir}" ] && cd ${dir} -log "ups:$ctx_ups" +log "bin:$ctx_bin" log "box:$ctx_box" log "dev:$ctx_dev" -log "bin:$ctx_bin" -log "dir:$dir" +log "ups:$ctx_ups" case $1 in + help) echo + echo " >>>> welcome context world! <<<<" + echo + echo "more info see https://github.com/shylinux/context" + echo + echo " install [dir [type]] 安装并启动服务" + echo " [start] 启动服务" + echo " create dir 创建并启动服务" + echo " restart 重启服务" + echo " upgrade 升级服务" + echo " quit 保存并停止服务" + echo " term 停止服务" + ;; install) shift && install "$@";; start) shift && main "$@";; "") main "$@";; diff --git a/bin/zone.sh b/bin/zone.sh index a5fbebf6..60498900 100755 --- a/bin/zone.sh +++ b/bin/zone.sh @@ -1,9 +1,9 @@ #! /bin/bash export ctx_ups=- +export ctx_box=- export ctx_dev=- export ctx_type=work [ -f bin/boot.sh ] && source bin/boot.sh || source boot.sh - diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 7f34f5c4..4892d099 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -139,6 +139,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", }, }, Help: "版本发布"}, "upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{ + "install": []interface{}{"system"}, "system": []interface{}{"boot.sh", "zone.sh", "user.sh", "node.sh", "init.shy", "common.shy", "exit.shy"}, "portal": []interface{}{"template.tar.gz", "librarys.tar.gz"}, "script": []interface{}{"test.php"}, @@ -945,6 +946,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } switch arg[0] { + case "install": + m.Cmd("cli.upgrade", "system") + m.Cmd("cli.upgrade", "portal") + case "project": m.Cmd("cli.project", "init") m.Cmd("cli.compile", "all") diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 463466c8..6561c698 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -4,5 +4,5 @@ var version = struct { host string self int }{ - "2019-09-12 16:21:30", "centos", 529, + "2019-09-12 22:20:19", "centos", 532, } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index d90d344b..3a5ca7d4 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -558,7 +558,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", "trash": "var/tmp/trash", }, Help: "目录管理"}, "pwd": &ctx.Config{Name: "pwd", Value: []interface{}{ - "var", "usr", "usr/local", "bin", "etc", "", + "", "usr/local", "usr", "var", "bin", "etc", "src", "src/plugin", }, Help: "当前目录"}, }, Commands: map[string]*ctx.Command{ @@ -629,7 +629,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", skip, find := false, false m.Confm("pwd", func(index int, value string) bool { - p := path.Join(value, arg[0]) + p := kit.Select("./", path.Join(value, arg[0])) if s, e := os.Stat(p); e == nil { if s.IsDir() { rg, _ := regexp.Compile(m.Option("dir_reg")) diff --git a/usr/local/wiki/自然/编程/index.md b/usr/local/wiki/自然/编程/index.md index fbb3de4d..bab48705 100644 --- a/usr/local/wiki/自然/编程/index.md +++ b/usr/local/wiki/自然/编程/index.md @@ -20,7 +20,29 @@ context是以分布式的方式,进行程序的开发。 $ curl https://shylinux.com/publish/boot.sh | bash -s install context ``` -install后面的参数context,就是指定的下载目录, +install后面的参数context,就是指定的下载目录,如不指定,会把相关文件下载到当前目录。 + +下载完成后,会自动启动context, +windows下的GitBash中,如果自动启动失败,则需要手动启动一下。 +``` +$ cd context && bin/boot.sh +``` + +启动后context,就是一种交互式的shell,可以执行各种内部命令和系统本地命令。 +如下查看当前目录与当目录下的文件。 +``` +0[22:21:19]nfs> pwd +/home/homework/context + +1[22:21:20]nfs> dir +time size line path +2019-09-12 22:21:18 103 5 bin/ +2019-09-12 22:20:40 72 3 etc/ +2019-09-12 22:21:18 50 2 usr/ +2019-09-12 22:20:40 55 3 var/ +2[22:21:20]nfs> +``` + 进入下载目录,可以看到的有八个文件。 在bin目录下,就是各种执行文件