Files
dock/ru2
2026-01-22 16:37:11 +08:00

139 lines
3.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
cat > install_native_fix.sh << 'EOF'
#!/bin/bash
# 颜色定义
GREEN='\033[32m'
RED='\033[31m'
YELLOW='\033[33m'
PLAIN='\033[0m'
# 1. 基础环境准备
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}错误:请使用 root 用户运行此脚本!${PLAIN}"
exit 1
fi
echo -e "${GREEN}正在安装必要工具...${PLAIN}"
apt-get update -y && apt-get install -y wget unzip tar systemd
# 2. 设置目录
INSTALL_DIR="/opt/rustdesk"
# 数据存放目录 (你的习惯路径)
DATA_DIR="/vol1/1000/dock/rustdesk_native"
mkdir -p "$INSTALL_DIR"
mkdir -p "$DATA_DIR"
# 3. 获取公网IP
read -p "请输入服务器公网 IP (必填): " HOST_IP
if [[ -z "$HOST_IP" ]]; then
echo -e "${RED}错误IP 不能为空!${PLAIN}"
exit 1
fi
# 4. 下载并解压程序
echo -e "${YELLOW}正在下载 RustDesk 服务端程序...${PLAIN}"
cd "$INSTALL_DIR"
# 清理旧文件
rm -rf rustdesk-server.zip hbbs hbbr amd64
wget -O rustdesk-server.zip https://github.com/rustdesk/rustdesk-server/releases/download/1.1.11-1/rustdesk-server-linux-amd64.zip
if [ ! -f "rustdesk-server.zip" ]; then
echo -e "${RED}下载失败,请检查网络连接。${PLAIN}"
exit 1
fi
echo -e "${YELLOW}正在解压并整理文件...${PLAIN}"
unzip -o rustdesk-server.zip
# === 关键修正:把文件从 amd64 文件夹里移动出来 ===
if [ -d "amd64" ]; then
mv amd64/hbbs .
mv amd64/hbbr .
rm -rf amd64
fi
# ============================================
chmod +x hbbs hbbr
if [ ! -f "hbbs" ]; then
echo -e "${RED}错误:解压后未找到 hbbs 文件,安装终止。${PLAIN}"
exit 1
fi
# 5. 创建系统服务 (hbbs - ID服务器)
echo -e "${YELLOW}正在注册系统服务...${PLAIN}"
cat > /etc/systemd/system/rustdesk-hbbs.service <<SERVICE
[Unit]
Description=RustDesk ID Server
After=network.target
[Service]
Type=simple
LimitNOFILE=1000000
ExecStart=${INSTALL_DIR}/hbbs -r ${HOST_IP} -k _
WorkingDirectory=${DATA_DIR}
User=root
Group=root
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
SERVICE
# 6. 创建系统服务 (hbbr - 中继服务器)
cat > /etc/systemd/system/rustdesk-hbbr.service <<SERVICE
[Unit]
Description=RustDesk Relay Server
After=network.target
[Service]
Type=simple
LimitNOFILE=1000000
ExecStart=${INSTALL_DIR}/hbbr -k _
WorkingDirectory=${DATA_DIR}
User=root
Group=root
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
SERVICE
# 7. 启动服务
systemctl daemon-reload
systemctl enable rustdesk-hbbs rustdesk-hbbr
systemctl restart rustdesk-hbbs rustdesk-hbbr
# 8. 检查状态并输出信息
sleep 3
if systemctl is-active --quiet rustdesk-hbbs; then
# 等待公钥生成
sleep 2
if [ -f "${DATA_DIR}/id_ed25519.pub" ]; then
PUB_KEY=$(cat "${DATA_DIR}/id_ed25519.pub")
else
PUB_KEY="密钥生成中,请稍后查看 ${DATA_DIR}/id_ed25519.pub"
fi
echo -e "${GREEN}=============================================${PLAIN}"
echo -e " RustDesk Server (原生版) 安装成功!"
echo -e "${GREEN}=============================================${PLAIN}"
echo -e "ID 服务器: ${GREEN}${HOST_IP}${PLAIN}"
echo -e "中继服务器: ${GREEN}${HOST_IP}${PLAIN}"
echo -e "API 服务器: ${YELLOW}原生版不含Web API直接使用即可${PLAIN}"
echo -e "Key (公钥):"
echo -e "${YELLOW}${PUB_KEY}${PLAIN}"
echo -e "${GREEN}=============================================${PLAIN}"
echo -e "数据目录: ${DATA_DIR}"
else
echo -e "${RED}服务启动失败,请运行 systemctl status rustdesk-hbbs 查看日志${PLAIN}"
fi
EOF
# 运行脚本
chmod +x install_native_fix.sh
./install_native_fix.sh