#!/bin/bash # Tinsnip Machine Setup - Service Environment Creation # Creates isolated environments for running services with NFS and rootless Docker set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Source shared library functions source "$SCRIPT_DIR/scripts/lib.sh" log() { log_with_prefix "Machine Setup" "$@" } error() { error_with_prefix "Machine Setup" "$@" } show_help() { cat << EOF Tinsnip Machine Setup Creates service environments with: - Service-specific users following UID conventions - NFS-backed persistent storage - Rootless Docker with privileged port support - XDG directory integration Usage: $0 # Interactive setup $0 # Direct setup Examples: $0 # Prompts for service details $0 gazette prod DS412plus # Sets up gazette-prod environment $0 lldap test 192.168.1.100 Services: gazette, lldap, redis, prometheus Environments: prod, test EOF } interactive_setup() { echo "Tinsnip Machine Setup" echo "====================" echo echo "This will create a service environment with:" echo "- Dedicated user with UID convention (11xxx)" echo "- NFS mount for persistent data" echo "- Rootless Docker with container support" echo "- XDG directory integration" echo # Get service name echo "Available services: gazette, lldap, redis, prometheus" read -p "Service name: " service_name # Get environment echo "Available environments: test, prod" read -p "Environment: " service_env # Get NAS server read -p "NAS server (hostname or IP): " nas_server echo echo "Configuration:" echo " Service: $service_name" echo " Environment: $service_env" echo " NAS: $nas_server" echo # Proceeding with setup # Run service setup exec "$SCRIPT_DIR/scripts/setup_service.sh" "$service_name" "$service_env" "$nas_server" } main() { # Handle help flag if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then show_help exit 0 fi # Check if running with parameters if [[ $# -eq 3 ]]; then # Direct setup with parameters exec "$SCRIPT_DIR/scripts/setup_service.sh" "$1" "$2" "$3" elif [[ $# -eq 0 ]]; then # Interactive setup interactive_setup else echo "Error: Invalid number of arguments" echo show_help exit 1 fi } main "$@"