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,5 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# Gemini CLI — One-line installer
|
||||
# Uses wrapper script so env vars work immediately in any shell.
|
||||
#
|
||||
# Usage:
|
||||
# curl -fsSL -H "Authorization: token TOKEN" \
|
||||
# https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/gemini/ugemini_install.sh \
|
||||
@@ -12,6 +14,9 @@ REGISTRY_URL="https://npm.sensey24.ru/"
|
||||
NPM_SCOPE="@google"
|
||||
NPM_PACKAGE="@google/gemini-cli"
|
||||
|
||||
ENV_FILE="/etc/profile.d/gemini-cli.sh"
|
||||
WRAPPER_PATH="/usr/local/bin/gemini"
|
||||
|
||||
GREEN="\033[92m"
|
||||
RED="\033[91m"
|
||||
CYAN="\033[96m"
|
||||
@@ -24,6 +29,34 @@ err() { echo -e "${RED}[!]${RESET} $*" >&2; }
|
||||
info() { echo -e "${CYAN}[i]${RESET} $*"; }
|
||||
warn() { echo -e "${YELLOW}[~]${RESET} $*"; }
|
||||
|
||||
create_wrapper() {
|
||||
# Find real entry point (npm symlink target)
|
||||
local real_bin
|
||||
real_bin=$(readlink -f "$WRAPPER_PATH" 2>/dev/null || true)
|
||||
|
||||
if [ -z "$real_bin" ] || [ "$real_bin" = "$WRAPPER_PATH" ]; then
|
||||
# Try to find it in node_modules
|
||||
local npm_root
|
||||
npm_root=$(npm root -g 2>/dev/null || echo "/usr/lib/node_modules")
|
||||
real_bin="$npm_root/@google/gemini-cli/dist/index.js"
|
||||
fi
|
||||
|
||||
if [ ! -f "$real_bin" ]; then
|
||||
warn "Could not find gemini entry point at $real_bin"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Remove symlink, create wrapper
|
||||
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 — Installer |"
|
||||
@@ -47,14 +80,12 @@ install_pkg() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Python3
|
||||
if ! command -v python3 &>/dev/null; then
|
||||
info "python3 not found, installing..."
|
||||
install_pkg python3
|
||||
fi
|
||||
log "Python3 $(python3 --version | awk '{print $2}')"
|
||||
|
||||
# curl
|
||||
if ! command -v curl &>/dev/null; then
|
||||
info "curl not found, installing..."
|
||||
install_pkg curl
|
||||
@@ -173,7 +204,6 @@ assert d.get('security',{}).get('auth',{}).get('selectedType') == 'gemini-api-ke
|
||||
"general": { "defaultApprovalMode": "yolo" }
|
||||
}
|
||||
SETTINGS_EOF
|
||||
# Trust common folders
|
||||
TRUSTED_FILE="$GEMINI_DIR/trustedFolders.json"
|
||||
python3 -c "
|
||||
import json, os
|
||||
@@ -190,13 +220,12 @@ else
|
||||
log "Settings already configured"
|
||||
fi
|
||||
|
||||
# ---- Set environment variables (system-wide, all users) ----
|
||||
# ---- Set environment variables (system-wide) ----
|
||||
|
||||
info "Setting environment variables..."
|
||||
API_KEY=$(python3 -c "import json; print(json.load(open('$INSTALL_DIR/gemini_config.json'))['api_key'])")
|
||||
BASE_URL=$(python3 -c "import json; print(json.load(open('$INSTALL_DIR/gemini_config.json'))['base_url'])")
|
||||
|
||||
# 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%%=*}"
|
||||
@@ -206,17 +235,19 @@ for kv in "GEMINI_API_KEY=\"$API_KEY\"" "GOOGLE_GEMINI_BASE_URL=\"$BASE_URL\"";
|
||||
echo "$kv" >> "$ETC_ENV"
|
||||
fi
|
||||
done
|
||||
log "Env vars written to $ETC_ENV (all users)"
|
||||
log "Env vars written to $ETC_ENV"
|
||||
|
||||
# Write to /etc/profile.d/ for export in login shells
|
||||
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
|
||||
log "Export script created: /etc/profile.d/gemini-cli.sh"
|
||||
chmod 644 "$ENV_FILE"
|
||||
log "Env file: $ENV_FILE"
|
||||
|
||||
# Export for current session
|
||||
# ---- Create wrapper (auto-loads env) ----
|
||||
|
||||
info "Creating wrapper..."
|
||||
create_wrapper
|
||||
export GEMINI_API_KEY="$API_KEY"
|
||||
export GOOGLE_GEMINI_BASE_URL="$BASE_URL"
|
||||
|
||||
@@ -238,13 +269,12 @@ if echo "$RESULT" | grep -qi "OK"; then
|
||||
echo " gemini-2.5-pro, gemini-2.5-flash"
|
||||
echo " gemini-3-flash, gemini-3.1-pro"
|
||||
echo ""
|
||||
echo " If env vars not active, run: source /etc/profile.d/gemini-cli.sh"
|
||||
echo " Env vars auto-loaded by wrapper. Works in any shell."
|
||||
echo ""
|
||||
else
|
||||
warn "Patches applied but test prompt failed."
|
||||
echo " Response: $RESULT"
|
||||
echo ""
|
||||
echo " Try manually:"
|
||||
echo " source /etc/profile.d/gemini-cli.sh"
|
||||
echo " gemini -p 'Hello'"
|
||||
fi
|
||||
|
||||
@@ -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