fix(gemini): system-wide env vars via /etc/environment + /etc/profile.d/

Install and update scripts now:
- Write GEMINI_API_KEY + GOOGLE_GEMINI_BASE_URL to /etc/environment (all users)
- Create /etc/profile.d/gemini-cli.sh for login shell export (all users)
- Export for current session
- Update script now also sets env vars (was missing entirely)
- Removed per-user ~/.bashrc approach — system-wide is more reliable

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
delta-cloud-208e
2026-03-08 10:35:51 +00:00
parent b7c72793fe
commit 8dd87dcab3
2 changed files with 123 additions and 101 deletions

View File

@@ -190,39 +190,35 @@ else
log "Settings already configured"
fi
# ---- Set environment variables ----
# ---- Set environment variables (system-wide, all users) ----
info "Setting environment variables..."
ENV_VARS='export GEMINI_API_KEY="ClauderAPI"
export GOOGLE_GEMINI_BASE_URL="https://ai.37-187-136-86.sslip.io"'
API_KEY="ClauderAPI"
BASE_URL="https://ai.37-187-136-86.sslip.io"
for rc_file in "$HOME/.bashrc" "$HOME/.zshrc"; do
if [ -f "$rc_file" ]; then
if ! grep -q 'GEMINI_API_KEY' "$rc_file" 2>/dev/null; then
echo "" >> "$rc_file"
echo "# Gemini CLI (UnlimitedCoding)" >> "$rc_file"
echo "$ENV_VARS" >> "$rc_file"
log "Added env vars to $(basename "$rc_file")"
fi
# Write to /etc/environment (all users, all sessions including cron)
ETC_ENV="/etc/environment"
for kv in "GEMINI_API_KEY=\"$API_KEY\"" "GOOGLE_GEMINI_BASE_URL=\"$BASE_URL\""; 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
log "Env vars written to $ETC_ENV (all users)"
# Write to /etc/profile.d/ for export in login shells
cat > /etc/profile.d/gemini-cli.sh << PROF_EOF
export GEMINI_API_KEY="$API_KEY"
export GOOGLE_GEMINI_BASE_URL="$BASE_URL"
PROF_EOF
chmod 644 /etc/profile.d/gemini-cli.sh
log "Export script created: /etc/profile.d/gemini-cli.sh"
# Export for current session
export GEMINI_API_KEY="ClauderAPI"
export GOOGLE_GEMINI_BASE_URL="https://ai.37-187-136-86.sslip.io"
# ---- Also set for other users ----
if [ "$(id -u)" -eq 0 ]; then
PROFILE_D="/etc/profile.d/gemini-cli.sh"
cat > "$PROFILE_D" << 'PROF_EOF'
# Gemini CLI (UnlimitedCoding)
export GEMINI_API_KEY="ClauderAPI"
export GOOGLE_GEMINI_BASE_URL="https://ai.37-187-136-86.sslip.io"
PROF_EOF
chmod 644 "$PROFILE_D"
log "Set env vars for all users: $PROFILE_D"
fi
export GEMINI_API_KEY="$API_KEY"
export GOOGLE_GEMINI_BASE_URL="$BASE_URL"
# ---- Verify ----