Update 试验用脚本

This commit is contained in:
2025-11-03 10:55:27 +08:00
committed by GitHub
parent 728330b083
commit 7eff2e3c10

View File

@@ -1,102 +1,103 @@
cat > fix-syncthing-install.sh << 'EOF' # 完全重新配置
#!/bin/bash systemctl stop syncthing
rm -rf /var/lib/syncthing/config/*
echo "========================================" # 重新生成配置并指定监听地址
echo " Syncthing 修复安装脚本" sudo -u syncthing /usr/local/bin/syncthing -generate="/var/lib/syncthing/config"
echo "========================================"
# 修复系统依赖 # 手动修改配置
echo "安装系统依赖..." cat > /var/lib/syncthing/config/config.xml << 'EOF'
apt update <configuration version="39">
apt install -y gnupg2 curl wget <folder id="default" label="Default Folder" path="/var/lib/syncthing/sync" type="sendreceive" rescanIntervalS="3600" fsWatcherEnabled="true" fsWatcherDelayS="10" ignorePerms="false" autoNormalize="true">
<filesystemType>basic</filesystemType>
# 清理之前的错误配置 <device id="SELF"></device>
echo "清理旧配置..." <minDiskFree unit="%">1</minDiskFree>
systemctl stop syncthing 2>/dev/null <versioning></versioning>
systemctl disable syncthing 2>/dev/null <copiers>0</copiers>
rm -f /etc/systemd/system/syncthing.service <pullerMaxPendingKiB>0</pullerMaxPendingKiB>
rm -f /etc/apt/sources.list.d/syncthing.list <hashers>0</hashers>
<order>random</order>
# 方法1: 使用通用安装(推荐) <ignoreDelete>false</ignoreDelete>
echo "使用通用安装方法..." <scanProgressIntervalS>0</scanProgressIntervalS>
cd /tmp <pullerPauseS>0</pullerPauseS>
LATEST_VERSION=$(curl -s https://api.github.com/repos/syncthing/syncthing/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') <maxConflicts>0</maxConflicts>
ARCH=$(uname -m) <disableSparseFiles>false</disableSparseFiles>
<disableTempIndexes>false</disableTempIndexes>
case $ARCH in <paused>false</paused>
x86_64) ARCH="amd64" ;; <weakHashThresholdPct>25</weakHashThresholdPct>
aarch64) ARCH="arm64" ;; <markerName>.stfolder</markerName>
armv7l) ARCH="armv7" ;; <useLargeBlocks>false</useLargeBlocks>
*) ARCH="amd64" ;; <junctionsAsDirs>false</junctionsAsDirs>
esac <syncOwnership>false</syncOwnership>
<sendFullIndex>false</sendFullIndex>
echo "下载 Syncthing $LATEST_VERSION ($ARCH)" <caseSensitiveFS>false</caseSensitiveFS>
wget -q https://github.com/syncthing/syncthing/releases/download/${LATEST_VERSION}/syncthing-linux-${ARCH}-${LATEST_VERSION}.tar.gz <localFlags></localFlags>
tar -xzf syncthing-linux-${ARCH}-${LATEST_VERSION}.tar.gz <fsync>false</fsync>
cp syncthing-linux-${ARCH}-${LATEST_VERSION}/syncthing /usr/local/bin/ <blockPullOrder>standard</blockPullOrder>
chmod +x /usr/local/bin/syncthing <copyRangeMethod>standard</copyRangeMethod>
<modTimeWindowS>0</modTimeWindowS>
# 创建配置目录 </folder>
echo "创建配置目录..." <device id="SELF" name="$(hostname)" compression="metadata" introducer="false" skipIntroductionRemovals="false" introducedBy="">
useradd -r -s /bin/false -d /var/lib/syncthing -m syncthing 2>/dev/null || true <address>dynamic</address>
mkdir -p /var/lib/syncthing/config </device>
chown -R syncthing:syncthing /var/lib/syncthing <gui enabled="true" tls="true" debugging="false">
<address>0.0.0.0:8384</address>
# 创建正确的服务文件 <apikey>$(cat /var/lib/syncthing/config/config.xml | grep apikey | sed -n 's/.*<apikey>\(.*\)<\/apikey>.*/\1/p')</apikey>
echo "创建系统服务..." <theme>default</theme>
cat > /etc/systemd/system/syncthing.service << 'SERVICE' </gui>
[Unit] <ldap></ldap>
Description=Syncthing <options>
Documentation=man:syncthing(1) <listenAddress>default</listenAddress>
After=network.target <globalAnnounceServer>default</globalAnnounceServer>
<globalAnnounceEnabled>true</globalAnnounceEnabled>
[Service] <localAnnounceEnabled>true</localAnnounceEnabled>
User=syncthing <maxSendKbps>0</maxSendKbps>
ExecStart=/usr/local/bin/syncthing serve --no-browser --no-restart --home=/var/lib/syncthing/config <maxRecvKbps>0</maxRecvKbps>
Restart=on-failure <reconnectionIntervalS>60</reconnectionIntervalS>
RestartSec=5 <relaysEnabled>true</relaysEnabled>
SuccessExitStatus=3 4 <relayReconnectIntervalM>10</relayReconnectIntervalM>
RestartForceExitStatus=3 4 <startBrowser>false</startBrowser>
<natEnabled>true</natEnabled>
[Install] <natLeaseMinutes>60</natLeaseMinutes>
WantedBy=multi-user.target <natRenewalMinutes>30</natRenewalMinutes>
SERVICE <natTimeoutSeconds>10</natTimeoutSeconds>
<urAccepted>0</urAccepted>
# 启动服务 <urSeen>3</urSeen>
echo "启动服务..." <urUniqueID>$(cat /var/lib/syncthing/config/config.xml | grep urUniqueID | sed -n 's/.*<urUniqueID>\(.*\)<\/urUniqueID>.*/\1/p')</urUniqueID>
systemctl daemon-reload <urURL>https://data.syncthing.net/</urURL>
systemctl enable syncthing <urPostInsecurely>false</urPostInsecurely>
systemctl start syncthing <urInitialDelayS>1800</urInitialDelayS>
<restartOnWakeup>true</restartOnWakeup>
sleep 3 <autoUpgradeIntervalH>12</autoUpgradeIntervalH>
<upgradeToPreReleases>false</upgradeToPreReleases>
if systemctl is-active --quiet syncthing; then <keepTemporariesH>24</keepTemporariesH>
echo "✓ Syncthing 服务启动成功" <cacheIgnoredFiles>false</cacheIgnoredFiles>
else <progressUpdateIntervalS>5</progressUpdateIntervalS>
echo "查看服务状态..." <limitBandwidthInLan>false</limitBandwidthInLan>
systemctl status syncthing -l --no-pager <minHomeDiskFree unit="%">1</minHomeDiskFree>
echo "尝试手动启动..." <releasesURL>https://upgrades.syncthing.net/meta.json</releasesURL>
sudo -u syncthing /usr/local/bin/syncthing -generate="/var/lib/syncthing/config" <overwriteRemoteDeviceNamesOnConnect>false</overwriteRemoteDeviceNamesOnConnect>
systemctl start syncthing <tempIndexMinBlocks>10</tempIndexMinBlocks>
fi <unackedNotificationID>authenticationUserAndPassword</unackedNotificationID>
<trafficClass>0</trafficClass>
# 显示信息 <defaultFolderPath>/var/lib/syncthing/sync</defaultFolderPath>
echo "" <setLowPriority>true</setLowPriority>
echo "========================================" <minHomeDiskFree unit="%">1</minHomeDiskFree>
echo " Syncthing 安装完成!" <crashReportingEnabled>false</crashReportingEnabled>
echo "========================================" <stunKeepaliveStartS>0</stunKeepaliveStartS>
IP=$(hostname -I | awk '{print $1}') <stunKeepaliveMinS>0</stunKeepaliveMinS>
echo "访问地址: https://$IP:8384" <stunServer>default</stunServer>
echo "" <databaseTuning>auto</databaseTuning>
echo "管理命令:" <maxConcurrentIncomingRequestKiB>0</maxConcurrentIncomingRequestKiB>
echo " systemctl start syncthing" <announceLANAddresses>true</announceLANAddresses>
echo " systemctl stop syncthing" <sendFullIndexOnUpgrade>false</sendFullIndexOnUpgrade>
echo " systemctl restart syncthing" <featureFlags></featureFlags>
echo " systemctl status syncthing" <connectionLimitEnough>0</connectionLimitEnough>
echo "" <connectionLimitMax>0</connectionLimitMax>
echo "查看运行状态:" <insecureAllowOldTLSVersions>false</insecureAllowOldTLSVersions>
systemctl status syncthing --no-pager -l </options>
</configuration>
EOF EOF
chmod +x fix-syncthing-install.sh chown -R syncthing:syncthing /var/lib/syncthing/config
./fix-syncthing-install.sh systemctl start syncthing