Files
dock/03
2026-01-25 10:37:17 +08:00

100 lines
2.7 KiB
Bash
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.
#!/bin/bash
# 1. 基础环境修复
echo "正在修复基础环境..."
apt-get update
# 安装常用工具lsof 用于端口检查psmisc 用于进程管理
apt-get install -y curl wget lsof psmisc
# 2. 准备目录 (修改为 /data)
DATA_DIR="/data"
# 检查目录是否存在,不存在则创建
if [ ! -d "$DATA_DIR" ]; then
echo "目录 $DATA_DIR 不存在,正在为你创建..."
mkdir -p "$DATA_DIR"
else
echo "检测到目录已存在: $DATA_DIR"
fi
# 3. 下载安装包 (优先使用你的源,失败则使用官方源)
echo "正在获取安装包..."
URL_HBBS="https://cloudreve.vps3344521.xyz/f/W9tx/rustdesk-server-hbbs_1.1.15_amd64.deb"
URL_HBBR="https://cloudreve.vps3344521.xyz/f/j3fJ/rustdesk-server-hbbr_1.1.15_amd64.deb"
# 下载 hbbs
wget -O hbbs.deb "$URL_HBBS" || wget -O hbbs.deb "https://github.com/rustdesk/rustdesk-server/releases/download/1.1.11-1/rustdesk-server-hbbs_1.1.11_amd64.deb"
# 下载 hbbr
wget -O hbbr.deb "$URL_HBBR" || wget -O hbbr.deb "https://github.com/rustdesk/rustdesk-server/releases/download/1.1.11-1/rustdesk-server-hbbr_1.1.11_amd64.deb"
# 检查文件大小,防止 502 错误
if [ ! -s hbbs.deb ]; then
echo "错误:未能下载有效的安装包,请检查网络连接。"
exit 1
fi
# 4. 安装并清理
echo "正在安装软件包..."
dpkg -i hbbs.deb hbbr.deb
apt-get install -f -y
rm -f hbbs.deb hbbr.deb
# 5. 配置 Systemd 服务
# 自动获取本机公网 IP
HOST_IP=$(curl -s4 ifconfig.me)
# 写入 hbbs 服务 (指定工作目录为 /data)
cat > /etc/systemd/system/rustdesk-hbbs.service <<EOF
[Unit]
Description=RustDesk ID Server
After=network.target
[Service]
Type=simple
# -k _ 强制生成并读取当前目录下的密钥对
ExecStart=/usr/bin/hbbs -r ${HOST_IP}:21117 -k _
WorkingDirectory=${DATA_DIR}
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
# 写入 hbbr 服务 (指定工作目录为 /data)
cat > /etc/systemd/system/rustdesk-hbbr.service <<EOF
[Unit]
Description=RustDesk Relay Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/hbbr -k _
WorkingDirectory=${DATA_DIR}
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
# 6. 启动并显示 Key
systemctl daemon-reload
systemctl enable --now rustdesk-hbbs rustdesk-hbbr
echo "------------------------------------------------"
echo "RustDesk 服务已在常规模式下启动!"
echo "数据存储路径已设置为: $DATA_DIR"
echo "正在等待 Key 文件生成..."
sleep 3
PUB_KEY="${DATA_DIR}/id_ed25519.pub"
if [ -f "$PUB_KEY" ]; then
echo "你的 Key 为:"
cat "$PUB_KEY"
else
echo "警告Key 文件尚未生成。"
echo "请尝试运行: systemctl status rustdesk-hbbs 检查服务状态"
fi
echo "------------------------------------------------"