- Write OPENAI_API_KEY and OPENAI_BASE_URL to /etc/environment (all users) - Create /etc/profile.d/codex-env.sh for login shell export (all users) - Export for current session too - Removes per-user ~/.bashrc approach — system-wide is more reliable Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
96 lines
3.3 KiB
Bash
Executable File
96 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# UnlimitedCoding — Codex CLI Installer
|
|
# Downloads Codex binary from GitHub + applies config patches
|
|
#
|
|
# Usage:
|
|
# curl -fsSL https://git.sensey24.ru/.../ucodex_install.sh | sudo bash
|
|
|
|
set -e
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
CYAN='\033[0;36m'
|
|
BOLD='\033[1m'
|
|
NC='\033[0m'
|
|
|
|
echo -e "${BOLD}=== UnlimitedCoding — Codex CLI Installer ===${NC}"
|
|
|
|
# Check prerequisites
|
|
for cmd in python3 curl; do
|
|
if ! command -v "$cmd" &>/dev/null; then
|
|
echo -e "${RED}Error: $cmd is required but not found${NC}"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Check Python version (need 3.11+ for tomllib)
|
|
PY_VER=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
|
|
PY_MAJOR=$(echo "$PY_VER" | cut -d. -f1)
|
|
PY_MINOR=$(echo "$PY_VER" | cut -d. -f2)
|
|
if [ "$PY_MAJOR" -lt 3 ] || ([ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 11 ]); then
|
|
echo -e "${RED}Error: Python 3.11+ required (found $PY_VER)${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Step 1: Install/update Codex binary
|
|
echo -e "\n${BOLD}Step 1: Installing Codex CLI binary...${NC}"
|
|
if [ -f "$SCRIPT_DIR/update-codex.sh" ]; then
|
|
bash "$SCRIPT_DIR/update-codex.sh"
|
|
else
|
|
echo -e "${RED}update-codex.sh not found${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Step 2: Apply config patches
|
|
echo -e "\n${BOLD}Step 2: Applying config patches...${NC}"
|
|
if [ ! -f "$SCRIPT_DIR/codex_config.json" ]; then
|
|
echo -e "${YELLOW}codex_config.json not found, copying example...${NC}"
|
|
cp "$SCRIPT_DIR/codex_config.example.json" "$SCRIPT_DIR/codex_config.json"
|
|
echo -e "${YELLOW}Edit codex_config.json with your API endpoint and key, then re-run.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
python3 "$SCRIPT_DIR/codex_patcher.py" --apply --config "$SCRIPT_DIR/codex_config.json"
|
|
|
|
# Step 3: Set env vars system-wide (all users, all 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'])")
|
|
|
|
# Write to /etc/environment (system-wide, all users)
|
|
ETC_ENV="/etc/environment"
|
|
for kv in "OPENAI_API_KEY=\"$API_KEY\"" "OPENAI_BASE_URL=\"${BASE_URL}/v1\""; do
|
|
KEY="${kv%%=*}"
|
|
if grep -q "^${KEY}=" "$ETC_ENV" 2>/dev/null; then
|
|
sed -i "s|^${KEY}=.*|${kv}|" "$ETC_ENV"
|
|
else
|
|
echo "$kv" >> "$ETC_ENV"
|
|
fi
|
|
done
|
|
echo -e " ${GREEN}Env vars written to $ETC_ENV (all users)${NC}"
|
|
|
|
# Also write to /etc/profile.d/ so vars are exported in login shells
|
|
cat > /etc/profile.d/codex-env.sh << ENVEOF
|
|
export OPENAI_API_KEY="$API_KEY"
|
|
export OPENAI_BASE_URL="${BASE_URL}/v1"
|
|
ENVEOF
|
|
chmod 644 /etc/profile.d/codex-env.sh
|
|
echo -e " ${GREEN}Export script created: /etc/profile.d/codex-env.sh${NC}"
|
|
|
|
# Export for current session too
|
|
export OPENAI_API_KEY="$API_KEY"
|
|
export OPENAI_BASE_URL="${BASE_URL}/v1"
|
|
|
|
# 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"
|
|
echo -e "${YELLOW}Note: Env vars are set system-wide. New shells will pick them up automatically.${NC}"
|
|
echo -e "${YELLOW}For current shell: source /etc/profile.d/codex-env.sh${NC}"
|