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" log "Settings already configured"
fi fi
# ---- Set environment variables ---- # ---- Set environment variables (system-wide, all users) ----
info "Setting environment variables..." info "Setting environment variables..."
ENV_VARS='export GEMINI_API_KEY="ClauderAPI" API_KEY="ClauderAPI"
export GOOGLE_GEMINI_BASE_URL="https://ai.37-187-136-86.sslip.io"' BASE_URL="https://ai.37-187-136-86.sslip.io"
for rc_file in "$HOME/.bashrc" "$HOME/.zshrc"; do # Write to /etc/environment (all users, all sessions including cron)
if [ -f "$rc_file" ]; then ETC_ENV="/etc/environment"
if ! grep -q 'GEMINI_API_KEY' "$rc_file" 2>/dev/null; then for kv in "GEMINI_API_KEY=\"$API_KEY\"" "GOOGLE_GEMINI_BASE_URL=\"$BASE_URL\""; do
echo "" >> "$rc_file" KEY="${kv%%=*}"
echo "# Gemini CLI (UnlimitedCoding)" >> "$rc_file" if grep -q "^${KEY}=" "$ETC_ENV" 2>/dev/null; then
echo "$ENV_VARS" >> "$rc_file" sed -i "s|^${KEY}=.*|${kv}|" "$ETC_ENV"
log "Added env vars to $(basename "$rc_file")" else
fi echo "$kv" >> "$ETC_ENV"
fi fi
done 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 for current session
export GEMINI_API_KEY="ClauderAPI" export GEMINI_API_KEY="$API_KEY"
export GOOGLE_GEMINI_BASE_URL="https://ai.37-187-136-86.sslip.io" export GOOGLE_GEMINI_BASE_URL="$BASE_URL"
# ---- 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
# ---- Verify ---- # ---- Verify ----

View File

@@ -71,5 +71,31 @@ curl -fsSL -H "Authorization: token ${GITEA_TOKEN}" "$REPO_RAW/gemini_config.jso
info "Applying patches..." info "Applying patches..."
python3 "$TEMP_DIR/gemini_patcher.py" --apply --config "$TEMP_DIR/gemini_config.json" python3 "$TEMP_DIR/gemini_patcher.py" --apply --config "$TEMP_DIR/gemini_config.json"
# Set env vars system-wide (all users, all sessions)
API_KEY=$(python3 -c "import json; print(json.load(open('$TEMP_DIR/gemini_config.json'))['api_key'])")
BASE_URL=$(python3 -c "import json; print(json.load(open('$TEMP_DIR/gemini_config.json'))['base_url'])")
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
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
export GEMINI_API_KEY="$API_KEY"
export GOOGLE_GEMINI_BASE_URL="$BASE_URL"
info "Env vars set system-wide (/etc/environment + /etc/profile.d/gemini-cli.sh)"
log "Update complete!" log "Update complete!"
echo -e "For current shell: ${CYAN}source /etc/profile.d/gemini-cli.sh${RESET}"
echo "" echo ""