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:
@@ -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 ----
|
||||
|
||||
|
||||
@@ -71,5 +71,31 @@ curl -fsSL -H "Authorization: token ${GITEA_TOKEN}" "$REPO_RAW/gemini_config.jso
|
||||
info "Applying patches..."
|
||||
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!"
|
||||
echo -e "For current shell: ${CYAN}source /etc/profile.d/gemini-cli.sh${RESET}"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user