#!/bin/sh # ============================================================ # 下载地址(首次运行从这里拉取 notify.exe)—— 按需修改 DOWNLOAD_URL="https://git.pchuan.top/cc-tools/notify/releases/download/v1.0.0/notify.exe" # ============================================================ DIR="$(cd "$(dirname "$0")" && pwd)" BIN="$DIR/../bin" EXE="$BIN/notify.exe" LOCK="$BIN/notify.download.lock" # 首次运行:后台下载,不阻塞钩子 if [ ! -f "$EXE" ]; then mkdir -p "$BIN" 2>/dev/null # mkdir 原子:成功=本进程负责下载,失败=已有进程在下 if mkdir "$LOCK" 2>/dev/null; then TMP="$EXE.downloading" # nohup + & 让下载脱离钩子在后台跑;完成后原子改名并清锁 nohup sh -c "curl -fsSL '$DOWNLOAD_URL' -o '$TMP' && mv -f '$TMP' '$EXE'; rmdir '$LOCK' 2>/dev/null" >/dev/null 2>&1 & fi fi # 本次不等下载;exe 就绪后才转发参数与 stdin [ -f "$EXE" ] && exec "$EXE" "$@"