🐛 fix(core): 容忍 Cask 升级时的瞬时下载失败并优化错误校验逻辑
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Homebrew 智能升级脚本(强制 Cask 更新增强版 v5.3 - 移除 sudo 密码注入)
|
||||
# Homebrew 智能升级脚本(强制 Cask 更新增强版 v5.4 - 容忍 Cask 瞬时下载失败)
|
||||
|
||||
# ================== 脚本环境设置 ==================
|
||||
|
||||
@@ -46,6 +46,31 @@ terminal_width() {
|
||||
separator() { local width; width=$(terminal_width); printf '=%.0s' $(seq 1 "$width"); printf "\n"; }
|
||||
print_header() { echo -e "${BLUE}$1${NC}"; }
|
||||
|
||||
run_cask_upgrade() {
|
||||
local status=0 outdated_casks
|
||||
|
||||
brew upgrade --cask --greedy --force || status=$?
|
||||
if [[ "$status" -eq 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}Warning: Cask upgrade reported a non-zero exit code (${status}). Verifying whether outdated casks remain...${NC}"
|
||||
|
||||
if ! outdated_casks="$(brew outdated --cask --greedy 2>/dev/null)"; then
|
||||
echo -e "${YELLOW}Warning: Unable to verify outdated casks after the failed upgrade command.${NC}"
|
||||
return "$status"
|
||||
fi
|
||||
|
||||
if [[ -z "$outdated_casks" ]]; then
|
||||
echo -e "${YELLOW}Warning: No outdated casks remain. Treating the previous Cask error as transient and continuing.${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}The following casks still appear to be outdated:${NC}"
|
||||
printf '%s\n' "$outdated_casks"
|
||||
return "$status"
|
||||
}
|
||||
|
||||
# ================== 流程开始 ==================
|
||||
separator
|
||||
|
||||
@@ -94,7 +119,7 @@ export HOMEBREW_COLOR=1
|
||||
export COLUMNS
|
||||
COLUMNS="$(terminal_width)"
|
||||
|
||||
brew upgrade --cask --greedy --force
|
||||
run_cask_upgrade
|
||||
|
||||
separator
|
||||
printf "\n"
|
||||
|
||||
Reference in New Issue
Block a user