#!/bin/sh # AC/DC Installer - Alpha/Delta Network # # Usage: # curl -sSL https://install.ac-dc.network | sh # curl -sSL https://install.ac-dc.network | sh -s -- --help # # Options: # --version VERSION Install specific version (default: latest) # --dir DIR Install directory (default: /usr/local/bin) # --no-verify Skip SHA256 verification (not recommended) # --help Show this help message set -e # Configuration RELEASE_URL="${ACDC_RELEASE_URL:-https://releases.ac-dc.network}" INSTALL_DIR="${ACDC_INSTALL_DIR:-/usr/local/bin}" BINARY_NAME="ac-dc" VERSION="" SKIP_VERIFY=false # Colors (disabled if not a terminal) if [ -t 1 ]; then RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;34m' BOLD='\033[1m' NC='\033[0m' else RED='' GREEN='' YELLOW='' BLUE='' BOLD='' NC='' fi # Logging functions info() { printf "${BLUE}==>${NC} ${BOLD}%s${NC}\n" "$1" } success() { printf "${GREEN}==>${NC} ${BOLD}%s${NC}\n" "$1" } warn() { printf "${YELLOW}Warning:${NC} %s\n" "$1" >&2 } error() { printf "${RED}Error:${NC} %s\n" "$1" >&2 exit 1 } # Show help show_help() { cat << 'EOF' AC/DC Installer - Alpha/Delta Network Usage: curl -sSL https://install.ac-dc.network | sh curl -sSL https://install.ac-dc.network | sh -s -- [OPTIONS] Options: --version VERSION Install specific version (default: latest) --dir DIR Install directory (default: /usr/local/bin) --no-verify Skip SHA256 verification (not recommended) --help Show this help message Environment Variables: ACDC_RELEASE_URL Override release server URL ACDC_INSTALL_DIR Override installation directory After Installation: ac-dc setup Run interactive setup wizard ac-dc install Install network components (adnet) ac-dc start Start services ac-dc status Check node status For more information: https://docs.ac-dc.network EOF exit 0 } # Parse command line arguments parse_args() { while [ $# -gt 0 ]; do case "$1" in --version) VERSION="$2" shift 2 ;; --dir) INSTALL_DIR="$2" shift 2 ;; --no-verify) SKIP_VERIFY=true shift ;; --help|-h) show_help ;; *) error "Unknown option: $1. Use --help for usage." ;; esac done } # Detect platform detect_platform() { info "Detecting platform..." OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) # Normalize architecture case "$ARCH" in x86_64|amd64) ARCH="x86_64" ;; aarch64|arm64) ARCH="aarch64" ;; *) error "Unsupported architecture: $ARCH (supported: x86_64, aarch64)" ;; esac # Normalize OS and set target triple case "$OS" in linux) # Check for musl vs glibc if ldd --version 2>&1 | grep -q musl; then TARGET="${ARCH}-unknown-linux-musl" else TARGET="${ARCH}-unknown-linux-gnu" fi ;; darwin) TARGET="${ARCH}-apple-darwin" ;; *) error "Unsupported operating system: $OS (supported: linux, darwin)" ;; esac printf " Platform: %s\n" "$TARGET" } # Check required dependencies check_dependencies() { info "Checking dependencies..." for cmd in curl tar; do if ! command -v "$cmd" >/dev/null 2>&1; then error "Required command not found: $cmd" fi done # Check for sha256sum or shasum if command -v sha256sum >/dev/null 2>&1; then SHA_CMD="sha256sum" elif command -v shasum >/dev/null 2>&1; then SHA_CMD="shasum -a 256" else if [ "$SKIP_VERIFY" = false ]; then warn "Neither sha256sum nor shasum found. Skipping verification." SKIP_VERIFY=true fi fi printf " Dependencies OK\n" } # Get latest version from release server get_version() { if [ -n "$VERSION" ]; then printf " Using specified version: %s\n" "$VERSION" return fi info "Fetching latest version..." VERSION=$(curl -sSL --fail "${RELEASE_URL}/latest" 2>/dev/null) || { warn "Could not fetch latest version, using fallback: 0.2.0" VERSION="0.2.0" } # Trim whitespace and newlines VERSION=$(printf "%s" "$VERSION" | tr -d '[:space:]') printf " Latest version: %s\n" "$VERSION" } # Download binary download_binary() { info "Downloading ac-dc v${VERSION}..." FILENAME="${BINARY_NAME}-${VERSION}-${TARGET}.tar.gz" DOWNLOAD_URL="${RELEASE_URL}/${VERSION}/${FILENAME}" TEMP_DIR=$(mktemp -d) ARCHIVE_PATH="${TEMP_DIR}/${FILENAME}" printf " URL: %s\n" "$DOWNLOAD_URL" HTTP_CODE=$(curl -sSL -w "%{http_code}" -o "$ARCHIVE_PATH" "$DOWNLOAD_URL") || { rm -rf "$TEMP_DIR" error "Failed to download: $DOWNLOAD_URL" } if [ "$HTTP_CODE" != "200" ]; then rm -rf "$TEMP_DIR" error "Download failed with HTTP $HTTP_CODE" fi ARCHIVE_SIZE=$(wc -c < "$ARCHIVE_PATH" | tr -d ' ') printf " Downloaded: %s bytes\n" "$ARCHIVE_SIZE" } # Verify SHA256 checksum verify_checksum() { if [ "$SKIP_VERIFY" = true ]; then warn "Skipping checksum verification" return fi info "Verifying checksum..." CHECKSUM_URL="${DOWNLOAD_URL}.sha256" EXPECTED=$(curl -sSL --fail "$CHECKSUM_URL" 2>/dev/null | awk '{print $1}') || { warn "Could not fetch checksum, skipping verification" return } ACTUAL=$($SHA_CMD "$ARCHIVE_PATH" | awk '{print $1}') if [ -z "$EXPECTED" ]; then warn "Empty checksum received, skipping verification" return fi # Case-insensitive comparison EXPECTED_LOWER=$(printf "%s" "$EXPECTED" | tr '[:upper:]' '[:lower:]') ACTUAL_LOWER=$(printf "%s" "$ACTUAL" | tr '[:upper:]' '[:lower:]') if [ "$EXPECTED_LOWER" != "$ACTUAL_LOWER" ]; then rm -rf "$TEMP_DIR" error "Checksum mismatch!\n Expected: $EXPECTED\n Actual: $ACTUAL" fi printf " Checksum verified: %s\n" "$ACTUAL" } # Extract and install binary install_binary() { info "Installing to ${INSTALL_DIR}..." # Extract archive tar -xzf "$ARCHIVE_PATH" -C "$TEMP_DIR" || { rm -rf "$TEMP_DIR" error "Failed to extract archive" } # Find the binary (might be in root or subdirectory) BINARY_PATH="" if [ -f "${TEMP_DIR}/${BINARY_NAME}" ]; then BINARY_PATH="${TEMP_DIR}/${BINARY_NAME}" else # Search in subdirectories BINARY_PATH=$(find "$TEMP_DIR" -name "$BINARY_NAME" -type f | head -1) fi if [ -z "$BINARY_PATH" ] || [ ! -f "$BINARY_PATH" ]; then rm -rf "$TEMP_DIR" error "Binary not found in archive" fi # Create install directory if needed if [ ! -d "$INSTALL_DIR" ]; then if [ -w "$(dirname "$INSTALL_DIR")" ]; then mkdir -p "$INSTALL_DIR" else sudo mkdir -p "$INSTALL_DIR" fi fi # Install binary DEST="${INSTALL_DIR}/${BINARY_NAME}" if [ -w "$INSTALL_DIR" ]; then cp "$BINARY_PATH" "$DEST" chmod +x "$DEST" else printf " Requires sudo for installation\n" sudo cp "$BINARY_PATH" "$DEST" sudo chmod +x "$DEST" fi # Cleanup rm -rf "$TEMP_DIR" printf " Installed: %s\n" "$DEST" } # Verify installation verify_installation() { info "Verifying installation..." if ! command -v "$BINARY_NAME" >/dev/null 2>&1; then # Check if install dir is in PATH if [ -x "${INSTALL_DIR}/${BINARY_NAME}" ]; then warn "${INSTALL_DIR} is not in your PATH" printf " Add to your shell profile:\n" printf " export PATH=\"\$PATH:%s\"\n" "$INSTALL_DIR" else error "Installation verification failed" fi fi INSTALLED_VERSION=$("${INSTALL_DIR}/${BINARY_NAME}" --version 2>/dev/null | head -1) || true printf " Installed: %s\n" "${INSTALLED_VERSION:-ac-dc}" } # Show post-install instructions post_install() { printf "\n" success "AC/DC installed successfully!" printf "\n" printf "${BOLD}Next steps:${NC}\n" printf " 1. Run the setup wizard: ${BLUE}ac-dc setup${NC}\n" printf " 2. Install node components: ${BLUE}ac-dc install${NC}\n" printf " 3. Start your node: ${BLUE}ac-dc start${NC}\n" printf " 4. Check status: ${BLUE}ac-dc status${NC}\n" printf "\n" printf "Documentation: ${BLUE}https://docs.ac-dc.network${NC}\n" printf "Source code: ${BLUE}https://source.ac-dc.network/alpha-delta-network/ac-dc${NC}\n" printf "\n" } # Main function main() { printf "\n" printf "${BOLD}AC/DC Installer${NC} - Alpha/Delta Network\n" printf "================================================\n" printf "\n" parse_args "$@" detect_platform check_dependencies get_version download_binary verify_checksum install_binary verify_installation post_install } # Run main main "$@"