|
| 1 | +#!/bin/bash |
| 2 | +# Ratifact Installation Script for Linux |
| 3 | +# Complete one-liner setup: installs all dependencies and runs the app |
| 4 | +# This script is designed to be piped directly: bash -c "$(curl -fsSL https://...install.sh)" |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# Color codes |
| 9 | +RED='\033[0;31m' |
| 10 | +GREEN='\033[0;32m' |
| 11 | +YELLOW='\033[1;33m' |
| 12 | +CYAN='\033[0;36m' |
| 13 | +NC='\033[0m' # No Color |
| 14 | + |
| 15 | +# Logging setup |
| 16 | +LOG_FILE="/tmp/ratifact-install-$(date +%Y%m%d_%H%M%S).log" |
| 17 | +exec > >(tee -a "$LOG_FILE") |
| 18 | +exec 2>&1 |
| 19 | + |
| 20 | +echo "Installation log: $LOG_FILE" |
| 21 | + |
| 22 | +# Helper functions |
| 23 | +print_header() { |
| 24 | + echo "" |
| 25 | + echo -e "${CYAN}╔═══════════════════════════════════════════════════════════╗${NC}" |
| 26 | + echo -e "${CYAN}║ Ratifact Installation Script - Linux ║${NC}" |
| 27 | + echo -e "${CYAN}╚═══════════════════════════════════════════════════════════╝${NC}" |
| 28 | + echo "" |
| 29 | +} |
| 30 | + |
| 31 | +print_success() { |
| 32 | + echo -e "${GREEN}✓ $1${NC}" |
| 33 | +} |
| 34 | + |
| 35 | +print_error() { |
| 36 | + echo -e "${RED}❌ ERROR: $1${NC}" |
| 37 | +} |
| 38 | + |
| 39 | +print_warning() { |
| 40 | + echo -e "${YELLOW}⚠️ WARNING: $1${NC}" |
| 41 | +} |
| 42 | + |
| 43 | +print_info() { |
| 44 | + echo -e "${CYAN}ℹ️ $1${NC}" |
| 45 | +} |
| 46 | + |
| 47 | +print_section() { |
| 48 | + echo "" |
| 49 | + echo -e "${CYAN}▶ $1${NC}" |
| 50 | +} |
| 51 | + |
| 52 | +# Start installation |
| 53 | +print_header |
| 54 | + |
| 55 | +# Security check - prompt user to review code |
| 56 | +print_section "Code Review Required" |
| 57 | +echo -e "${YELLOW}========================================${NC}" |
| 58 | +echo -e "${YELLOW}IMPORTANT: Please review the installation script${NC}" |
| 59 | +echo -e "${YELLOW}========================================${NC}" |
| 60 | +echo "This script will:" |
| 61 | +echo " - Check for: Rust, Docker, OpenSSL" |
| 62 | +echo " - Create a .env file with database credentials" |
| 63 | +echo " - Start PostgreSQL container via Docker Compose" |
| 64 | +echo " - Build the Ratifact application" |
| 65 | +echo "" |
| 66 | +echo "Script location: $0" |
| 67 | +echo "" |
| 68 | + |
| 69 | +read -p "$(echo -e ${YELLOW})Have you reviewed the script and wish to continue? (yes/no)${NC}: " review_confirm |
| 70 | +if [[ "$review_confirm" != "yes" ]]; then |
| 71 | + echo -e "${YELLOW}Installation cancelled.${NC}" |
| 72 | + exit 0 |
| 73 | +fi |
| 74 | + |
| 75 | +# Detect Linux distribution |
| 76 | +print_section "Detecting Linux distribution" |
| 77 | +if [ -f /etc/os-release ]; then |
| 78 | + . /etc/os-release |
| 79 | + DISTRO=$ID |
| 80 | + print_success "Distribution detected: $PRETTY_NAME" |
| 81 | +else |
| 82 | + print_warning "Could not detect distribution. Assuming generic Linux." |
| 83 | + DISTRO="generic" |
| 84 | +fi |
| 85 | + |
| 86 | +# Install system dependencies |
| 87 | +print_section "Installing system dependencies" |
| 88 | +case "$DISTRO" in |
| 89 | + ubuntu|debian) |
| 90 | + print_info "Installing packages via apt..." |
| 91 | + sudo apt-get update -qq |
| 92 | + sudo apt-get install -y -qq curl git openssl docker.io make > /dev/null 2>&1 |
| 93 | + sudo usermod -aG docker $USER > /dev/null 2>&1 |
| 94 | + print_success "System packages installed" |
| 95 | + ;; |
| 96 | + fedora) |
| 97 | + print_info "Installing packages via dnf..." |
| 98 | + sudo dnf install -y -q curl git openssl docker make > /dev/null 2>&1 |
| 99 | + sudo usermod -aG docker $USER > /dev/null 2>&1 |
| 100 | + print_success "System packages installed" |
| 101 | + ;; |
| 102 | + arch) |
| 103 | + print_info "Installing packages via pacman..." |
| 104 | + sudo pacman -S --noconfirm curl git openssl docker make > /dev/null 2>&1 |
| 105 | + sudo usermod -aG docker $USER > /dev/null 2>&1 |
| 106 | + print_success "System packages installed" |
| 107 | + ;; |
| 108 | + *) |
| 109 | + print_warning "Unknown distribution. Please install: curl, git, openssl, docker, make" |
| 110 | + ;; |
| 111 | +esac |
| 112 | + |
| 113 | +# Install Rust |
| 114 | +print_section "Installing Rust" |
| 115 | +if command -v rustc &> /dev/null; then |
| 116 | + RUST_VERSION=$(rustc --version) |
| 117 | + print_success "Rust already installed: $RUST_VERSION" |
| 118 | +else |
| 119 | + print_info "Installing Rust via rustup..." |
| 120 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --quiet > /dev/null 2>&1 |
| 121 | + source $HOME/.cargo/env |
| 122 | + print_success "Rust installed: $(rustc --version)" |
| 123 | +fi |
| 124 | + |
| 125 | +# Start Docker service |
| 126 | +print_section "Starting Docker service" |
| 127 | +sudo systemctl start docker > /dev/null 2>&1 || true |
| 128 | +sudo systemctl enable docker > /dev/null 2>&1 || true |
| 129 | + |
| 130 | +# Check if Docker is accessible |
| 131 | +if ! docker ps > /dev/null 2>&1; then |
| 132 | + print_warning "Docker requires sudo. Running with sudo from now on..." |
| 133 | + DOCKER_PREFIX="sudo " |
| 134 | +else |
| 135 | + DOCKER_PREFIX="" |
| 136 | +fi |
| 137 | + |
| 138 | +# Clone repository if not already in it |
| 139 | +if [ ! -f "Cargo.toml" ]; then |
| 140 | + print_section "Cloning Ratifact repository" |
| 141 | + git clone https://github.com/adolfousier/ratifact.git ratifact |
| 142 | + cd ratifact |
| 143 | +fi |
| 144 | + |
| 145 | +# Generate .env file |
| 146 | +print_section "Setting up .env file" |
| 147 | +if [ ! -f ".env" ]; then |
| 148 | + print_info "Generating .env file with random credentials..." |
| 149 | + PASSWORD=$(openssl rand -base64 12 | tr -d "=+/" | cut -c1-16) |
| 150 | + |
| 151 | + cat > .env << EOF |
| 152 | +DATABASE_URL=postgres://ratifact:${PASSWORD}@localhost:25851/ratifact |
| 153 | +POSTGRES_USERNAME=ratifact |
| 154 | +POSTGRES_PASSWORD=${PASSWORD} |
| 155 | +DEBUG_LOGS_ENABLED=true |
| 156 | +EOF |
| 157 | + print_success ".env file generated" |
| 158 | +else |
| 159 | + print_success ".env file already exists" |
| 160 | +fi |
| 161 | + |
| 162 | +# Start PostgreSQL container |
| 163 | +print_section "Starting PostgreSQL" |
| 164 | +print_info "Starting PostgreSQL container via Docker Compose..." |
| 165 | +${DOCKER_PREFIX}docker compose up -d > /dev/null 2>&1 |
| 166 | +print_success "PostgreSQL container started" |
| 167 | +print_info "Waiting for PostgreSQL to be ready (30 seconds)..." |
| 168 | +sleep 30 |
| 169 | + |
| 170 | +# Build and run the project |
| 171 | +print_section "Building Ratifact" |
| 172 | +print_info "Running cargo build..." |
| 173 | +cargo build 2>&1 | grep -E "Finished|error" || true |
| 174 | +if [ ${PIPESTATUS[0]} -eq 0 ]; then |
| 175 | + print_success "Build completed successfully" |
| 176 | +else |
| 177 | + print_error "Build failed" |
| 178 | + exit 1 |
| 179 | +fi |
| 180 | + |
| 181 | +# Completion message |
| 182 | +echo "" |
| 183 | +echo -e "${GREEN}╔═══════════════════════════════════════════════════════════╗${NC}" |
| 184 | +echo -e "${GREEN}║ Setup Completed Successfully! ║${NC}" |
| 185 | +echo -e "${GREEN}╚═══════════════════════════════════════════════════════════╝${NC}" |
| 186 | +echo "" |
| 187 | +echo -e "${CYAN}To run Ratifact:${NC}" |
| 188 | +echo " cargo run" |
| 189 | +echo "" |
| 190 | +echo -e "${CYAN}To build a release version:${NC}" |
| 191 | +echo " cargo build --release" |
| 192 | +echo "" |
| 193 | +echo -e "${CYAN}To run tests:${NC}" |
| 194 | +echo " cargo test" |
| 195 | +echo "" |
| 196 | +echo -e "${YELLOW}Installation log saved to: $LOG_FILE${NC}" |
| 197 | +echo "" |
0 commit comments