#!/bin/bash # Asthra Programming Language Installer # Usage: curl -sSf https://asthra-lang.org/install | sh set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration GITHUB_REPO="asthra-lang/asthra" INSTALL_DIR="$HOME/.asthra" BIN_DIR="$INSTALL_DIR/bin" # Utility functions log() { echo -e "${BLUE}[INFO]${NC} $1" } warn() { echo -e "${YELLOW}[WARN]${NC} $1" } error() { echo -e "${RED}[ERROR]${NC} $1" >&2 } success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } # Detect OS and architecture detect_platform() { local os local arch case "$(uname -s)" in Linux*) os="linux";; Darwin*) os="macos";; CYGWIN*|MINGW*|MSYS*) os="windows";; *) error "Unsupported operating system: $(uname -s)"; exit 1;; esac case "$(uname -m)" in x86_64|amd64) arch="x86_64";; arm64|aarch64) arch="arm64";; armv7l) arch="armv7";; *) error "Unsupported architecture: $(uname -m)"; exit 1;; esac echo "${os}-${arch}" } # Get latest release version get_latest_version() { log "Fetching latest release information..." local version version=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | \ grep '"tag_name":' | \ sed -E 's/.*"([^"]+)".*/\1/') if [ -z "$version" ]; then error "Failed to fetch latest version" exit 1 fi echo "$version" } # Download and install Asthra install_asthra() { local platform="$1" local version="$2" log "Installing Asthra $version for $platform..." # Create installation directory mkdir -p "$BIN_DIR" # Construct download URL local download_url="https://github.com/${GITHUB_REPO}/releases/download/${version}/asthra-${version}-${platform}.tar.gz" local temp_file="/tmp/asthra-${version}.tar.gz" # Download the release log "Downloading from: $download_url" if ! curl -L -o "$temp_file" "$download_url"; then error "Failed to download Asthra release" exit 1 fi # Extract the archive log "Extracting to $INSTALL_DIR..." if ! tar -xzf "$temp_file" -C "$INSTALL_DIR" --strip-components=1; then error "Failed to extract Asthra release" exit 1 fi # Clean up rm -f "$temp_file" # Make binary executable chmod +x "$BIN_DIR/asthra" } # Update PATH in shell profile update_path() { local shell_profile # Determine shell profile file case "$SHELL" in */bash) if [ -f "$HOME/.bashrc" ]; then shell_profile="$HOME/.bashrc" else shell_profile="$HOME/.bash_profile" fi ;; */zsh) shell_profile="$HOME/.zshrc" ;; */fish) shell_profile="$HOME/.config/fish/config.fish" ;; *) shell_profile="$HOME/.profile" ;; esac # Check if PATH is already updated if grep -q "asthra" "$shell_profile" 2>/dev/null; then log "PATH already configured in $shell_profile" return fi # Add to PATH log "Adding Asthra to PATH in $shell_profile" echo "" >> "$shell_profile" echo "# Asthra Programming Language" >> "$shell_profile" echo "export PATH=\"\$HOME/.asthra/bin:\$PATH\"" >> "$shell_profile" success "Added Asthra to PATH in $shell_profile" warn "Please restart your shell or run: source $shell_profile" } # Verify installation verify_installation() { log "Verifying installation..." if [ -x "$BIN_DIR/asthra" ]; then local version_output version_output=$("$BIN_DIR/asthra" --version 2>/dev/null || echo "") if [ -n "$version_output" ]; then success "Asthra installed successfully!" success "Version: $version_output" else warn "Asthra binary found but version check failed" fi else error "Asthra binary not found at $BIN_DIR/asthra" exit 1 fi } # Print usage information print_usage() { echo "" echo "🚀 Asthra is now installed!" echo "" echo "To get started:" echo " 1. Restart your shell or run: source ~/.$(basename $SHELL)rc" echo " 2. Create a new file: hello.asthra" echo " 3. Add some code:" echo " func main() {" echo " print(\"Hello, Asthra!\")" echo " }" echo " 4. Run it: asthra run hello.asthra" echo "" echo "Resources:" echo " • Documentation: https://asthra-lang.org/docs/" echo " • Examples: https://github.com/asthra-lang/asthra/tree/main/examples" echo " • Community: https://discord.gg/asthra" echo "" } # Main installation process main() { echo "🌟 Asthra Programming Language Installer" echo "========================================" echo "" # Check dependencies if ! command -v curl >/dev/null 2>&1; then error "curl is required but not installed" exit 1 fi if ! command -v tar >/dev/null 2>&1; then error "tar is required but not installed" exit 1 fi # Detect platform local platform platform=$(detect_platform) log "Detected platform: $platform" # Get latest version local version version=$(get_latest_version) log "Latest version: $version" # Install Asthra install_asthra "$platform" "$version" # Update PATH update_path # Verify installation verify_installation # Print usage information print_usage } # Run main function main "$@"