#!/bin/bash ############################################################################### # Retently Platform Setup - Bootstrap Script ############################################################################### # This is a minimal bootstrap script that clones the docker repository. # The full setup script is in the docker repo (requires authentication). # # Usage: # curl -fsSL https://retently.dev/setup.sh | bash # OR # curl -fsSL https://retently.dev/setup.sh -o setup.sh && bash setup.sh ############################################################################### set -e # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' BOLD='\033[1m' NC='\033[0m' ############################################################################### # Configuration ############################################################################### # Determine default workspace based on user if [ "$(id -u)" -eq 0 ]; then # Running as root - use /var/www for servers DEFAULT_WORKSPACE="/var/www/retently-platform" else # Running as regular user - use ~/Projects for developers DEFAULT_WORKSPACE="${HOME}/Projects/retently-platform" fi # Allow override via environment variable or command line WORKSPACE_DIR="${RETENTLY_WORKSPACE:-$DEFAULT_WORKSPACE}" DOCKER_REPO="git@bitbucket.org:retently/com.retently.docker.git" DOCKER_DIR="${WORKSPACE_DIR}/docker" ############################################################################### # Helper Functions ############################################################################### print_header() { echo -e "${BLUE}${BOLD}" echo "╔═══════════════════════════════════════════════════════════╗" echo "║ Retently Platform Setup - Bootstrap v1.0.0 ║" echo "╚═══════════════════════════════════════════════════════════╝" echo -e "${NC}" } print_success() { echo -e " ${GREEN}✓${NC} $1" } print_error() { echo -e " ${RED}✗${NC} $1" } print_warning() { echo -e " ${YELLOW}⚠${NC} $1" } print_info() { echo -e " ${BLUE}→${NC} $1" } print_section() { echo "" echo -e "${BLUE}${BOLD}═══ $1 ═══${NC}" echo "" } check_prerequisites() { print_section "Checking Prerequisites" local all_good=true # Check git if command -v git &> /dev/null; then local git_version=$(git --version | cut -d' ' -f3) print_success "Git found (version $git_version)" else print_error "Git is not installed" echo -e " ${YELLOW}Install with: brew install git (macOS) or apt-get install git (Linux)${NC}" all_good=false fi # Check SSH key for git access if [ -f ~/.ssh/id_rsa ] || [ -f ~/.ssh/id_ed25519 ]; then print_success "SSH key found" else print_warning "No SSH key found in ~/.ssh/" echo -e " ${YELLOW}You'll need SSH keys for Bitbucket access${NC}" echo -e " ${YELLOW}See: https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/${NC}" all_good=false fi if [ "$all_good" = false ]; then echo "" print_error "Prerequisites check failed. Please install missing dependencies." exit 1 fi } test_docker_access() { print_section "Testing Repository Access" print_info "Checking access to docker repository..." if git ls-remote "$DOCKER_REPO" HEAD &> /dev/null; then print_success "Access granted to docker repository" return 0 else print_error "Cannot access docker repository" echo "" echo -e "${YELLOW}Possible reasons:${NC}" echo -e " • SSH key not added to Bitbucket account" echo -e " • No permissions for this repository" echo -e " • Network/firewall issues" echo "" echo -e "${BLUE}To fix:${NC}" echo -e " 1. Add your SSH key to Bitbucket: https://bitbucket.org/account/settings/ssh-keys/" echo -e " 2. Request repository access from your team lead" echo -e " 3. Test SSH: ${YELLOW}ssh -T git@bitbucket.org${NC}" echo "" return 1 fi } clone_docker_repo() { print_section "Setting Up Workspace" # Create workspace directory if [ ! -d "$WORKSPACE_DIR" ]; then print_info "Creating workspace directory: $WORKSPACE_DIR" mkdir -p "$WORKSPACE_DIR" print_success "Workspace directory created" else print_success "Workspace directory exists" fi cd "$WORKSPACE_DIR" # Clone or update docker repo if [ -d "$DOCKER_DIR" ]; then print_info "Docker repository already exists" cd "$DOCKER_DIR" # Check if it's a git repo if [ ! -d .git ]; then print_error "Docker directory exists but is not a git repository" exit 1 fi print_info "Pulling latest changes..." if git pull --ff-only &> /dev/null; then print_success "Docker repository updated" else print_warning "Could not update (you may have local changes)" fi cd .. else print_info "Cloning docker repository..." # Clone with verbose error output local clone_output clone_output=$(git clone "$DOCKER_REPO" docker 2>&1) local clone_status=$? if [ $clone_status -eq 0 ]; then print_success "Docker repository cloned" else print_error "Failed to clone docker repository" echo "" echo -e "${RED}Error details:${NC}" echo "$clone_output" | sed 's/^/ /' echo "" echo -e "${YELLOW}Common causes:${NC}" echo -e " 1. SSH key not added to Bitbucket" echo -e " ${BLUE}→ Add your key at: https://bitbucket.org/account/settings/ssh-keys/${NC}" echo "" echo -e " 2. No repository access" echo -e " ${BLUE}→ Request access from your team lead${NC}" echo "" echo -e " 3. SSH connection issues" echo -e " ${BLUE}→ Test: ssh -T git@bitbucket.org${NC}" echo -e " ${BLUE}→ Should say: 'authenticated via ssh key'${NC}" echo "" echo -e " 4. Wrong SSH key permissions" echo -e " ${BLUE}→ Fix: chmod 600 ~/.ssh/id_rsa${NC}" echo -e " ${BLUE}→ Fix: chmod 700 ~/.ssh${NC}" echo "" exit 1 fi fi } run_full_setup() { print_section "Running Full Setup" if [ ! -f "$DOCKER_DIR/bin/setup.sh" ]; then print_error "Full setup script not found in docker repository" echo -e " ${YELLOW}Expected: $DOCKER_DIR/bin/setup.sh${NC}" exit 1 fi print_info "Handing off to full setup script..." echo "" echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}" echo "" cd "$WORKSPACE_DIR" exec bash "$DOCKER_DIR/bin/setup.sh" "$@" } ############################################################################### # Main Script ############################################################################### main() { # Parse arguments for custom workspace while [[ $# -gt 0 ]]; do case $1 in -*) # Ignore flags, pass to full setup later shift ;; *) # Non-option argument = custom workspace path WORKSPACE_DIR="$1" DOCKER_DIR="${WORKSPACE_DIR}/docker" shift ;; esac done # Print header print_header # Show workspace location with 3-second delay echo "" if [ "$(id -u)" -eq 0 ]; then echo -e "${YELLOW}Running as root - using server workspace location${NC}" else echo -e "${BLUE}Running as developer - using local workspace location${NC}" fi echo "" echo -e "${BOLD}Installation Directory:${NC} ${CYAN}$WORKSPACE_DIR${NC}" echo "" echo -e "${MAGENTA}This will create:${NC}" echo -e " ${CYAN}$WORKSPACE_DIR/${NC} ${YELLOW}# Main workspace folder${NC}" echo -e " ${CYAN}$WORKSPACE_DIR/docker/${NC} ${YELLOW}# Docker configs & infra${NC}" echo -e " ${CYAN}$WORKSPACE_DIR/webapp/${NC} ${YELLOW}# Services you have access to${NC}" echo -e " ${CYAN}$WORKSPACE_DIR/core/${NC}" echo -e " ... etc" echo "" echo -e "${YELLOW}To change the installation directory, cancel (Ctrl+C) and run:${NC}" echo -e " ${YELLOW}curl -fsSL https://retently.dev/setup.sh | bash -s /desired/path${NC}" echo -e " ${BLUE}# Creates: /desired/path/docker, /desired/path/webapp, etc${NC}" echo "" echo -e " ${YELLOW}RETENTLY_WORKSPACE=/desired/path bash <(curl -fsSL https://retently.dev/setup.sh)${NC}" echo "" echo -e "${BLUE}Starting in 3 seconds...${NC}" # 3-second countdown for i in 3 2 1; do echo -ne "\r${BLUE}Starting in $i seconds...${NC}" sleep 1 done echo -ne "\r${GREEN}Starting now! ${NC}\n" echo "" echo -e "${YELLOW}This bootstrap script will:${NC}" echo -e " 1. Check prerequisites (git, SSH keys)" echo -e " 2. Test access to Retently repositories" echo -e " 3. Clone docker configuration repository" echo -e " 4. Run the full setup script (with all repos)" echo "" # Check prerequisites check_prerequisites # Test access to docker repo (requires authentication) if ! test_docker_access; then exit 1 fi # Clone docker repository clone_docker_repo # Run full setup from docker repo run_full_setup "$@" } # Run main function main "$@"