From b5a6cdce966b38b8156fc9b337044374d480d651 Mon Sep 17 00:00:00 2001 From: LamGC Date: Wed, 29 Oct 2025 17:56:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20curl=20=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=90=8E=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf-sshd.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/conf-sshd.sh b/conf-sshd.sh index de97ccf..0012339 100755 --- a/conf-sshd.sh +++ b/conf-sshd.sh @@ -292,14 +292,27 @@ if [ "$(has_param "-c" "--cron")" == "true" ]; then # 将当前脚本移动到 ~/.conf-sshd/conf-sshd.sh 中. mkdir -p ~/.conf-sshd # 检查当前脚本是否为文件 + target_script=~/.conf-sshd/conf-sshd.sh if [ ! -f "$0" ]; then echo "Downloading conf-sshd script..." - curl -oL ~/.conf-sshd/conf-sshd.sh "$script_url" + + # 修复:使用与 --update-self 相同的健壮下载逻辑 + # 1. 下载到临时文件 + if ! curl -sL "$script_url" -o "$target_script.tmp"; then + echo "Script download failed at $(date '+%Y-%m-%d %H:%M:%S')" + rm -f "$target_script.tmp" + exit 1 + fi + + # 2. 原子替换 + mv "$target_script.tmp" "$target_script" + else echo "Copying conf-sshd script..." - cp "$0" ~/.conf-sshd/conf-sshd.sh + cp "$0" "$target_script" fi - chmod +x ~/.conf-sshd/conf-sshd.sh + + chmod +x "$target_script" echo "Install conf-sshd script successfully." # 将当前脚本追加到当前用户的 Crontab 中 echo "Configuring Crontab..."