diff --git a/installers/install_agy.sh b/installers/install_agy.sh new file mode 100644 index 0000000..b4c1034 --- /dev/null +++ b/installers/install_agy.sh @@ -0,0 +1,197 @@ +#!/usr/bin/env bash +# +# Antigravity CLI Installer Script (Linux Only) +# + +# Run metascript to check if the shell is bash and load libraries +PARENT_DIR="$(dirname "$0")/.." +METASCRIPT_LOCAL="$PARENT_DIR/bootstrap.sh" +METASCRIPT_URL="https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/bootstrap.sh" + +if [ -f "$METASCRIPT_LOCAL" ]; then + . "$METASCRIPT_LOCAL" +else + if command -v wget >/dev/null 2>&1; then + eval "$(wget -qO- "$METASCRIPT_URL")" + elif command -v curl >/dev/null 2>&1; then + eval "$(curl -fsSL "$METASCRIPT_URL")" + else + echo "Error: Neither wget nor curl is installed to fetch bootstrap.sh." >&2 + exit 1 + fi +fi + +set -euo pipefail + +# Constants +DOWNLOAD_BASE_URL="https://antigravity-cli-auto-updater-974169037036.us-central1.run.app" +TARGET_DIR="$HOME/.local/bin" +BINARY_PATH="$TARGET_DIR/agy" + +install_agy() { + if [ -f "$BINARY_PATH" ]; then + log_info "Notice: 'agy' is already installed at $BINARY_PATH." + log_info "The Antigravity CLI automatically self-updates in the background during regular runs." + if ! confirm "Do you want to perform a fresh reinstall/upgrade anyway?"; then + log_info "Skipping Antigravity CLI installation." + return 0 + fi + else + if ! confirm "Install Antigravity CLI (agy)?"; then + log_info "Skipping Antigravity CLI installation." + return 0 + fi + fi + + # Detect Architecture (map uname -m to amd64 / arm64) + local arch + local raw_arch + raw_arch=$(detect_arch) + case "$raw_arch" in + x86_64) arch="amd64" ;; + arm64) arch="arm64" ;; + *) log_error "Unsupported Linux architecture: $raw_arch"; exit 1 ;; + esac + + # musl libc detection on Linux + local platform="linux_${arch}" + if [ -f /lib/libc.musl-x86_64.so.1 ] || [ -f /lib/libc.musl-aarch64.so.1 ] || ldd /bin/ls 2>&1 | grep -q musl; then + platform="linux_${arch}_musl" + fi + + log_info "Platform detected: $platform" + log_info "Querying release repository..." + + # Construct Platform JSON Manifest URL + local manifest_url="$DOWNLOAD_BASE_URL/manifests/$platform.json" + local manifest_json="" + + if has_command curl; then + manifest_json=$(curl -fsSL "$manifest_url" 2>/dev/null || true) + elif has_command wget; then + manifest_json=$(wget -qO- "$manifest_url" 2>/dev/null || true) + fi + + if [ -z "$manifest_json" ]; then + log_error "Could not connect to the release server to download the manifest." + exit 1 + fi + + # POSIX-compliant JSON parser (no jq dependencies) + parse_json_key() { + local payload="$1" + local key="$2" + echo "$payload" | sed -n 's/.*"'"$key"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' + } + + local version + local url + local sha512 + version=$(parse_json_key "$manifest_json" "version") + url=$(parse_json_key "$manifest_json" "url") + sha512=$(parse_json_key "$manifest_json" "sha512") + + if [ -z "$url" ] || [ -z "$sha512" ]; then + log_error "Failed to parse release manifest." + exit 1 + fi + + log_info "Latest available version: $version" + + # Setup temp/staging dir + local staging_dir + staging_dir="$(make_temp_dir)" + + local is_tar_gz=false + if [[ "$url" == *.tar.gz* ]]; then + is_tar_gz=true + fi + + local staging_payload + local extracted_binary + if [ "$is_tar_gz" = true ]; then + staging_payload="$staging_dir/agy.tar.gz" + extracted_binary="$staging_dir/antigravity" + else + staging_payload="$staging_dir/agy" + extracted_binary="$staging_payload" + fi + + log_info "Downloading release package..." + if has_command curl; then + curl -fsSL "$url" -o "$staging_payload" + else + wget -qO "$staging_payload" "$url" + fi + + # Verify SHA512 Checksum + local actual_hash + if has_command sha512sum; then + actual_hash=$(sha512sum "$staging_payload" | cut -d' ' -f1 || true) + elif has_command shasum; then + actual_hash=$(shasum -a 512 "$staging_payload" | cut -d' ' -f1 || true) + else + log_error "Neither sha512sum nor shasum is available to verify the download." + rm -rf "$staging_dir" + exit 1 + fi + + if [ "$actual_hash" != "$sha512" ]; then + log_error "Security Halt: Downloaded payload checksum does not match manifest. Installation aborted." + rm -rf "$staging_dir" + exit 1 + fi + log_success "Download complete and checksum verified." + + # Direct Binary Extraction & Write Permission Validation + mkdir -p "$TARGET_DIR" + + if [ "$is_tar_gz" = true ]; then + log_info "Extracting binary from archive..." + tar -xzf "$staging_payload" -C "$staging_dir" antigravity + else + log_info "Copying binary directly to destination..." + fi + + cp "$extracted_binary" "$BINARY_PATH" + chmod +x "$BINARY_PATH" + rm -rf "$staging_dir" + + log_success "Antigravity CLI successfully installed to $BINARY_PATH." +} + +configure_shell() { + # Ensure $TARGET_DIR is in PATH for shell configurations if not present + IFS=' ' read -ra target_files <<< "$(get_shell_configs)" + + local path_content='export PATH="$HOME/.local/bin:$PATH"' + + for config_file in "${target_files[@]}"; do + if [ -f "$config_file" ] && ! grep -q '\.local/bin' "$config_file" 2>/dev/null; then + log_info "Adding ~/.local/bin to PATH in $config_file..." + inject_block "$config_file" "local-bin path" "$path_content" + + # Source if modified (only for bashrc) + if [ "$config_file" = "$HOME/.bashrc" ]; then + . "$config_file" 2>/dev/null || true + fi + fi + done +} + +run_handoff() { + log_info "Configuring shell environment via agy native setup handoff..." + # Run standard configuration and absorb non-fatal soft warning exits + "$BINARY_PATH" install || true +} + +main() { + install_agy + configure_shell + run_handoff + + echo + log_success "Antigravity CLI installation complete." +} + +main "$@" diff --git a/readme.md b/readme.md index e427540..720df2e 100644 --- a/readme.md +++ b/readme.md @@ -8,6 +8,7 @@ The goal is simple: reduce the number of manual steps required after installing | Script | Description | | ----------------- | --------------------------------------------------------------------- | +| `install_agy.sh` | Installs Antigravity CLI and triggers native shell configuration. | | `install_node.sh` | Installs Node.js (LTS) and NVM (Node Version Manager). | | `install_nvim.sh` | Installs Neovim 0.11.7 and clones my Neovim configuration repository. | | `install_yazi.sh` | Installs Yazi terminal file manager and its dependencies. | diff --git a/routes.sh b/routes.sh index 4b4db2d..a1557af 100755 --- a/routes.sh +++ b/routes.sh @@ -17,13 +17,14 @@ require_bash # Registry of installers declare -A INSTALLERS=( + [agy]="Install Antigravity CLI" [node]="Install Node.js (LTS) and NVM" [nvim]="Install Neovim 0.11.7 and configuration" [yazi]="Install Yazi terminal file manager and dependencies" [zoxide]="Install Zoxide directory jumper" ) # Order in which installers should be displayed -INSTALLER_KEYS=(node nvim yazi zoxide) +INSTALLER_KEYS=(agy node nvim yazi zoxide) SCRIPT_NAMES="${1:-}" if [ -z "$SCRIPT_NAMES" ] || [ "$SCRIPT_NAMES" = "-h" ] || [ "$SCRIPT_NAMES" = "--help" ]; then