homelab infrastructure services
at fix-docker-install 171 lines 6.2 kB view raw
1#!/bin/bash 2 3set -euo pipefail 4 5# tinsnip installer - Downloads and sets up tinsnip infrastructure platform 6 7REPO_URL="https://tangled.sh/dynamicalsystem.com/tinsnip" 8BRANCH="main" 9INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/opt/dynamicalsystem.tinsnip}" 10INSTALLER_VERSION="12f7992" # Updated automatically on commit 11 12# Service repository options 13SERVICE_REPO_URL="${SERVICE_REPO_URL:-}" 14SERVICE_INSTALL_DIR="${SERVICE_INSTALL_DIR:-$HOME/.local/opt/dynamicalsystem.service}" 15 16log() { 17 echo "[Installer] $*" 18} 19 20error() { 21 log "ERROR: $*" >&2 22 exit 1 23} 24 25download_file() { 26 local file_path="$1" 27 local dest_path="$2" 28 local url="${REPO_URL}/raw/${BRANCH}/${file_path}" 29 local filename=$(basename "$file_path") 30 31 log " $filename" 32 33 if command -v curl &> /dev/null; then 34 if curl -fsSL "$url" -o "$dest_path" 2>/dev/null; then 35 chmod +x "$dest_path" 2>/dev/null || true 36 return 0 37 fi 38 fi 39 40 error "Failed to download $file_path" 41} 42 43clone_with_git() { 44 log "Cloning repository with git..." 45 if ! command -v git &> /dev/null; then 46 log "Git not found, installing..." 47 sudo apt-get update -qq && sudo apt-get install -y git 48 fi 49 50 if ! git clone "git@tangled.sh:dynamicalsystem.com/tinsnip" "$INSTALL_DIR"; then 51 error "Failed to clone repository. Make sure you have SSH access to git@tangled.sh" 52 fi 53} 54 55# Infer service repo URL from tinsnip repo URL 56infer_service_repo() { 57 local tinsnip_url="$1" 58 # Replace "tinsnip" with "service" in the URL 59 echo "${tinsnip_url/tinsnip/service}" 60} 61 62# Clone or download service repository 63install_service_catalog() { 64 local service_repo="${SERVICE_REPO_URL:-$(infer_service_repo "$REPO_URL")}" 65 66 log "Installing service catalog..." 67 log " Repository: $service_repo" 68 69 if [[ -d "$SERVICE_INSTALL_DIR" ]]; then 70 log " Removing: $SERVICE_INSTALL_DIR" 71 rm -rf "$SERVICE_INSTALL_DIR" 72 fi 73 74 mkdir -p "$(dirname "$SERVICE_INSTALL_DIR")" 75 76 # Try git clone first 77 if command -v git &> /dev/null; then 78 # Convert HTTPS URL to git URL for cloning 79 local git_url="${service_repo/https:\/\/tangled.sh\//git@tangled.sh:}" 80 81 if git clone "$git_url" "$SERVICE_INSTALL_DIR" 2>/dev/null; then 82 log " Service catalog installed: $SERVICE_INSTALL_DIR" 83 return 0 84 fi 85 fi 86 87 # Fallback to downloading files if git fails 88 log "Git clone failed, downloading service files..." 89 # For now, skip download fallback as service repo structure may vary 90 log "WARNING: Could not clone service repository. Services will not be available." 91 log "You can manually clone the service repository later:" 92 log " git clone $service_repo $SERVICE_INSTALL_DIR" 93} 94 95main() { 96 log "tinsnip Infrastructure Installer (version: $INSTALLER_VERSION)" 97 log "==============================================================" 98 99 cd ~ || error "Failed to change to home directory" 100 101 if [[ ! -f /etc/os-release ]] || ! grep -q "Ubuntu" /etc/os-release; then 102 error "This installer requires Ubuntu" 103 fi 104 105 if [[ -d "$INSTALL_DIR" ]]; then 106 log "Tinsnip directory already exists. Removing for fresh installation..." 107 log " Removing: $INSTALL_DIR" 108 rm -rf "$INSTALL_DIR" 109 fi 110 111 log " Creating: $INSTALL_DIR" 112 mkdir -p "$INSTALL_DIR"/{scripts,machine/scripts,config} 113 114 log "Downloading setup files..." 115 116 # Download main files 117 download_file "setup.sh" "$INSTALL_DIR/setup.sh" 118 download_file "README.md" "$INSTALL_DIR/README.md" 119 download_file "fresh-install.sh" "$INSTALL_DIR/fresh-install.sh" 120 121 # Download legacy scripts 122 download_file "scripts/create_tinsnip_user.sh" "$INSTALL_DIR/scripts/create_tinsnip_user.sh" 123 download_file "scripts/setup_rootless_docker.sh" "$INSTALL_DIR/scripts/setup_rootless_docker.sh" 124 download_file "scripts/deploy_service.sh" "$INSTALL_DIR/scripts/deploy_service.sh" 125 126 # Download machine infrastructure (the important stuff!) 127 download_file "machine/setup.sh" "$INSTALL_DIR/machine/setup.sh" 128 download_file "machine/validate.sh" "$INSTALL_DIR/machine/validate.sh" 129 download_file "machine/scripts/lib.sh" "$INSTALL_DIR/machine/scripts/lib.sh" 130 download_file "machine/scripts/setup_service.sh" "$INSTALL_DIR/machine/scripts/setup_service.sh" 131 download_file "machine/scripts/setup_station.sh" "$INSTALL_DIR/machine/scripts/setup_station.sh" 132 download_file "machine/scripts/mount_nas.sh" "$INSTALL_DIR/machine/scripts/mount_nas.sh" 133 download_file "machine/scripts/install_docker.sh" "$INSTALL_DIR/machine/scripts/install_docker.sh" 134 download_file "machine/scripts/generate_nfs_exports.sh" "$INSTALL_DIR/machine/scripts/generate_nfs_exports.sh" 135 136 # Always install service catalog 137 install_service_catalog 138 139 log "Installation complete!" 140 log "" 141 log "Next steps:" 142 log "1. cd $INSTALL_DIR" 143 log "2. Set up machine infrastructure for a service:" 144 log " ./machine/setup.sh <service> <environment> <nas-server>" 145 log "" 146 log "Examples:" 147 148 if [[ -d "$SERVICE_INSTALL_DIR" ]]; then 149 # Get list of available services from the catalog 150 for service in $(ls -1 "$SERVICE_INSTALL_DIR" 2>/dev/null | grep -v README | head -3); do 151 log " ./machine/setup.sh $service prod DS412plus.local" 152 done 153 log " ./machine/setup.sh gateway test 192.168.1.100" 154 log "" 155 log "Parameters:" 156 log " <service> - Service name (e.g., gazette, lldap, gateway)" 157 log " <environment> - Environment (prod, test, dev)" 158 log " <nas-server> - NFS server hostname or IP" 159 log "" 160 else 161 log " ./machine/setup.sh gateway prod DS412plus.local" 162 log " ./machine/setup.sh lldap test 192.168.1.100" 163 log "" 164 log "Parameters:" 165 log " <service> - Service name (e.g., gazette, lldap, gateway)" 166 log " <environment> - Environment (prod, test, dev)" 167 log " <nas-server> - NFS server hostname or IP" 168 fi 169} 170 171main "$@"