fix(codex): set OPENAI_API_KEY in shell profile + current session
Install/update scripts now: - Export env vars for current session (fixes "Missing OPENAI_API_KEY") - Write to ~/.bashrc or ~/.zshrc for persistence - Handle sudo (detect real user via SUDO_USER) - Remove stale entries before writing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -55,9 +55,50 @@ fi
|
||||
|
||||
python3 "$SCRIPT_DIR/codex_patcher.py" --apply --config "$SCRIPT_DIR/codex_config.json"
|
||||
|
||||
# Step 3: Validate
|
||||
echo -e "\n${BOLD}Step 3: Validating...${NC}"
|
||||
# Step 3: Set env vars for current and future sessions
|
||||
echo -e "\n${BOLD}Step 3: Setting environment variables...${NC}"
|
||||
|
||||
API_KEY=$(python3 -c "import json; print(json.load(open('$SCRIPT_DIR/codex_config.json'))['api_key'])")
|
||||
BASE_URL=$(python3 -c "import json; print(json.load(open('$SCRIPT_DIR/codex_config.json'))['base_url'])")
|
||||
|
||||
# Export for current session
|
||||
export OPENAI_API_KEY="$API_KEY"
|
||||
export OPENAI_BASE_URL="${BASE_URL}/v1"
|
||||
|
||||
# Determine real user (even when running under sudo)
|
||||
REAL_USER="${SUDO_USER:-$USER}"
|
||||
REAL_HOME=$(eval echo "~$REAL_USER")
|
||||
|
||||
# Write to user's shell profile for persistence
|
||||
PROFILE=""
|
||||
if [ -f "$REAL_HOME/.bashrc" ]; then
|
||||
PROFILE="$REAL_HOME/.bashrc"
|
||||
elif [ -f "$REAL_HOME/.zshrc" ]; then
|
||||
PROFILE="$REAL_HOME/.zshrc"
|
||||
elif [ -f "$REAL_HOME/.profile" ]; then
|
||||
PROFILE="$REAL_HOME/.profile"
|
||||
fi
|
||||
|
||||
if [ -n "$PROFILE" ]; then
|
||||
# Remove old entries if present
|
||||
sed -i '/^export OPENAI_API_KEY=/d' "$PROFILE" 2>/dev/null || true
|
||||
sed -i '/^export OPENAI_BASE_URL=/d' "$PROFILE" 2>/dev/null || true
|
||||
# Add new entries
|
||||
echo "export OPENAI_API_KEY=\"$API_KEY\"" >> "$PROFILE"
|
||||
echo "export OPENAI_BASE_URL=\"${BASE_URL}/v1\"" >> "$PROFILE"
|
||||
echo -e " ${GREEN}Env vars written to $PROFILE${NC}"
|
||||
else
|
||||
echo -e " ${YELLOW}No shell profile found. Add manually:${NC}"
|
||||
echo -e " export OPENAI_API_KEY=\"$API_KEY\""
|
||||
echo -e " export OPENAI_BASE_URL=\"${BASE_URL}/v1\""
|
||||
fi
|
||||
|
||||
# Step 4: Validate
|
||||
echo -e "\n${BOLD}Step 4: Validating...${NC}"
|
||||
python3 "$SCRIPT_DIR/update_codex_patcher.py" --validate
|
||||
|
||||
echo -e "\n${GREEN}=== Installation complete! ===${NC}"
|
||||
echo -e "Run: ${CYAN}codex${NC} to start"
|
||||
if [ -n "$PROFILE" ]; then
|
||||
echo -e "${YELLOW}Note: Run 'source $PROFILE' or restart shell for env vars to take effect.${NC}"
|
||||
fi
|
||||
|
||||
@@ -99,5 +99,29 @@ curl -fsSL -H "Authorization: token ${GITEA_TOKEN}" "$REPO_RAW/codex_config.json
|
||||
info "Applying patches..."
|
||||
python3 "$PATCH_DIR/codex_patcher.py" --apply --config "$PATCH_DIR/codex_config.json"
|
||||
|
||||
# Ensure env vars are set for current and future sessions
|
||||
API_KEY=$(python3 -c "import json; print(json.load(open('$PATCH_DIR/codex_config.json'))['api_key'])")
|
||||
BASE_URL=$(python3 -c "import json; print(json.load(open('$PATCH_DIR/codex_config.json'))['base_url'])")
|
||||
export OPENAI_API_KEY="$API_KEY"
|
||||
export OPENAI_BASE_URL="${BASE_URL}/v1"
|
||||
|
||||
REAL_USER="${SUDO_USER:-$USER}"
|
||||
REAL_HOME=$(eval echo "~$REAL_USER")
|
||||
PROFILE=""
|
||||
if [ -f "$REAL_HOME/.bashrc" ]; then
|
||||
PROFILE="$REAL_HOME/.bashrc"
|
||||
elif [ -f "$REAL_HOME/.zshrc" ]; then
|
||||
PROFILE="$REAL_HOME/.zshrc"
|
||||
elif [ -f "$REAL_HOME/.profile" ]; then
|
||||
PROFILE="$REAL_HOME/.profile"
|
||||
fi
|
||||
if [ -n "$PROFILE" ]; then
|
||||
sed -i '/^export OPENAI_API_KEY=/d' "$PROFILE" 2>/dev/null || true
|
||||
sed -i '/^export OPENAI_BASE_URL=/d' "$PROFILE" 2>/dev/null || true
|
||||
echo "export OPENAI_API_KEY=\"$API_KEY\"" >> "$PROFILE"
|
||||
echo "export OPENAI_BASE_URL=\"${BASE_URL}/v1\"" >> "$PROFILE"
|
||||
info "Env vars written to $PROFILE"
|
||||
fi
|
||||
|
||||
log "Update complete!"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user