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

opt auto.sh

This commit is contained in:
shaoying 2019-11-08 04:00:19 +08:00
parent 1891d89c1b
commit 4b02000c3d
4 changed files with 42 additions and 22 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh
if [ "$ctx_dev" = "" ] || [ "$ctx_dev" = "-" ]; then
if [ "${ctx_dev}" = "" ] || [ "${ctx_dev}" = "-" ]; then
ctx_dev="http://localhost:9095"
fi
@ -11,26 +11,34 @@ ctx_sid=${ctx_sid:=""}
ctx_welcome=${ctx_welcome:="^_^ Welcome to Context world ^_^"}
ctx_goodbye=${ctx_goodbye:="^_^ Welcome to Context world ^_^"}
ShyLine() {
echo "$*"|sed -e 's/\"/\\\"/g' -e 's/\n/\\n/g'
}
ShyJSON() {
[ $# -eq 1 ] && echo \"`ShyLine "$1"`\" && return
echo -n "{"
[ -n "$1" ] && echo -n \"$1\"\:\"$2\" && shift 2 && while [ -n "$1" ]; do
echo -n \, && echo -n \"$1\"\:\"$2\" && shift 2
while [ $# -gt 1 ]; do
echo -n \"`ShyLine "$1"`\"\:\"`ShyLine "$2"`\"
shift 2 && [ $# -gt 1 ] && echo -n ","
done
echo -n "}"
}
ShyPost() {
ShyJSON "$@" pwd "$(pwd)" sid "${ctx_sid}"| xargs -d'\n' -n1 curl -s "${ctx_url}" -H "${ctx_head}" -d 2>/dev/null
local data=`ShyJSON "$@" SHELL "${SHELL}" pwd "${PWD}" sid "${ctx_sid}"`
curl -s "${ctx_url}" -H "${ctx_head}" -d "${data}"
}
ShySync() {
case "$1" in
"history") tail -n0 -f $HISTFILE | while true; do read line
ShyPost arg "$line" cmd history SHELL $SHELL
echo $line
done;;
"input")
curl -s "${ctx_url}?cmd=input&arg=$READLINE_LINE" &>/dev/null
;;
esac
ShyWord() {
echo "$*"|sed -e 's/\ /%20/g' -e 's/\n/\\n/g'
}
ShyForm() {
while [ $# -gt 1 ]; do
echo -n "`ShyWord "$1"`=`ShyWord "$2"`"
shift 2 && [ $# -gt 1 ] && echo -n "&"
done
}
ShyGet() {
local data=`ShyForm "$@" SHELL "${SHELL}" pwd "${PWD}" sid "${ctx_sid}"`
curl -s "${ctx_url}?${data}"
}
Shy() {
local ctx_res=`ShyPost cmd "$1" arg "$2"`
@ -40,6 +48,18 @@ Shy() {
esac
}
ShySync() {
case "$1" in
"history") tail -n0 -f $HISTFILE | while true; do read line
line=`ShyLine $line`
Shy history "$line"
echo $line
done;;
"input")
ShyGet arg "$READLINE_LINE" cmd "input" SHELL "$SHELL"
;;
esac
}
ShyHistory() {
case "$SHELL" in
@ -52,12 +72,13 @@ ShyHistory() {
}
ShyLogout() {
echo ${ctx_goodbye}
ShyPost cmd logout
Shy logout
}
ShyLogin() {
ctx_sid=`ShyPost cmd login pid "$$" pane "${TMUX_PANE}" hostname "$(hostname)" username "${USER}"`
HOST=`hostname` ctx_sid=`ShyPost cmd login pid "$$" pane "${TMUX_PANE}" hostname "${HOST}" username "${USER}"`
echo ${ctx_welcome}
echo "sid: ${ctx_sid}"
echo "url: ${ctx_url}"
echo "sid: ${ctx_sid:0:6}"
echo "pid: $$"
}

View File

@ -471,9 +471,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Echo(err.String())
return
}
if cmd.ProcessState.ExitCode() != 0 {
return
}
// 解析结果
if format(m, out); m.Has("cmd_select") {

View File

@ -155,7 +155,7 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
}
// 本地用户
if !msg.Options("username") && kit.IsLocalIP(msg.Option("remote_ip")) && msg.Confs("web.login", "local") {
if !msg.Options("username") && kit.IsLocalIP(msg.Option("remote_ip")) && msg.Confs("web.login", "local") && !strings.HasPrefix(msg.Option("agent"), "curl") {
msg.Cmd("aaa.role", "root", "user", msg.Cmdx("ssh.work", "create"))
msg.Log("info", "%s: %s", msg.Option("remote_ip"), msg.Option("username", msg.Conf("runtime", "work.name")))
Cookie(msg, w, r)
@ -169,6 +169,7 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
defer func() {
msg.Log("time", "serve: %v", msg.Format("cost"))
}()
msg.Option("agent", r.Header.Get("User-Agent"))
msg.Option("remote_addr", r.RemoteAddr)
msg.Option("remote_ip", r.Header.Get("remote_ip"))
msg.Option("index_url", r.Header.Get("index_url"))

View File

@ -46,7 +46,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"shy": Dockfile,
}},
"git": {Name: "git", Help: "记录", Value: map[string]interface{}{
"alias": map[string]interface{}{"s": "status", "b": "branch"},
"alias": map[string]interface{}{"s": "status", "b": "branch"},
"config": []interface{}{map[string]interface{}{"conf": "merge.tool", "value": "vimdiff"}},
}},
"vim": {Name: "vim", Help: "记录", Value: map[string]interface{}{
"opens": map[string]interface{}{},