- Replace grep -oP (Perl regex) with portable sed — fixes "grep: invalid option -- P" on macOS - Add sedi() wrapper for cross-platform sed -i (BSD vs GNU) - Detect macOS via uname and use apple-darwin binary suffix instead of linux-musl - Add is_native_binary() helper: checks both ELF (Linux) and Mach-O (macOS) - macOS env vars: use launchctl setenv + /etc/codex-env.sh + ~/.zshrc source line - Linux env vars: keep /etc/environment + /etc/profile.d/ as before - Wrapper script uses dynamic ENV_FILE path instead of hardcoded /etc/profile.d/ - Fix SUDO_USER handling for correct ~/.zshrc path when run via sudo - Uninstaller: also remove .codex-bin, /etc/codex-env.sh, launchctl vars, rc file entries - Uninstaller: scan /Users/* on macOS instead of /home/* - Fix CRLF line endings in ucodex_uninstall.sh Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
129 lines
3.3 KiB
Bash
Executable File
129 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Codex CLI — Uninstaller
|
|
# Removes Codex CLI binary, config, env vars.
|
|
#
|
|
# Usage: sudo bash ucodex_uninstall.sh
|
|
set -euo pipefail
|
|
|
|
OS="$(uname -s)"
|
|
IS_MACOS=false
|
|
[ "$OS" = "Darwin" ] && IS_MACOS=true
|
|
|
|
# Cross-platform sed -i
|
|
sedi() {
|
|
if $IS_MACOS; then
|
|
sed -i '' "$@"
|
|
else
|
|
sed -i "$@"
|
|
fi
|
|
}
|
|
|
|
GREEN="\033[92m"
|
|
CYAN="\033[96m"
|
|
YELLOW="\033[93m"
|
|
BOLD="\033[1m"
|
|
RESET="\033[0m"
|
|
|
|
log() { echo -e "${GREEN}[+]${RESET} $*"; }
|
|
warn() { echo -e "${YELLOW}[~]${RESET} $*"; }
|
|
info() { echo -e "${CYAN}[i]${RESET} $*"; }
|
|
|
|
echo -e "${BOLD}"
|
|
echo " +--------------------------------------+"
|
|
echo " | Codex CLI — Uninstaller |"
|
|
echo " +--------------------------------------+"
|
|
echo -e "${RESET}"
|
|
|
|
# ---- Remove binary ----
|
|
|
|
CODEX_PATH=$(command -v codex 2>/dev/null || echo "")
|
|
if [ -n "$CODEX_PATH" ]; then
|
|
info "Removing wrapper: $CODEX_PATH"
|
|
rm -f "$CODEX_PATH"
|
|
log "Wrapper removed"
|
|
else
|
|
warn "Codex wrapper not found in PATH"
|
|
fi
|
|
|
|
# Also remove the hidden binary
|
|
if [ -f "/usr/local/bin/.codex-bin" ]; then
|
|
info "Removing binary: /usr/local/bin/.codex-bin"
|
|
rm -f "/usr/local/bin/.codex-bin"
|
|
log "Binary removed"
|
|
fi
|
|
|
|
# ---- Determine user home directories ----
|
|
|
|
if $IS_MACOS; then
|
|
_home_dirs=(/Users/*)
|
|
else
|
|
_home_dirs=(/root /home/*)
|
|
fi
|
|
|
|
# ---- Remove config ----
|
|
|
|
for user_home in "${_home_dirs[@]}"; do
|
|
CODEX_DIR="$user_home/.codex"
|
|
if [ -d "$CODEX_DIR" ]; then
|
|
info "Removing $CODEX_DIR..."
|
|
rm -rf "$CODEX_DIR"
|
|
log "Removed $CODEX_DIR"
|
|
fi
|
|
done
|
|
|
|
# ---- Remove env vars from shell rc files ----
|
|
|
|
for user_home in "${_home_dirs[@]}"; do
|
|
for rc_file in "$user_home/.bashrc" "$user_home/.zshrc"; do
|
|
if [ -f "$rc_file" ] && grep -q 'OPENAI_API_KEY\|OPENAI_BASE_URL\|Codex' "$rc_file" 2>/dev/null; then
|
|
info "Cleaning env vars from $rc_file..."
|
|
sedi '/# Codex/d' "$rc_file"
|
|
sedi '/# UnlimitedCoding.*[Cc]odex/d' "$rc_file"
|
|
sedi '/OPENAI_API_KEY/d' "$rc_file"
|
|
sedi '/OPENAI_BASE_URL/d' "$rc_file"
|
|
log "Cleaned $rc_file"
|
|
fi
|
|
done
|
|
done
|
|
|
|
# ---- Remove env vars from /etc/environment ----
|
|
|
|
if [ -f "/etc/environment" ] && grep -q 'OPENAI_API_KEY\|OPENAI_BASE_URL' /etc/environment 2>/dev/null; then
|
|
info "Cleaning /etc/environment..."
|
|
sedi '/OPENAI_API_KEY/d' /etc/environment
|
|
sedi '/OPENAI_BASE_URL/d' /etc/environment
|
|
log "Cleaned /etc/environment"
|
|
fi
|
|
|
|
# ---- Remove env file and profile.d scripts ----
|
|
|
|
for envf in "/etc/profile.d/codex-cli.sh" "/etc/profile.d/codex-env.sh" "/etc/codex-env.sh"; do
|
|
if [ -f "$envf" ]; then
|
|
rm -f "$envf"
|
|
log "Removed $envf"
|
|
fi
|
|
done
|
|
|
|
# ---- macOS: unset launchctl env vars ----
|
|
|
|
if $IS_MACOS; then
|
|
launchctl unsetenv OPENAI_API_KEY 2>/dev/null || true
|
|
launchctl unsetenv OPENAI_BASE_URL 2>/dev/null || true
|
|
log "Unset launchctl env vars"
|
|
fi
|
|
|
|
# ---- Clean codex-env.sh source lines from rc files ----
|
|
|
|
for user_home in "${_home_dirs[@]}"; do
|
|
for rc_file in "$user_home/.bashrc" "$user_home/.zshrc"; do
|
|
if [ -f "$rc_file" ] && grep -q 'codex-env\.sh' "$rc_file" 2>/dev/null; then
|
|
sedi '/codex-env\.sh/d' "$rc_file"
|
|
log "Cleaned codex-env source from $rc_file"
|
|
fi
|
|
done
|
|
done
|
|
|
|
echo ""
|
|
echo -e "${GREEN}${BOLD} Codex CLI fully uninstalled!${RESET}"
|
|
echo ""
|