From ff2fb4da149d75d10b47b22be940f1219dd7bcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Mon, 27 May 2024 05:36:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20Docker=20=E5=AE=89?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 105 ++++++++++++++++++++++++++++-------------- lib/tools/docker.sh | 109 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 34 deletions(-) create mode 100644 lib/tools/docker.sh diff --git a/README.md b/README.md index 809963dc..f1d3448b 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,18 @@ Yunzai 应用端,支持多账号,支持协议端:OneBotv11、ComWeChat、G 项目仅供学习交流使用,严禁用于任何商业用途和非法行为 -## 使用方法 +## 安装教程 -### 建议使用 TRSS Script 一键安装管理 +
脚本安装 - [🌌 TRSS](https://TRSS.me) - [🔼 Vercel](https://TRSS-Script.Vercel.app) - [🐱 GitHub](https://TimeRainStarSky.GitHub.io/TRSS_Script) - [🇬 Gitee](https://Gitee.com/TimeRainStarSky/TRSS_Script) -### 手动安装 +
+ +
手动安装 > 环境准备:Windows/Linux/MacOS/Android > [Node.js(>=v21)](https://nodejs.org), [Redis](https://redis.io), [Git](https://git-scm.com), [Chrome(可选)](https://google.cn/chrome) @@ -49,35 +51,86 @@ git clone --depth 1 https://gitee.com/TimeRainStarSky/Yunzai cd Yunzai ``` -2. 推荐安装插件(可选) +2. 安装 [pnpm](https://pnpm.io/zh/installation) 和依赖 ```sh -git clone --depth 1 https://github.com/TimeRainStarSky/Yunzai-genshin plugins/genshin -git clone --depth 1 https://github.com/yoimiya-kokomi/miao-plugin plugins/miao-plugin -git clone --depth 1 https://github.com/TimeRainStarSky/TRSS-Plugin plugins/TRSS-Plugin +npm i -g pnpm +pnpm i ``` +3. 前台运行 + +| 操作 | 命令 | +| ---- | ---- | +| 启动 | node . | +| 停止 | node . stop | + +4. 使用 [pm2](https://pm2.keymetrics.io) 后台运行 + +| 操作 | 命令 | +| ---- | ---- | +| 启动 | pnpm start | +| 停止 | pnpm stop | +| 日志 | pnpm log | + +5. 开机自启 + ```sh -git clone --depth 1 https://gitee.com/TimeRainStarSky/Yunzai-genshin plugins/genshin -git clone --depth 1 https://gitee.com/yoimiya-kokomi/miao-plugin plugins/miao-plugin -git clone --depth 1 https://Yunzai.TRSS.me plugins/TRSS-Plugin +pnpm start +pnpm pm2 save +pnpm pm2 startup ``` -3. 安装 [pnpm](https://pnpm.io/zh/installation) 和依赖 +
+ +
Docker 安装 ```sh -npm i -g pnpm -pnpm i +bash <(curl -L https://github.com/TimeRainStarSky/Yunzai/raw/main/lib/tools/docker.sh) +bash <(curl -L https://gitee.com/TimeRainStarSky/Yunzai/raw/main/lib/tools/docker.sh) ``` -4. 前台运行 +| 参数 | 描述 | 默认值 | +| ---- | ---- | ------ | +| DIR | 安装文件夹 | $HOME/Yunzai | +| CMD | 启动命令 | tsyz | +| CMDPATH | 命令文件夹 | /usr/local/bin | +| DKNAME | 容器名 | Yunzai | +| DKRESTART | 自动重启 | always | +| DKURL | Docker 源 | docker.nju.edu.cn | +| GITURL | 仓库源 | https://gitee.com/TimeRainStarSky/Yunzai | +| APTURL | APT 源 | mirrors.ustc.edu.cn | +| APTDEP | APT 依赖 | chromium fonts-lxgw-wenkai fonts-noto-color-emoji | +| NPMURL | NPM 源 | https://registry.npmmirror.com | + +- 参数修改方法 + +```sh +参数1="值1" 参数2="值2" bash <(x) +``` | 操作 | 命令 | | ---- | ---- | -| 启动 | node . | -| 停止 | node . stop | +| 连接 | tsyz | +| 断开 | Ctrl+P+Q | +| 启动 | tsyz start | +| 停止 | tsyz stop | +| 日志 | tsyz log 行数 | +| 命令 | tsyz 命令 | + +
+ +## 使用教程 -5. 启动协议端 +1. 推荐安装插件(可选) + +``` +#安装genshin +#安装miao-plugin +#安装TRSS-Plugin +``` + +2. 启动协议端
WebSocket
@@ -182,23 +235,7 @@ ws://localhost:2536/GSUIDCore
-6. 设置主人:发送 `#设置主人`,日志获取验证码并发送 - -7. 使用 [pm2](https://pm2.keymetrics.io) 后台运行 - -| 操作 | 命令 | -| ---- | ---- | -| 启动 | pnpm start | -| 停止 | pnpm stop | -| 日志 | pnpm log | - -8. 开机自启 - -```sh -pnpm start -pnpm pm2 save -pnpm pm2 startup -``` +3. 设置主人:发送 `#设置主人`,日志获取验证码并发送 ## 班级群(¿ diff --git a/lib/tools/docker.sh b/lib/tools/docker.sh new file mode 100644 index 00000000..7cfc0099 --- /dev/null +++ b/lib/tools/docker.sh @@ -0,0 +1,109 @@ +#TRSS Yunzai Docker 安装脚本 作者:时雨🌌星空 +NAME=v1.0.0;VERSION=202405270 +R="" G="" Y="" C="" B="" O="" +echo "$B——————————————————————————— +$R TRSS$Y Yunzai$G Docker$C Script$O + $G$NAME$C ($VERSION)$O +$B——————————————————————————— + $G作者:$C时雨🌌星空$O + +$Y- 正在检查环境$O +" +DIR="${DIR:-$HOME/Yunzai}" +CMD="${CMD:-tsyz}" +CMDPATH="${CMDPATH:-/usr/local/bin}" +DKNAME="${DKNAME:-Yunzai}" +DKRESTART="${DKRESTART:-always}" +DKURL="${DKURL:-docker.nju.edu.cn}" +GITURL="${GITURL:-https://gitee.com/TimeRainStarSky/Yunzai}" +APTURL="${APTURL:-mirrors.ustc.edu.cn}" +APTDEP="${APTDEP:-chromium fonts-lxgw-wenkai fonts-noto-color-emoji}" +NPMURL="${NPMURL:-https://registry.npmmirror.com}" +abort(){ echo " +$R! $@$O";exit 1;} +mktmp(){ TMP="$DIR/tmp"&&rm -rf "$TMP"&&mkdir -p "$TMP"||abort "缓存目录创建失败";} +if type docker;then + echo " +$G- Docker 已安装$O +" +elif type pacman &>/dev/null;then + echo " +$Y- 正在使用 pacman 安装 Docker$O +" + pacman -Syu --noconfirm --needed --overwrite "*" docker||abort "Docker 安装失败" +elif type apt &>/dev/null;then + echo " +$Y- 正在使用 apt 安装 Docker$O +" + apt update&&apt install -y docker.io||abort "Docker 安装失败" +else + echo " +$Y- 正在使用 官方脚本 安装 Docker$O +" + DOWNLOAD_URL="https://$APTURL/docker-ce" bash <(curl -L get.docker.com)||abort "官方脚本 执行失败,请自行安装 Docker 后重试:https://docker.com" +fi +docker info||{ systemctl enable --now docker||service docker start&&docker info;}&&echo " +$G- Docker 已启动$O"||abort "Docker 启动失败" +N=1 +until echo " +$Y- 正在从 $C$DKURL$Y 下载 Docker 容器$O +" +docker pull "$DKURL/library/node:slim";do + echo " +$R! 下载失败,5秒后切换镜像源$O" + sleep 5 + ((N++)) + case "$N" in + 1)DKURL="docker.nju.edu.cn";; + 2)DKURL="mirror.ccs.tencentyun.com";; + 3)DKURL="mirror.baidubce.com";; + 4)DKURL="dockerproxy.com";; + 5)DKURL="docker.m.daocloud.io";; + *)DKURL="docker.io";N=0 + esac +done +echo " +$Y- 正在构建 Docker 容器$O +" +mktmp +cd "$TMP" +echo "FROM $DKURL"'/library/node:slim +RUN sed -i "s|deb.debian.org|'"$APTURL"'|g" /etc/apt/sources.list.d/debian.sources\ + && apt update\ + && apt install -y ca-certificates\ + && sed -i "s|http://'"$APTURL"'|https://'"$APTURL"'|g" /etc/apt/sources.list.d/debian.sources\ + && apt update\ + && apt full-upgrade -y\ + && apt install -y curl git redis-server '"$APTDEP"'\ + && apt autoremove --purge\ + && apt clean\ + && git config --global --add safe.directory "*"\ + && npm install -g pnpm --registry "'"$NPMURL"'"\ + && rm -rf /var/cache/* /var/log/* /var/lib/apt /root/.npm\ + && echo -n "[ -s .git ]||git clone --depth 1 --single-branch \"'"$GITURL"'\" .&&pnpm install --force&&echo \"exec node .\">/start&&exec node .">/start +HEALTHCHECK CMD curl -s http://localhost:2536/status||exit 1 +WORKDIR /root/Yunzai +CMD ["sh","/start"] +EXPOSE 2536'>Dockerfile +docker build -t trss:yunzai .||abort "Docker 容器构建失败" +echo " +$Y- 正在启动 Docker 容器$O +" +docker rm -f $DKNAME 2>/dev/null +docker image prune -f +docker run -itd -h Yunzai --name $DKNAME -v "$DIR":/root/Yunzai --restart $DKRESTART $([ $DKNAME = Yunzai ]&&echo "-p2536:2536"||echo "-P") trss:yunzai||abort "Docker 容器启动失败" +mkdir -vp "$CMDPATH"&& +echo -n 'if [ -n "$1" ];then case "$1" in + s|start)exec docker start '$DKNAME';; + st|stop)exec docker stop -t0 '$DKNAME';; + rs|restart)exec docker restart -t0 '$DKNAME';; + l|log)exec docker logs -fn"${2:-100}" '$DKNAME';; + *)exec docker exec -it '$DKNAME' "$@";; +esac;else + docker logs -n100 '$DKNAME' + exec docker attach '$DKNAME' +fi'>"$CMDPATH/$CMD"&& +chmod 755 "$CMDPATH/$CMD"||abort "脚本执行命令 $CMDPATH/$CMD 设置失败,手动执行命令:docker attach $DKNAME" +echo " +$G- Docker 容器安装完成,启动命令:$C$CMD$O" +rm -rf "$TMP" \ No newline at end of file