Created
January 4, 2024 03:01
-
-
Save Brandon7CC/d578cf5876e844051d007d47759a7f7d to your computer and use it in GitHub Desktop.
Install Google Cloud Command Line Interface (gcloud CLI)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Set up `gcloud` cli on macOS and Linux | |
# Check which OS we're on | |
if [[ "$OSTYPE" == "linux-gnu" ]]; then | |
OS="linux" | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
OS="darwin" | |
else | |
echo "Unsupported OS: $OSTYPE" | |
exit 1 | |
fi | |
# If we're on macOS, install with Homebrew `brew install --cask google-cloud-sdk` | |
if [[ "$OS" == "darwin" ]]; then | |
if ! command -v brew &> /dev/null; then | |
echo "Homebrew not found. Please install Homebrew first." | |
exit 1 | |
fi | |
# Check if gcloud is installed | |
if ! command -v gcloud &> /dev/null; then | |
brew install --cask google-cloud-sdk | |
fi | |
fi | |
# If we're on Linux, install with `snap`. | |
if [[ "$OS" == "linux" ]]; then | |
if ! command -v snap &> /dev/null; then | |
echo "Snap not found. Please install Snap first." | |
exit 1 | |
fi | |
# Check if gcloud is installed | |
if ! command -v gcloud &> /dev/null; then | |
sudo snap install google-cloud-sdk --classic | |
fi | |
fi | |
# Initialize gcloud | |
gcloud init | |
gcloud auth application-default login | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment