#!/data/data/com.termux/files/usr/bin/bash # Script: GCloud SDK Installer for Termux # Description: Automates the installation and setup of Google Cloud SDK on Termux. # Author: Samir Badaila # Version: 1.1 # Date: 2025-02-27 set -e # Exit on error # Color codes for terminal output GREEN='\033[0;32m' RED='\033[0;31m' BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Function to display a header header() { clear echo -e "${GREEN}========================================${NC}" echo -e "${GREEN} Google Cloud SDK Installer for Termux ${NC}" echo -e "${GREEN}========================================${NC}" echo -e "${BLUE}Version: 1.1 | Published Date: 2025-02-27${NC}\n" } success() { echo -e "${GREEN}[✓] $1${NC}" } error() { echo -e "${RED}[✗] Error: $1${NC}" exit 1 } warning() { echo -e "${YELLOW}[!] Warning: $1${NC}" } install_package() { local package=$1 echo -e "${BLUE}[~] Installing $package...${NC}" if pkg install "$package" -y >/dev/null 2>&1; then success "$package installed successfully." else warning "Failed to install $package. Skipping..." fi } header echo -e "${BLUE}[~] Updating system packages...${NC}" if pkg update -y >/dev/null 2>&1; then success "System packages updated successfully." else error "Failed to update system packages. Check your network connection." fi ARCH=$(dpkg --print-architecture) SUPPORTED_ARCHS=("aarch64" "arm") if [[ ! " ${SUPPORTED_ARCHS[*]} " =~ " ${ARCH} " ]]; then error "Unsupported architecture: $ARCH. Only 'aarch64' and 'arm' are supported." fi echo -e "${BLUE}[~] Detected architecture: $ARCH${NC}" DEPENDENCIES=("ldns" "libffi" "python" "openssl" "openssh" "libsqlite" "libresolv-wrapper") echo -e "${BLUE}[~] Installing dependencies...${NC}" for package in "${DEPENDENCIES[@]}"; do install_package "$package" done success "All dependencies installed successfully." echo -e "${BLUE}[~] Downloading Google Cloud SDK...${NC}" TEMP_DIR=$(mktemp -d) GCLOUD_URL="https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz" if curl -# -f "$GCLOUD_URL" -o "$TEMP_DIR/gcloud.tar.gz"; then success "Google Cloud SDK downloaded successfully." else error "Failed to download Google Cloud SDK." fi echo -e "${BLUE}[~] Extracting Google Cloud SDK...${NC}" if tar --strip-components=1 -C "$PREFIX" -zxf "$TEMP_DIR/gcloud.tar.gz"; then success "Google Cloud SDK extracted successfully." else error "Failed to extract Google Cloud SDK." fi echo -e "${BLUE}[~] Configuring environment...${NC}" if ! grep -q "$PREFIX/bin" "$HOME/.bashrc"; then echo "export PATH=\$PATH:$PREFIX/bin" >> "$HOME/.bashrc" fi if ! grep -q "CLOUDSDK_PYTHON" "$HOME/.bashrc"; then echo "export CLOUDSDK_PYTHON=$(command -v python3)" >> "$HOME/.bashrc" fi source "$HOME/.bashrc" success "Environment configured successfully." echo -e "${BLUE}[~] Verifying Google Cloud SDK installation...${NC}" if command -v gcloud &>/dev/null; then success "Google Cloud SDK is installed. Version details:" gcloud --version else error "Google Cloud SDK installation failed." fi echo -e "${BLUE}[~] Cleaning up cache files...${NC}" if rm -rf "$TEMP_DIR" 2>/dev/null; then success "Cache files removed successfully." else warning "Failed to clean up temporary files." fi echo -e "\n${GREEN}========================================${NC}" echo -e "${GREEN} Google Cloud SDK Installation Complete ${NC}" echo -e "${GREEN}========================================${NC}" echo -e "${BLUE}Run 'gcloud init' to configure your Google Cloud account.${NC}"