homelab infrastructure services
1#!/bin/bash
2
3# Tinsnip Machine Setup - Service Environment Creation
4# Creates isolated environments for running services with NFS and rootless Docker
5
6set -euo pipefail
7
8SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
10# Source shared library functions
11source "$SCRIPT_DIR/scripts/lib.sh"
12
13log() {
14 log_with_prefix "Machine Setup" "$@"
15}
16
17error() {
18 error_with_prefix "Machine Setup" "$@"
19}
20
21show_help() {
22 cat << EOF
23Tinsnip Machine Setup
24
25Creates service environments with:
26- Service-specific users following UID conventions
27- NFS-backed persistent storage
28- Rootless Docker with privileged port support
29- XDG directory integration
30
31Usage:
32 $0 # Interactive setup
33 $0 <service> <env> <nas> # Direct setup
34
35Examples:
36 $0 # Prompts for service details
37 $0 gazette prod DS412plus # Sets up gazette-prod environment
38 $0 lldap test 192.168.1.100
39
40Services: gazette, lldap, redis, prometheus
41Environments: prod, test
42EOF
43}
44
45interactive_setup() {
46 echo "Tinsnip Machine Setup"
47 echo "===================="
48 echo
49 echo "This will create a service environment with:"
50 echo "- Dedicated user with UID convention (11xxx)"
51 echo "- NFS mount for persistent data"
52 echo "- Rootless Docker with container support"
53 echo "- XDG directory integration"
54 echo
55
56 # Get service name
57 echo "Available services: gazette, lldap, redis, prometheus"
58 read -p "Service name: " service_name
59
60 # Get environment
61 echo "Available environments: test, prod"
62 read -p "Environment: " service_env
63
64 # Get NAS server
65 read -p "NAS server (hostname or IP): " nas_server
66
67 echo
68 echo "Configuration:"
69 echo " Service: $service_name"
70 echo " Environment: $service_env"
71 echo " NAS: $nas_server"
72 echo
73
74 # Proceeding with setup
75
76 # Run service setup
77 exec "$SCRIPT_DIR/scripts/setup_service.sh" "$service_name" "$service_env" "$nas_server"
78}
79
80main() {
81 # Handle help flag
82 if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
83 show_help
84 exit 0
85 fi
86
87 # Check if running with parameters
88 if [[ $# -eq 3 ]]; then
89 # Direct setup with parameters
90 exec "$SCRIPT_DIR/scripts/setup_service.sh" "$1" "$2" "$3"
91 elif [[ $# -eq 0 ]]; then
92 # Interactive setup
93 interactive_setup
94 else
95 echo "Error: Invalid number of arguments"
96 echo
97 show_help
98 exit 1
99 fi
100}
101
102main "$@"