Automation Scripts
Reference for the automation framework in .scripts/. These scripts handle setup, configuration, and maintenance across all nodes.
Bootstrap Framework
bootstrap.sh
Purpose: Universal dependency sourcing and environment setup
Location: .scripts/bootstrap.sh
Usage Pattern:
| |
Functions Provided:
- Automatic repository root detection and navigation
- Library loading (
common.sh,validation.sh,templates.sh,services.sh,init.sh) - Environment variable setup (
SCRIPTS_ROOT) - Consistent error handling preparation
Integration: All automation scripts must source the bootstrap system as their first operation to ensure consistent environment and library availability.
Core Library Functions
common.sh
Purpose: Core utilities, logging, and fundamental operations
Location: .scripts/lib/common.sh
Logging Functions
| |
Repository Navigation
| |
Argument Validation
| |
Template Rendering
| |
Telegram Integration
| |
Utility Functions
| |
services.sh
Purpose: Systemd service management utilities
Location: .scripts/lib/services.sh
Service Status Functions
| |
Service Control Functions
| |
Service Monitoring Functions
| |
validation.sh
Purpose: Input validation and system verification
Location: .scripts/lib/validation.sh
File System Validation
| |
System Validation
| |
Network and Resource Validation
| |
templates.sh
Purpose: Configuration template rendering
Location: .scripts/lib/templates.sh
Template Rendering Functions
| |
Features:
- Environment variable substitution via
envsubst - Atomic file operations with
.tmpfiles - Batch directory processing with structure preservation
- External variable file support
init.sh
Purpose: Declarative service initialization framework
Location: .scripts/lib/init.sh
Core Initialization Functions
| |
Helper Functions
| |
Operational Scripts
Infrastructure Management
setup-tiers
Purpose: Complete data tier infrastructure setup
Location: .scripts/ops/setup-tiers
Usage:
| |
Operations Performed:
- Directory Creation: Ensures all tier base directories exist
- Project Discovery: Automatically discovers all projects in node directory
- Symbolic Link Creation: Creates
@tier1,@tier2,@tier3links for each project - Environment File Linking: Links
.envfiles to@tier1for configuration - Host Link Creation: Creates
.host/@tierlinks for system-level access - Shared Structure Setup: Establishes shared directory hierarchy with cross-links
Safety Features:
- Interactive confirmation for existing symlink replacement
- Validation of target directory existence and permissions
- Comprehensive logging of all operations
- Safe handling of non-symlink existing paths
sync-tiers
Purpose: Automated data tier synchronization and backup
Location: .scripts/ops/sync-tiers
Usage:
| |
Process Flow:
- Validation Phase: Confirms node directory and docker-compose.yml existence
- Tier 1 Sync: Executes
rclone1Docker service for critical configuration data - Tier 2 Sync: Executes
rclone2Docker service for application data - Error Handling: Automatic error trapping with detailed Telegram notifications
- Success Reporting: Completion confirmation with operation summary
Docker Compose Integration:
| |
Configuration Management
envsubst-directory
Purpose: Batch template rendering for entire directories
Location: .scripts/ops/envsubst-directory
Usage:
| |
Features:
- Recursive Processing: Discovers all files in source directory recursively
- Structure Preservation: Maintains relative directory structure in destination
- Backup Creation: Backs up existing destination files to
/tmpwith timestamps - Environment Substitution: Uses
envsubstfor variable replacement - Atomic Operations: Creates temporary files before final placement
File Processing:
- Processes all files (not just
.templateextensions) - Handles filenames with spaces and special characters safely
- Creates destination subdirectories as needed
- Provides detailed logging for each file processed
envsubst-crontab
Purpose: Crontab installation from templates with environment variables
Location: .scripts/ops/envsubst-crontab
Usage:
| |
Standard Environment Variables:
| |
Safety Features:
- Backup Creation: Current crontab backed up before installation
- Validation: Rendered crontab validated before installation
- Preview: Shows rendered crontab content before installation
- Rollback: Automatic rollback on installation failure
- Empty Check: Prevents installation of empty crontabs
envsubst-ufw
Purpose: UFW firewall rule application with template support
Location: .scripts/ops/envsubst-ufw
Usage:
| |
Rule Processing:
- Docker Service Rules: Processes
*.rulesfiles usingufw-dockercommand - Host Rules: Processes optional host-level UFW rules
- Idempotent Application: Rules can be safely re-applied
- Comment Handling: Ignores blank lines and
#comments - Error Handling: Stops on first rule failure with detailed error reporting
Rule File Format:
| |
Development and Maintenance
lint-docker-compose
Purpose: Docker Compose file linting and formatting
Location: .scripts/ops/lint-docker-compose
Usage:
| |
Features:
- Automatic Fixing: Uses
dclintwith--fixoption for automatic corrections - Pre-commit Integration:
--hookmode processes only staged files - Exclusions: Excludes
data,state,vaultdirectories from linting - Re-staging: In hook mode, automatically re-stages fixed files
- Recursive Processing: Processes all
docker-compose*.ymlfiles in repository
Pre-commit Hook Integration:
| |
check-package-updates
Purpose: System package update monitoring with notifications
Location: .scripts/ops/check-package-updates
Usage:
| |
Process:
- Package List Update: Runs
apt-get updateto refresh package information - Update Detection: Uses
apt-get --just-print upgradeto identify available updates - Formatting: Formats package list for Telegram notification with counts
- Notification: Sends Telegram alert with update details and package names
- Error Handling: Automatic error trapping with failure notifications
Output Format:
5 updates available: `package1`, `package2`, `package3`, `package4`, `package5`sync-remote
Purpose: Git repository synchronization for node changes
Location: .scripts/ops/sync-remote
Usage:
| |
Git Operations:
- Staging: Automatically stages all changes in node directory
- Branch Management: Creates or switches to
sync/<NODE>branch - Bot Identity: Configures commits with “Adam Jensen [bot]” identity
- Commit Creation: Creates commits with timestamp and node identification
- Rebase Integration: Rebases onto
origin/trunkwith conflict detection - Force Push: Uses
--force-with-leasefor safe remote updates
Branch Strategy:
- Branch Pattern:
sync/<NODE>(e.g.,sync/icarus,sync/daedalus) - Base Branch:
origin/trunk - Commit Message:
[NODE] Auto-commit: TIMESTAMP - Conflict Handling: Automatic rebase abort and notification on conflicts
Host-Specific Scripts
Node Initialization Scripts
Each host maintains numbered initialization scripts in .host/.scripts/:
UFW Firewall Initialization
Pattern: <NODE>/.host/.scripts/10-ufw
Common Implementation:
| |
Cron Job Initialization
Pattern: <NODE>/.host/.scripts/20-cron or <NODE>/.host/.scripts/30-cron
Common Implementation:
| |
API Documentation
Automation Script API
Standard Exit Codes
| |
Environment Variable Conventions
| |
Logging API
All scripts support consistent logging through the common library:
| |
Error Handling API
Standardized error handling with automatic notifications:
| |
Docker Compose Integration API
Service Discovery Pattern
Services are discovered through Docker labels:
| |
Health Check Pattern
Services implement standardized health checks:
| |
Network Assignment Pattern
Services connect to standardized network types:
| |
Usage Examples
Complete Service Setup
| |
Maintenance Workflow
| |
Development Workflow
| |
This reference covers the key scripts for managing and maintaining the automation framework.