Skip to content

Commit 0ecd1df

Browse files
committed
fix(gcloud): handle existing install, reduce output, fix PATH detection
- Add ~/google-cloud-sdk/bin to PATH at script start so existing installs are detected even when not in shell PATH - Three-way check: gcloud in PATH → update, SDK dir exists → recover, neither → fresh install (avoids "directory already exists" error) - Fresh install uses direct tarball + install.sh --quiet instead of the noisy sdk.cloud.google.com wrapper script - Pipe update output through tail -1 to reduce noise Signed-off-by: Sebastian Mendel <sebastian.mendel@netresearch.de> Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
1 parent 3669bbf commit 0ecd1df

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

scripts/installers/gcloud_installer.sh

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,42 @@ if [ ! -f "$CATALOG_FILE" ]; then
1414
fi
1515

1616
BINARY_NAME="$(jq -r '.binary_name' "$CATALOG_FILE")"
17+
GCLOUD_SDK="$HOME/google-cloud-sdk"
18+
GCLOUD_BIN="$GCLOUD_SDK/bin"
19+
20+
# Ensure SDK bin is in PATH for detection and post-install
21+
if [ -d "$GCLOUD_BIN" ]; then
22+
export PATH="$GCLOUD_BIN:$PATH"
23+
fi
1724

1825
# Get current version
1926
before="$(command -v "$BINARY_NAME" >/dev/null 2>&1 && "$BINARY_NAME" version 2>/dev/null | head -1 || true)"
2027

2128
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
22-
# Already installed - use built-in update
23-
"$BINARY_NAME" components update --quiet 2>&1 || true
29+
# Already installed - use built-in update (quiet)
30+
"$BINARY_NAME" components update --quiet 2>&1 | tail -1
31+
elif [ -d "$GCLOUD_SDK" ]; then
32+
# SDK directory exists but gcloud not functional - try to recover
33+
if [ -x "$GCLOUD_BIN/$BINARY_NAME" ]; then
34+
"$GCLOUD_BIN/$BINARY_NAME" components update --quiet 2>&1 | tail -1
35+
else
36+
echo "[$TOOL] Error: $GCLOUD_SDK exists but gcloud not found in $GCLOUD_BIN" >&2
37+
echo "[$TOOL] Remove $GCLOUD_SDK and re-run to reinstall" >&2
38+
exit 1
39+
fi
2440
else
25-
# Fresh install via Google Cloud SDK installer
41+
# Fresh install via Google Cloud SDK installer (quiet)
2642
TMP="$(mktemp -d)"
27-
cd "$TMP"
28-
curl -fsSL https://sdk.cloud.google.com -o install.sh
29-
bash install.sh --disable-prompts --install-dir="$HOME" 2>&1
30-
cd - >/dev/null
43+
INSTALLER_URL="https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz"
44+
echo "[$TOOL] Downloading Google Cloud SDK..."
45+
curl -fsSL "$INSTALLER_URL" -o "$TMP/google-cloud-sdk.tar.gz"
46+
tar -xzf "$TMP/google-cloud-sdk.tar.gz" -C "$HOME"
3147
rm -rf "$TMP"
3248

33-
# Add to PATH if not already present
34-
GCLOUD_BIN="$HOME/google-cloud-sdk/bin"
35-
if [ -d "$GCLOUD_BIN" ] && ! command -v "$BINARY_NAME" >/dev/null 2>&1; then
36-
export PATH="$GCLOUD_BIN:$PATH"
37-
fi
49+
# Run install script quietly (no prompts, no PATH modification, no usage reporting)
50+
"$GCLOUD_SDK/install.sh" --quiet --usage-reporting false --command-completion false --path-update false 2>&1 | tail -1
51+
52+
export PATH="$GCLOUD_BIN:$PATH"
3853
fi
3954

4055
# Report

0 commit comments

Comments
 (0)