Files
karuo-ai/01_卡资(金)/金仓_存储备份/Codex版本锁定/脚本/codex_pin_version.sh
2026-07-19 00:21:46 +08:00

85 lines
3.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Codex 版本锁定:从 GitHub 下载指定旧版并禁止自动升级
# 用法: bash codex_pin_version.sh [版本tag默认 rust-v0.135.0]
set -euo pipefail
TAG="${1:-rust-v0.135.0}"
ARCH="$(uname -m)"
PIN_ROOT="${HOME}/Documents/卡若Ai的文件夹/1、金_资产存储/备份/系统"
PIN_DIR="${PIN_ROOT}/codex_pin_${TAG#rust-v}"
BACKUP_APP="${PIN_ROOT}/codex_full_reset_20260528/Codex.app"
CONFIG="${HOME}/.codex/config.toml"
if [[ "${ARCH}" != "arm64" ]]; then
echo "当前脚本仅验证过 Apple Silicon (arm64)" >&2
exit 1
fi
mkdir -p "${PIN_DIR}"
cd "${PIN_DIR}"
if [[ ! -f codex-aarch64-apple-darwin.tar.gz ]]; then
echo "▸ 从 GitHub 下载 ${TAG} ..."
gh release download "${TAG}" -R openai/codex \
-p 'codex-aarch64-apple-darwin.tar.gz' \
-p 'codex-package-aarch64-apple-darwin.tar.gz' \
--clobber
fi
tar -xzf codex-aarch64-apple-darwin.tar.gz
echo "▸ 退出 Codex ..."
osascript -e 'tell application "Codex" to quit' 2>/dev/null || true
sleep 3
pgrep -x Codex >/dev/null && killall Codex 2>/dev/null || true
sleep 2
echo "▸ 备份当前安装 ..."
rm -rf "${PIN_DIR}/Codex.app.before_downgrade"
[[ -d /Applications/Codex.app ]] && cp -a /Applications/Codex.app "${PIN_DIR}/Codex.app.before_downgrade"
[[ -f /usr/local/bin/codex ]] && cp -a /usr/local/bin/codex "${PIN_DIR}/codex.before_downgrade" || true
echo "▸ 安装桌面版5 月备份包,与 0.135.0 同期)..."
chflags -R nouchg /Applications/Codex.app 2>/dev/null || true
chflags nouchg /usr/local/bin/codex 2>/dev/null || true
rm -rf /Applications/Codex.app
cp -a "${BACKUP_APP}" /Applications/Codex.app
echo "▸ 修复 Gatekeeper清除隔离 + 重签名)..."
xattr -cr /Applications/Codex.app
codesign --force --deep --sign - /Applications/Codex.app >/dev/null
echo "▸ 安装 CLI随 App 内嵌,/usr/local/bin/codex 为符号链接)..."
# App 内已含匹配版本 CLI仅当 /usr/local/bin/codex 为独立文件时才覆盖
if [[ -L /usr/local/bin/codex ]] || [[ ! -f /usr/local/bin/codex ]]; then
ln -sf /Applications/Codex.app/Contents/Resources/codex /usr/local/bin/codex
else
cp -a "${PIN_DIR}/codex-aarch64-apple-darwin" /usr/local/bin/codex
chmod +x /usr/local/bin/codex
chflags uchg /usr/local/bin/codex
fi
echo "▸ 锁定 App 防覆盖升级 ..."
chflags -R uchg /Applications/Codex.app
echo "▸ 关闭 CLI 启动更新检查 ..."
BLOCK_SCRIPT="$(dirname "$0")/codex_block_updates.sh"
if [[ -x "${BLOCK_SCRIPT}" ]]; then
# 仅 config + Sparkle + 锁hosts 需本机 sudo
bash "${BLOCK_SCRIPT}" on 2>/dev/null || true
else
if ! grep -q '^check_for_update_on_startup' "${CONFIG}" 2>/dev/null; then
printf 'check_for_update_on_startup = false\n\n' | cat - "${CONFIG}" > "${CONFIG}.tmp" && mv "${CONFIG}.tmp" "${CONFIG}"
else
sed -i '' 's/^check_for_update_on_startup.*/check_for_update_on_startup = false/' "${CONFIG}"
fi
defaults write com.openai.codex SUEnableAutomaticChecks -bool false 2>/dev/null || true
defaults write com.openai.codex SUAutomaticallyUpdate -bool false 2>/dev/null || true
chflags -R uchg /Applications/Codex.app
fi
echo "✅ 完成"
defaults read /Applications/Codex.app/Contents/Info.plist CFBundleShortVersionString
codex --version
echo "解锁升级: chflags -R nouchg /Applications/Codex.app && chflags nouchg /usr/local/bin/codex"