Files
dock/试验用脚本
2025-11-03 11:27:48 +08:00

77 lines
2.5 KiB
Bash

#!/bin/bash
echo "🐱 欢迎使用 Syncthing 萌化一键安装脚本!"
echo "✨ 开始安装 Syncthing..."
# 检测系统
if [ -f /etc/debian_version ]; then
echo "🍥 检测到 Debian/Ubuntu 系统"
# 安装 Syncthing
curl -s -o /usr/share/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
echo "deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | tee /etc/apt/sources.list.d/syncthing.list
apt update && apt install -y syncthing
elif [ -f /etc/redhat-release ]; then
echo "🎀 检测到 CentOS/RHEL 系统"
dnf install -y syncthing || yum install -y epel-release && yum install -y syncthing
else
echo "❌ 不支持的系统"
exit 1
fi
echo "🎯 配置 Syncthing 服务..."
# 创建服务配置
cat > /etc/systemd/system/syncthing@root.service << 'EOF'
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %i
Documentation=man:syncthing(1)
After=network.target
[Service]
User=%i
ExecStart=/usr/bin/syncthing serve --no-browser --no-restart --logflags=0 --gui-address="0.0.0.0:8384"
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
[Install]
WantedBy=multi-user.target
EOF
echo "🔧 设置防火墙..."
# 开放端口(如果防火墙开启的话)
if command -v ufw >/dev/null; then
ufw allow 8384/tcp comment "Syncthing GUI"
ufw allow 22000/tcp comment "Syncthing Transfer"
ufw allow 21027/udp comment "Syncthing Discovery"
elif command -v firewall-cmd >/dev/null; then
firewall-cmd --permanent --add-port=8384/tcp
firewall-cmd --permanent --add-port=22000/tcp
firewall-cmd --permanent --add-port=21027/udp
firewall-cmd --reload
fi
echo "📁 创建备份目录..."
mkdir -p /syncthing_backup
echo "💾 备份目录已创建: /syncthing_backup"
echo "🚀 启动服务..."
systemctl daemon-reload
systemctl enable syncthing@root
systemctl start syncthing@root
# 等待服务启动
sleep 5
echo "🎉 安装完成!"
echo ""
echo "========================================"
echo "🐾 Syncthing 管理界面访问信息:"
echo "🌐 地址: http://$(curl -s ifconfig.me):8384/"
echo "💻 本地访问: http://localhost:8384/"
echo "📁 备份目录: /syncthing_backup"
echo "🔧 服务管理: systemctl status/start/stop syncthing@root"
echo "========================================"
echo ""
echo "💕 首次访问请通过网页设置设备名称和密码~"
echo "🐱 祝你使用愉快!"