fix: wrapper scripts for all CLIs — env vars work immediately without source
Problem: `sudo bash install.sh` runs in child process, `export` inside it never reaches the user's current shell. /etc/environment and /etc/profile.d/ only work for NEW sessions. So `codex`/`gemini`/`qwen` fail with "Missing environment variable" right after install. Solution: wrapper scripts that auto-source env file before exec'ing binary. - codex: /usr/local/bin/codex (wrapper) -> /usr/local/bin/.codex-bin (real) - gemini: /usr/local/bin/gemini (wrapper) -> node .../dist/index.js - qwen: /usr/local/bin/qwen (wrapper) -> node .../dist/index.js Works immediately in ANY shell, no manual `source` needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# Gemini CLI — Updater
|
||||
# Re-installs latest version from registry + re-applies patches.
|
||||
# Uses wrapper script so env vars work immediately in any shell.
|
||||
#
|
||||
# Usage: sudo bash ugemini_update.sh
|
||||
# Or: curl -fsSL URL -o /tmp/ugemini_update.sh && sudo bash /tmp/ugemini_update.sh
|
||||
set -euo pipefail
|
||||
|
||||
GITEA_TOKEN="${GITEA_TOKEN:-cadffcb0a6a3be728ac1ff619bb40c86588f6837}"
|
||||
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"
|
||||
|
||||
ENV_FILE="/etc/profile.d/gemini-cli.sh"
|
||||
WRAPPER_PATH="/usr/local/bin/gemini"
|
||||
|
||||
GREEN="\033[92m"
|
||||
CYAN="\033[96m"
|
||||
YELLOW="\033[93m"
|
||||
@@ -23,6 +27,26 @@ info() { echo -e "${CYAN}[i]${RESET} $*"; }
|
||||
warn() { echo -e "${YELLOW}[~]${RESET} $*"; }
|
||||
err() { echo -e "${RED}[!]${RESET} $*" >&2; }
|
||||
|
||||
create_wrapper() {
|
||||
local npm_root
|
||||
npm_root=$(npm root -g 2>/dev/null || echo "/usr/lib/node_modules")
|
||||
local real_bin="$npm_root/@google/gemini-cli/dist/index.js"
|
||||
|
||||
if [ ! -f "$real_bin" ]; then
|
||||
warn "Could not find gemini entry point at $real_bin"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -f "$WRAPPER_PATH"
|
||||
cat > "$WRAPPER_PATH" << WEOF
|
||||
#!/usr/bin/env bash
|
||||
[ -f $ENV_FILE ] && . $ENV_FILE
|
||||
exec node "$real_bin" "\$@"
|
||||
WEOF
|
||||
chmod +x "$WRAPPER_PATH"
|
||||
log "Wrapper: $WRAPPER_PATH -> $real_bin"
|
||||
}
|
||||
|
||||
echo -e "${BOLD}"
|
||||
echo " +--------------------------------------+"
|
||||
echo " | Gemini CLI — Updater |"
|
||||
@@ -54,9 +78,6 @@ else
|
||||
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)
|
||||
@@ -64,14 +85,14 @@ 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)
|
||||
# ---- Set env vars system-wide ----
|
||||
|
||||
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'])")
|
||||
|
||||
@@ -85,17 +106,19 @@ for kv in "GEMINI_API_KEY=\"$API_KEY\"" "GOOGLE_GEMINI_BASE_URL=\"$BASE_URL\"";
|
||||
fi
|
||||
done
|
||||
|
||||
cat > /etc/profile.d/gemini-cli.sh << PROF_EOF
|
||||
cat > "$ENV_FILE" << 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
|
||||
chmod 644 "$ENV_FILE"
|
||||
|
||||
export GEMINI_API_KEY="$API_KEY"
|
||||
export GOOGLE_GEMINI_BASE_URL="$BASE_URL"
|
||||
# ---- Create wrapper (auto-loads env) ----
|
||||
|
||||
info "Env vars set system-wide (/etc/environment + /etc/profile.d/gemini-cli.sh)"
|
||||
create_wrapper
|
||||
|
||||
NEW_VER=$(gemini --version 2>/dev/null || echo "unknown")
|
||||
log "Version: $OLD_VER -> $NEW_VER"
|
||||
|
||||
log "Update complete!"
|
||||
echo -e "For current shell: ${CYAN}source /etc/profile.d/gemini-cli.sh${RESET}"
|
||||
echo -e "Gemini works immediately — no need to source anything."
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user