#!/usr/bin/env bash # Seaman Installer # Install Seaman - Docker development environment manager for Symfony 7+ 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 PHAR_URL="https://github.com/diego-ninja/seaman/releases/latest/download/seaman.phar" PHAR_NAME="seaman.phar" BIN_NAME="seaman" # Functions print_info() { echo -e "${BLUE}ℹ${NC} $1" } print_success() { echo -e "${GREEN}✓${NC} $1" } print_warning() { echo -e "${YELLOW}⚠${NC} $1" } print_error() { echo -e "${RED}✗${NC} $1" } print_header() { echo "" echo -e "${BLUE}🔱 Seaman Installer${NC}" echo "" } detect_shell() { local shell_name=$(basename "$SHELL") case "$shell_name" in bash) echo "$HOME/.bashrc" ;; zsh) echo "$HOME/.zshrc" ;; fish) echo "$HOME/.config/fish/config.fish" ;; *) echo "$HOME/.profile" ;; esac } add_to_path() { local bin_dir="$1" local shell_rc=$(detect_shell) local shell_name=$(basename "$SHELL") # Check if already in PATH if echo "$PATH" | grep -q "$bin_dir"; then return 0 fi print_info "Adding $bin_dir to PATH in $shell_rc" if [ "$shell_name" = "fish" ]; then echo "fish_add_path $bin_dir" >> "$shell_rc" else echo "" >> "$shell_rc" echo "# Seaman" >> "$shell_rc" echo "export PATH=\"\$PATH:$bin_dir\"" >> "$shell_rc" fi print_success "Added to PATH. Run: source $shell_rc" } # Main installation print_header print_info "Downloading Seaman..." TMP_DIR=$(mktemp -d) TMP_PHAR="$TMP_DIR/$PHAR_NAME" if ! curl -sS -L -f "$PHAR_URL" -o "$TMP_PHAR"; then print_error "Failed to download Seaman from $PHAR_URL" rm -rf "$TMP_DIR" exit 1 fi chmod +x "$TMP_PHAR" print_success "Downloaded Seaman" # Try to install to /usr/local/bin (preferred) if [ -w "/usr/local/bin" ]; then print_info "Installing to /usr/local/bin (system-wide)" mv "$TMP_PHAR" "/usr/local/bin/$BIN_NAME" print_success "Installed to /usr/local/bin/$BIN_NAME" rm -rf "$TMP_DIR" elif command -v sudo >/dev/null 2>&1; then print_info "Installing to /usr/local/bin (requires sudo)" if sudo mv "$TMP_PHAR" "/usr/local/bin/$BIN_NAME"; then print_success "Installed to /usr/local/bin/$BIN_NAME" rm -rf "$TMP_DIR" else print_warning "Failed to install to /usr/local/bin, falling back to user installation" INSTALL_TO_USER=1 fi else print_warning "Cannot write to /usr/local/bin and sudo not available" INSTALL_TO_USER=1 fi # Fallback: Install to ~/.local/bin if [ "${INSTALL_TO_USER:-0}" -eq 1 ]; then USER_BIN_DIR="$HOME/.local/bin" mkdir -p "$USER_BIN_DIR" print_info "Installing to $USER_BIN_DIR (user installation)" mv "$TMP_PHAR" "$USER_BIN_DIR/$BIN_NAME" print_success "Installed to $USER_BIN_DIR/$BIN_NAME" rm -rf "$TMP_DIR" # Add to PATH if not already there if ! echo "$PATH" | grep -q "$USER_BIN_DIR"; then print_warning "$USER_BIN_DIR is not in your PATH" echo "" echo "To use seaman, add it to your PATH:" echo "" SHELL_RC=$(detect_shell) SHELL_NAME=$(basename "$SHELL") if [ "$SHELL_NAME" = "fish" ]; then echo -e " ${GREEN}fish_add_path $USER_BIN_DIR${NC}" else echo -e " ${GREEN}export PATH=\"\$PATH:$USER_BIN_DIR\"${NC}" fi echo "" echo "Add this to your $SHELL_RC and run:" echo -e " ${GREEN}source $SHELL_RC${NC}" echo "" echo "Or run Seaman directly:" echo -e " ${GREEN}$USER_BIN_DIR/$BIN_NAME --version${NC}" echo "" # Ask user if they want to add automatically read -p "Add to PATH automatically? [Y/n] " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then add_to_path "$USER_BIN_DIR" fi fi fi # Verify installation echo "" print_info "Verifying installation..." if command -v seaman >/dev/null 2>&1; then VERSION=$(seaman --version 2>&1 || echo "unknown") print_success "Seaman installed successfully!" echo "" echo " Version: $VERSION" echo "" echo "Get started:" echo -e " ${GREEN}cd your-symfony-project${NC}" echo -e " ${GREEN}seaman init${NC}" echo -e " ${GREEN}seaman start${NC}" echo "" else print_warning "Installation complete, but 'seaman' command not found in PATH" echo "" echo "You may need to:" echo " 1. Restart your terminal" echo " 2. Run: source $(detect_shell)" if [ "${INSTALL_TO_USER:-0}" -eq 1 ]; then echo " 3. Or use: $USER_BIN_DIR/$BIN_NAME" fi echo "" fi