├── README.md ├── chronocat.sh └── ws-plugin.sh /README.md: -------------------------------------------------------------------------------- 1 |
2 | yuhuo 3 | 4 | 5 | # chronocat-docker-shell 6 | 7 | 使用[he0119/chronocat-docker](https://github.com/he0119/chronocat-docker),使用Docker一键式部署 8 | 9 | **使用Windows版NTQQ,可以使用合并转发功能** 10 | 11 | 仅适用于部分Linux主流版本,Windows平台请自行摸索,网上教程挺多的
12 | 13 |
14 | 15 | ## 风险 16 | 17 | 写在前面:作者已经在官网声明,请酌情考虑是否尝试 18 | 19 | ![image](https://github.com/CikeyQi/chronocat-docker-shell/assets/61369914/f6f26581-90f9-463b-9758-215f5a77a12d) 20 | 21 | 本项目仅作学习与参考,若发生任何损失,使用者将自行承担风险与责任 22 | 23 | ## 如何部署 24 | 25 | 在Linux终端中输入 26 | 27 | ``` shell 28 | bash <(curl -L https://sourl.cn/ihTgTy) 29 | ``` 30 | 31 | 按照提示操作即可 32 | 33 | ## 使用方法 34 | 35 | ### 安装与配置ws-plugin 36 | 37 | 在Linux终端中输入 38 | 39 | ``` shell 40 | bash <(curl -L https://sourl.cn/iMPpkw) 41 | ``` 42 | 43 | 按照提示操作即可 44 | 45 | ## 致谢 46 | 47 | - Chronocat项目:[chrononeko](https://github.com/chrononeko/) 48 | - Docker镜像:[he0119/chronocat-docker](https://github.com/he0119/chronocat-docker) 49 | -------------------------------------------------------------------------------- /chronocat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 添加颜色变量 4 | RED="\e[31m" # 红色 5 | GREEN="\e[32m" # 绿色 6 | YELLOW="\e[33m" # 黄色 7 | RESET="\e[0m" # 重置颜色 8 | 9 | # 添加函数以显示不同颜色的消息 10 | print_message() { 11 | local message="$1" 12 | local color="$2" 13 | echo -e "${color}${message}${RESET}" 14 | } 15 | 16 | check_port() { 17 | local port=$1 18 | 19 | # 检查端口是否是一个正整数 20 | if ! [[ $port =~ ^[0-9]+$ ]]; then 21 | print_message "错误:端口号必须是一个正整数。" "$RED" 22 | exit 1 23 | fi 24 | 25 | # 检查端口范围 26 | if [ $port -lt 1 ] || [ $port -gt 65535 ]; then 27 | print_message "错误:端口号必须在 1-65535 之间。" "$RED" 28 | exit 1 29 | fi 30 | 31 | # 检查端口是否被占用 32 | ss -nlt | awk '{print $4}' | grep -q ":$port$" 33 | if [ $? -eq 0 ]; then 34 | print_message "错误:端口号 $port 已被占用。" "$RED" 35 | exit 1 36 | fi 37 | 38 | # 检查非安全端口 39 | if [ $port -lt 1024 ]; then 40 | print_message "警告:端口号 $port 不是安全端口。" "$YELLOW" 41 | fi 42 | } 43 | 44 | print_message "欢迎使用 ChronoCat 一键安装脚本" "$GREEN" 45 | print_message "本脚本将自动安装 Docker 环境并拉取 ChronoCat 镜像" "$GREEN" 46 | print_message "脚本遇到问题请加群寻找解决方法:551081559" "$GREEN" 47 | 48 | # 获取用户输入的端口号 49 | read -p "请输入noVNC服务端口号(默认6080): " port1 50 | read -p "请输入Red服务端口号(默认16530): " port2 51 | read -p "请输入Satori服务端口号(默认5500): " port3 52 | 53 | # 检查输入是否为空,如果为空则使用默认值 54 | if [[ -z "$port1" ]]; then 55 | port1=6080 56 | fi 57 | 58 | if [[ -z "$port2" ]]; then 59 | port2=16530 60 | fi 61 | 62 | if [[ -z "$port3" ]]; then 63 | port3=5500 64 | fi 65 | 66 | # 检查端口号是否合法且被占用 67 | check_port $port1 68 | check_port $port2 69 | check_port $port3 70 | 71 | # 将端口号赋值给变量 72 | VNCPORT=$port1 73 | RedPORT=$port2 74 | SatoriPORT=$port3 75 | 76 | print_message "端口号检查完成,如有异常请处理异常" "$GREEN" 77 | 78 | # 检查是否安装 Docker 79 | if ! command -v docker &> /dev/null; then 80 | print_message "未检测到 Docker 环境,开始安装 Docker..." "$YELLOW" 81 | 82 | if command -v apt &> /dev/null; then 83 | apt update > /dev/null 84 | apt install -y docker.io > /dev/null 85 | elif command -v apt-get &> /dev/null; then 86 | apt-get update > /dev/null 87 | apt-get install -y docker.io > /dev/null 88 | elif command -v dnf &> /dev/null; then 89 | dnf install -y docker > /dev/null 90 | systemctl enable --now docker > /dev/null 91 | elif command -v yum &> /dev/null; then 92 | yum install -y docker-ce > /dev/null 93 | systemctl enable --now docker > /dev/null 94 | elif command -v pacman &> /dev/null; then 95 | pacman -Syu --noconfirm docker > /dev/null 96 | systemctl enable --now docker > /dev/null 97 | else 98 | print_message "无法确定操作系统的包管理器,请手动安装 Docker" "$RED" 99 | exit 1 100 | fi 101 | print_message "Docker 环境安装完成" "$GREEN" 102 | else 103 | print_message "已安装 Docker 环境,跳过安装" "$GREEN" 104 | fi 105 | 106 | print_message "正在拉取 ChronoCat 镜像..." "$YELLOW" 107 | 108 | docker pull he0119/chronocat-docker 109 | 110 | read -p "请输入容器名称(默认随机): " container_name 111 | read -p "请输入VNC服务密码(默认password): " password 112 | 113 | # 获取用户输入,选择网络模式 114 | print_message "请选择网络模式:" "$YELLOW" 115 | echo "1. 使用默认网络模式" 116 | echo "2. 使用 Host 网络模式" 117 | read -p "请输入选项 (默认为1): " network_option 118 | network_option=${network_option:-1} 119 | 120 | # 根据用户选择设置网络模式参数 121 | if [ "$network_option" == "2" ]; then 122 | network_mode="--network=host" 123 | else 124 | network_mode="" 125 | fi 126 | 127 | # 检查密码是否为空,如果为空则使用默认密码 128 | if [ -z "$password" ]; then 129 | password="password" 130 | fi 131 | 132 | # 检查容器名称是否为空,如果为空则生成一个随机名称 133 | if [ -z "$container_name" ]; then 134 | container_name=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8 ; echo '') 135 | fi 136 | 137 | print_message "=========================" "$GREEN" 138 | echo -e "\033[32请保存并牢记以下信息,它们只会显示一次\033[0m" 139 | echo -e "\033[32mnoVNC服务端口号:\033[0m \033[31m$VNCPORT\033[0m" 140 | echo -e "\033[32mRed服务端口号:\033[0m \033[31m$RedPORT\033[0m" 141 | echo -e "\033[32mSatori服务端口号:\033[0m \033[31m$SatoriPORT\033[0m" 142 | echo -e "\033[32mVNC服务密码:\033[0m \033[31m$password\033[0m" 143 | echo -e "\033[32m容器名称:\033[0m \033[31m$container_name\033[0m" 144 | print_message "=========================" "$GREEN" 145 | 146 | # 等待用户确认 147 | read -p "请确认以上信息是否正确?[Y/n] " confirm 148 | if [[ $confirm != "Y" && $confirm != "y" ]]; then 149 | print_message "用户取消操作,退出脚本。" "$RED" 150 | exit 1 151 | fi 152 | 153 | # 获取公网 IP 154 | ip=$(curl -s https://api.ipify.org) 155 | 156 | # 拼接 VNC 链接 157 | vnc_link="http://$ip:$VNCPORT/" 158 | 159 | print_message "正在启动 ChronoCat 容器..." "$YELLOW" 160 | 161 | # 静默启动容器 162 | docker run -it -d -p $RedPORT:16530 -p $VNCPORT:80 -p $SatoriPORT:5901 -e VNC_PASSWD=$password $network_mode --name $container_name he0119/chronocat-docker >> $container_name-docker.log 2>&1 163 | 164 | # 等待10秒 165 | sleep 10 166 | print_message "ChronoCat 容器启动完成" "$GREEN" 167 | 168 | # 等待用户VNC操作完成 169 | print_message "请在浏览器中打开VNC链接:" "$GREEN" 170 | print_message "=========================" "$GREEN" 171 | print_message "$vnc_link" "$RED" 172 | print_message "=========================" "$GREEN" 173 | read -p "登录NTQQ后,按下回车键继续" confirm 174 | 175 | # cat抓取容器中的token 176 | red_token=$(docker exec -it $container_name cat /wine/drive_c/users/root/.chronocat/config/chronocat.yml | awk '/- type: red/{getline; if ($1 == "token:") print $2}' | head -n 1) 177 | 178 | satori_token=$(docker exec -it $container_name cat /wine/drive_c/users/root/.chronocat/config/chronocat.yml | awk '/- type: satori/{getline; if ($1 == "token:") print $2}' | head -n 1) 179 | 180 | print_message "=========================" "$GREEN" 181 | echo -e "\033[32请保存并牢记以下信息,它们只会显示一次\033[0m" 182 | echo -e "\033[32mRed链接:\033[0m \033[31mhttp://$ip:$RedPORT\033[0m" 183 | echo -e "\033[32mRed Token:\033[0m \033[31m$red_token\033[0m" 184 | echo -e "\033[32mSatori链接:\033[0m \033[31mhttp://$ip:$SatoriPORT\033[0m" 185 | echo -e "\033[32mSatori Token:\033[0m \033[31m$satori_token\033[0m" 186 | print_message "=========================" "$GREEN" 187 | 188 | print_message "ChronoCat 安装完成" "$GREEN" -------------------------------------------------------------------------------- /ws-plugin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 添加颜色变量 4 | RED="\e[31m" # 红色 5 | GREEN="\e[32m" # 绿色 6 | YELLOW="\e[33m" # 黄色 7 | RESET="\e[0m" # 重置颜色 8 | 9 | # 添加函数以显示不同颜色的消息 10 | print_message() { 11 | local message="$1" 12 | local color="$2" 13 | echo -e "${color}${message}${RESET}" 14 | } 15 | 16 | print_message "欢迎使用 ChronoCat 一键安装脚本" "$GREEN" 17 | print_message "本脚本将安装并配置ws-plugin,请先部署NTQQ后再使用" "$GREEN" 18 | print_message "一键部署NTQQ脚本:https://github.com/CikeyQi/chronocat-docker-shell" "$GREEN" 19 | print_message "脚本遇到问题请加群寻找解决方法:551081559" "$GREEN" 20 | 21 | print_message "正在检查环境..." "$YELLOW" 22 | 23 | # 检查是否安装了Git 24 | if ! command -v git &> /dev/null; then 25 | print_message "请先安装Git" "$RED" 26 | exit 1 27 | fi 28 | 29 | # 检查是否安装了pnpm 30 | if ! command -v pnpm &> /dev/null; then 31 | print_message "请先安装pnpm" "$RED" 32 | exit 1 33 | fi 34 | 35 | # 检查当前目录是否存在plugins文件夹 36 | if [ ! -d "plugins" ]; then 37 | print_message "请在Yunzai根目录下运行此脚本" "$RED" 38 | exit 1 39 | fi 40 | 41 | # 检查当前目录是否存在plugins/ws-plugin文件夹 42 | if [ -d "plugins/ws-plugin" ]; then 43 | print_message "检测到您已经安装了ws-plugin,正在删除..." "$YELLOW" 44 | rm -rf ./plugins/ws-plugin/ 45 | fi 46 | 47 | print_message "正在克隆ws-plugin仓库..." "$YELLOW" 48 | 49 | # 克隆ws-plugin仓库到plugins/ws-plugin目录 50 | git clone --depth=1 -b red https://gitee.com/xiaoye12123/ws-plugin.git ./plugins/ws-plugin/ 51 | 52 | print_message "正在安装依赖..." "$YELLOW" 53 | 54 | # 安装依赖 55 | pnpm install --filter=ws-plugin 56 | 57 | # 用户选择TRSS-Yunzai或Miao-Yunzai 58 | echo "请选择您使用的Yunzai-Bot版本:" 59 | echo "1. TRSS-Yunzai" 60 | echo "2. Miao-Yunzai" 61 | read -p "请输入数字[1/2]:" version 62 | 63 | # 检查用户输入是否合法 64 | if [[ -z "$version" && "$version" != "1" && "$version" != "2" ]]; then 65 | echo "请输入数字[1/2]" 66 | exit 1 67 | fi 68 | 69 | # 如果是Miao-Yunzai,则下载apps.js放在根目录 70 | if [ "$version" == "2" ]; then 71 | print_message "正在下载配置文件..." "$YELLOW" 72 | wget https://gitee.com/Zyy955/Yunzai-Bot-plugin/raw/main/apps.js -O apps.js 73 | fi 74 | 75 | # 如果没有则新建ws-plugin/config/config/目录 76 | if [ ! -d "./plugins/ws-plugin/config/config/" ]; then 77 | mkdir ./plugins/ws-plugin/config/config/ 78 | fi 79 | 80 | # 检查是否存在ws-plugin/config/config/ws-config.yaml,如果存在则删除 81 | if [ -f "./plugins/ws-plugin/config/config/ws-config.yaml" ]; then 82 | rm ./plugins/ws-plugin/config/config/ws-config.yaml 83 | fi 84 | 85 | print_message "正在写入配置文件..." "$YELLOW" 86 | 87 | # 将ws-plugin/config/default_config/下的ws-config.yaml复制到ws-plugin/config/config/ 88 | cp ./plugins/ws-plugin/config/default_config/ws-config.yaml ./plugins/ws-plugin/config/config/ 89 | 90 | # 等待用户输入连接名称,链接地址和Token,机器人QQ 91 | read -p "请输入您的连接名称(默认chronocat):" name 92 | read -p "请输入您的链接地址(默认127.0.0.1:16530):" url 93 | read -p "请输入您的Red Token:" token 94 | read -p "请输入您的机器人QQ号:" uin 95 | 96 | # 检查用户输入是否合法,如果不输入则使用默认值 97 | if [ -z "$name" ]; then 98 | name="chronocat" 99 | fi 100 | 101 | if [ -z "$url" ]; then 102 | url="127.0.0.1:16530" 103 | fi 104 | 105 | if [[ "$url" == "http://"* ]]; then 106 | url=${url/http:\/\//} 107 | fi 108 | 109 | if [ -z "$token" ]; then 110 | echo "请输入您的Red Token" 111 | exit 1 112 | fi 113 | 114 | if [ -z "$uin" ]; then 115 | echo "请输入您的机器人QQ号" 116 | exit 1 117 | fi 118 | 119 | # 将用户输入的连接名称,链接地址和Token写入ws-plugin/config/config/ws-config.yaml 120 | cat << EOF >> ./plugins/ws-plugin/config/config/ws-config.yaml 121 | \\n 122 | - name: $name 123 | address: $url 124 | type: 4 125 | reconnectInterval: 5 126 | maxReconnectAttempts: 0 127 | accessToken: $token 128 | uin: $uin 129 | EOF 130 | 131 | # 如果是Miao-Yunzai,则提醒用户以后启动使用node apps启动 132 | if [ "$version" == "2" ]; then 133 | print_message "请以后使用 node apps 启动Yunzai-Bot" "$YELLOW" 134 | fi 135 | 136 | print_message "配置成功,将在5秒后启动Yunzai-Bot" "$GREEN" 137 | 138 | # 等待5秒 139 | sleep 5 140 | 141 | # 如果是TRSS-Yunzai,则使用node app启动,否则使用node apps启动 142 | if [ "$version" == "1" ]; then 143 | node app 144 | else 145 | node apps 146 | fi --------------------------------------------------------------------------------