- 旧版在钩子里同步 curl,大文件在慢链路上会被钩子超时杀掉,留下半截+锁 - 改为经 ShellExecute 启动隐藏 PowerShell 后台下载(脱离钩子进程),钩子毫秒级返回 - download.ps1 用 curl 下载、原子改名、清锁;纯 ASCII 避免 PowerShell 5.1 按 GBK 误读
25 lines
990 B
Bash
25 lines
990 B
Bash
#!/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" "$@"
|