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 ----

View File

@@ -1,75 +1,101 @@
#!/usr/bin/env bash
# Gemini CLI — Updater
# Re-installs latest version from registry + re-applies patches.
#
# Usage: sudo bash ugemini_update.sh
# Or: curl -fsSL URL -o /tmp/ugemini_update.sh && sudo bash /tmp/ugemini_update.sh
set -euo pipefail
REGISTRY_URL="https://npm.sensey24.ru/"
NPM_SCOPE="@google"
NPM_PACKAGE="@google/gemini-cli"
REPO_RAW="https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/gemini"
GREEN="\033[92m"
CYAN="\033[96m"
YELLOW="\033[93m"
RED="\033[91m"
BOLD="\033[1m"
RESET="\033[0m"
log() { echo -e "${GREEN}[+]${RESET} $*"; }
info() { echo -e "${CYAN}[i]${RESET} $*"; }
warn() { echo -e "${YELLOW}[~]${RESET} $*"; }
err() { echo -e "${RED}[!]${RESET} $*" >&2; }
echo -e "${BOLD}"
echo " +--------------------------------------+"
echo " | Gemini CLI — Updater |"
echo " +--------------------------------------+"
echo -e "${RESET}"
# ---- Check current version ----
OLD_VER=""
if command -v gemini &>/dev/null; then
OLD_VER=$(gemini --version 2>/dev/null || echo "unknown")
info "Current version: $OLD_VER"
else
warn "Gemini CLI not found. Will install fresh."
fi
# ---- Configure npm registry ----
info "Configuring npm registry: ${REGISTRY_URL}"
npm config set "${NPM_SCOPE}:registry" "${REGISTRY_URL}" 2>/dev/null || true
# ---- Update package ----
info "Installing latest ${NPM_PACKAGE}..."
if npm install -g "${NPM_PACKAGE}" 2>&1; then
log "Package updated"
else
err "npm install failed. Try: npm config set ${NPM_SCOPE}:registry http://npm.sensey24.ru/"
exit 1
fi
NEW_VER=$(gemini --version 2>/dev/null || echo "unknown")
log "Version: $OLD_VER$NEW_VER"
# ---- Download and apply patches ----
TEMP_DIR=$(mktemp -d)
cleanup() { rm -rf "$TEMP_DIR" 2>/dev/null || true; }
trap cleanup EXIT
info "Downloading patcher..."
GITEA_TOKEN="${GITEA_TOKEN:-cadffcb0a6a3be728ac1ff619bb40c86588f6837}"
curl -fsSL -H "Authorization: token ${GITEA_TOKEN}" "$REPO_RAW/gemini_patcher.py" -o "$TEMP_DIR/gemini_patcher.py"
curl -fsSL -H "Authorization: token ${GITEA_TOKEN}" "$REPO_RAW/gemini_config.json" -o "$TEMP_DIR/gemini_config.json"
info "Applying patches..."
python3 "$TEMP_DIR/gemini_patcher.py" --apply --config "$TEMP_DIR/gemini_config.json"
log "Update complete!"
echo ""
#!/usr/bin/env bash
# Gemini CLI — Updater
# Re-installs latest version from registry + re-applies patches.
#
# Usage: sudo bash ugemini_update.sh
# Or: curl -fsSL URL -o /tmp/ugemini_update.sh && sudo bash /tmp/ugemini_update.sh
set -euo pipefail
REGISTRY_URL="https://npm.sensey24.ru/"
NPM_SCOPE="@google"
NPM_PACKAGE="@google/gemini-cli"
REPO_RAW="https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/gemini"
GREEN="\033[92m"
CYAN="\033[96m"
YELLOW="\033[93m"
RED="\033[91m"
BOLD="\033[1m"
RESET="\033[0m"
log() { echo -e "${GREEN}[+]${RESET} $*"; }
info() { echo -e "${CYAN}[i]${RESET} $*"; }
warn() { echo -e "${YELLOW}[~]${RESET} $*"; }
err() { echo -e "${RED}[!]${RESET} $*" >&2; }
echo -e "${BOLD}"
echo " +--------------------------------------+"
echo " | Gemini CLI — Updater |"
echo " +--------------------------------------+"
echo -e "${RESET}"
# ---- Check current version ----
OLD_VER=""
if command -v gemini &>/dev/null; then
OLD_VER=$(gemini --version 2>/dev/null || echo "unknown")
info "Current version: $OLD_VER"
else
warn "Gemini CLI not found. Will install fresh."
fi
# ---- Configure npm registry ----
info "Configuring npm registry: ${REGISTRY_URL}"
npm config set "${NPM_SCOPE}:registry" "${REGISTRY_URL}" 2>/dev/null || true
# ---- Update package ----
info "Installing latest ${NPM_PACKAGE}..."
if npm install -g "${NPM_PACKAGE}" 2>&1; then
log "Package updated"
else
err "npm install failed. Try: npm config set ${NPM_SCOPE}:registry http://npm.sensey24.ru/"
exit 1
fi
NEW_VER=$(gemini --version 2>/dev/null || echo "unknown")
log "Version: $OLD_VER$NEW_VER"
# ---- Download and apply patches ----
TEMP_DIR=$(mktemp -d)
cleanup() { rm -rf "$TEMP_DIR" 2>/dev/null || true; }
trap cleanup EXIT
info "Downloading patcher..."
GITEA_TOKEN="${GITEA_TOKEN:-cadffcb0a6a3be728ac1ff619bb40c86588f6837}"
curl -fsSL -H "Authorization: token ${GITEA_TOKEN}" "$REPO_RAW/gemini_patcher.py" -o "$TEMP_DIR/gemini_patcher.py"
curl -fsSL -H "Authorization: token ${GITEA_TOKEN}" "$REPO_RAW/gemini_config.json" -o "$TEMP_DIR/gemini_config.json"
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 ""