添加windows远程开发脚本

This commit is contained in:
lijinwen 2023-07-19 13:49:29 +08:00
parent 5a8069a517
commit 60ca1ea098
5 changed files with 134 additions and 4 deletions

View File

@ -0,0 +1,126 @@
#!/bin/bash
client_user=$1
client_uuid=$2
server_ip=$3
server_user=$4
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ];then
echo "1,Parameter input error."
exit 1
fi
SUPPORT_ARCHS=( "arm64" "x86_64" "x64" "loongarch64" "aarch64" "loong64" "mips64el" "mips64");
arch=$(uname -m)
echo "${SUPPORT_ARCHS[@]}" | grep -wq "$arch" && support="Yes" || support="No"
if [ $support == "No" ];then
echo "1,Current arch not support."
exit 0
fi
echo $client_user $client_uuid $server_ip $server_user
uuidinfo=$client_user$client_uuid$server_user$server_ip
# echo $uuidinfo
hashkey=`echo $uuidinfo |md5sum |awk '{print $1}'`
# echo $hashkey
SESSION="${hashkey}"
SERVER=~/.kylin-ide-server
TOKENFILE=$SERVER/data/.$hashkey.token
# RUNNINGPID=$(ps -aux | grep $SESSION | grep server-main.js | grep -v grep | awk '{print $2}')
RUNNINGPID=$(ps -aux | grep $SESSION | grep server-main.js | grep -v grep | awk '{print $2}')
WEB_SERVER_PATH=$SERVER/server/node
# os=$(cat /etc/os-release | grep "PRETTY_NAME" | awk -F '=' '{print $2}')
# echo "runningpid:$RUNNINGPID arch:${arch} os :${os}"
STATUS=("RUNNING" "TOSTART" "TODEPLOY" "ERROR")
# echo "----------"
if [ -n "$RUNNINGPID" ];then
# isrunning=1
stat=${STATUS[0]}
[ -e $TOKENFILE ] && token=$(cat $TOKENFILE) || token=""
else
# isrunning=0
test -f $WEB_SERVER_PATH && stat=${STATUS[1]} || stat=${STATUS[2]}
fi
# echo $stat
#todeploy 中找软件包,找不到报错 或者脚本和软件包在一个目录下载解压,然后运行脚本 进行cp
error_token="1,Token not found ."
error_stat="1,status error."
run_webide_server(){
SERVER_DATA=$SERVER/data
[ -d $SERVER_DATA ] || mkdir $SERVER_DATA
SERVER_BIN=$SERVER/server/bin/kylin-ide-server
LOGFILE=$SERVER_DATA/${hashkey}.log
TOKEN=$(cat /proc/sys/kernel/random/uuid)
echo $TOKEN >$SERVER_DATA/.${hashkey}.token
echo "token=$TOKEN"
if [ token == "" ]
then
echo $error_token
else
[ -e $SERVER_DATA/.${hashkey}.sock ] && rm -rf $SERVER_DATA/.${hashkey}.sock
$SERVER_BIN --socket-path=$SERVER_DATA/.${hashkey}.sock --remotename=${server_user}@${server_ip} --connection-token-file=$SERVER_DATA/.${hashkey}.token --server-data-dir=$SERVER_DATA --enable-remote-auto-shutdown > $LOGFILE 2>&1 &
fi
}
prepare_start_remote_server(){
stat=$1
case $stat in
"RUNNING")
# echo "start RUNNING"
if [ token == "" ]
then
echo $error_token
else
# selfSock = `/tmp/${hashkey}.sock` 客户端sock
serverSock="/home/${server_user}/.kylin-ide-server/data/.${hashkey}.sock"
echo "0,${serverSock},${token}"
fi
;;
"TOSTART")
# echo "start TOSTART"
run_webide_server
;;
"TODEPLOY")
# echo "start deploy"
if [ ! -d ~/.kylin-ide-server/server ];then
mkdir -p ~/.kylin-ide-server/server
fi
# find -type
codepath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# echo $codepath
echo ${codepath}
echo ${arch}
pkg="$(ls "${codepath}" | grep "^kylin-ide-server_\([0-9]*.\)\{2\}[0-9]*_${arch}"|sort -r | head -n 1)"
echo $pkg
if [ -z $pkg ];then
echo "1,not find package in ${codepath}"
exit 1
fi
tar -xf ${codepath}/${pkg} -C ~/.kylin-ide-server/server;
run_webide_server
;;
*)
# echo "===error"
echo $error_stat
exit 1
esac
}
# echo $stat
prepare_start_remote_server $stat
exit 0

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 325 KiB

After

Width:  |  Height:  |  Size: 212 KiB

View File

@ -173,19 +173,23 @@
- 获取远程Linux主机的SSH用户和密码查看远程主机的架构是否属于x86_64、loongarch64、aarch64的其中一种目前远程开发支持以上三种架构
- 检查“远程机”的sshd服务是否正常“/etc/ssh/sshd_config”中 “AllowTcpForwarding”和“PermitTunnel”为yes如果“AllowTcpForwarding”和“PermitTunnel”为no请修改配置并重启sshd服务
- 检查在客户机是否能够通过ssh连接到远程机
- 脚本下载:
从[windows远程开发脚本下载地址](https://gitee.com/openkylin/extensions-repo.git/) 下载KylinIDETEeam/remote-dev/目录下的kylin-ide-server-build.sh和kylin-remote-start.exe文件
- 远程开发环境服务端软件包下载:
- 根据远程机的架构从gitee中选择对应架构的软件包进行下载(**下载版本 >= v0.1.2**)。[远程开发服务端软件包](https://gitee.com/mcy-kylin/kylin-ide-server/releases/) ,如: OpenKylin 操作系统、x86架构下需下载对应[kylin-ide-server_0.1.2_x86_64.tar.gz](https://gitee.com/mcy-kylin/kylin-ide-server/releases/download/v0.1.2/kylin-ide-server_0.1.2_x86_64.tar.gz)包
- 将下载的软件包和kylin-ide-server-build.sh脚本放在远程机的同一个目录下~/test/
- 为kylin-ide-server-build.sh脚本设置`可执行权限`。
- 将kylin-remote-start.bat脚本放在windows客户端目录下
- 将kylin-remote-start.exe脚本放在windows客户端目录下
## 2、脚本执行
- kylin-remote-start.bat脚本执行
- 将脚本放在windows客户端上后通过cmd启动windows命令终端进入脚本所在目录执行该脚本,格式如下:
` kylin-remote-start.bat [远程用户名] [远程环境ip] [远程环境kylin-ide-server-build.sh脚本所在目录]`
` kylin-remote-start.exe [远程用户名] [远程环境ip] [远程环境kylin-ide-server-build.sh脚本所在目录]`
- 执行脚本后输入远程机密码,如下图所示:
![9-1](resources/kylin-remote-dev/windows1.png "启动bat脚本")
- 根据提示在新的弹窗中再次输入远程机密码此次输入密码是为了建立隧道使用过程中请勿关闭该窗口。如果未弹出窗口或超时请重新bat执行脚本