更新 hy2.sh

This commit is contained in:
2026-03-19 15:22:12 +08:00
parent 86efd98624
commit d105b46d68

38
hy2.sh
View File

@@ -66,18 +66,50 @@ get_public_ips() {
printf '%s|%s\n' "$ipv4" "$ipv6"
}
wait_for_apt_lock() {
local timeout="${1:-300}"
local waited=0
while pgrep -x apt >/dev/null 2>&1 \
|| pgrep -x apt-get >/dev/null 2>&1 \
|| pgrep -x dpkg >/dev/null 2>&1 \
|| pgrep -f unattended-upgrades >/dev/null 2>&1; do
if (( waited == 0 )); then
yellow "检测到 APT/DPKG 正被其他进程占用,正在等待..."
ps -ef | grep -E 'apt|apt-get|dpkg|unattended' | grep -v grep || true
fi
if (( waited >= timeout )); then
red "等待 APT 锁超时(${timeout} 秒)。"
if confirm_yn "是否继续等待?"; then
waited=0
else
return 1
fi
fi
sleep 2
waited=$((waited + 2))
done
return 0
}
apt_update_and_install_base() {
if ! confirm_yn "即将执行 apt update 并安装基础依赖 curl sed ufw jq openssl是否继续"; then
if ! confirm_yn "即将执行 apt update 并安装基础依赖 curl sed ufw openssl是否继续"; then
red "已取消。"
exit 1
fi
blue "==> 更新 APT 软件库"
export DEBIAN_FRONTEND=noninteractive
blue "==> 更新 APT 软件库"
wait_for_apt_lock 300 || { red "APT 被占用,无法继续。"; exit 1; }
apt update -y
blue "==> 安装基础依赖"
apt install -y curl sed ufw jq openssl
wait_for_apt_lock 300 || { red "APT 被占用,无法继续。"; exit 1; }
apt install -y curl sed ufw openssl
}
disable_existing_firewalls() {