Creating Modules
Modules are self-contained scripts for specific setup tasks.
Template
#!/bin/bash
# natilius - Module Name
# Brief description
#
# Copyright (C) 2024 Vincent Koc
# License: GPL-3.0-or-later
# MODULE: category/module_name
# Dependencies: homebrew
# Config: MY_VERSION
log_info "Starting module_name setup..."
# Check prerequisites
if ! command -v required_tool &> /dev/null; then
log_warning "required_tool not found, skipping"
return 0
fi
# Idempotent check
if command -v mytool &> /dev/null; then
log_success "Already installed, skipping"
return 0
fi
# Install
log_info "Installing..."
brew install mytool
log_success "module_name setup complete"
Guidelines
- Be idempotent — Safe to run multiple times
- Check prerequisites — Verify dependencies
- Use logging —
log_info,log_success,log_warning,log_error - Handle errors — Don't crash the setup
- Document — Dependencies and config in header
Adding Your Module
- Create:
modules/category/my_module.sh - Add to
natilius.shmodule list - Document in
docs/configuration/modules.md - Add tests
Example
#!/bin/bash
# natilius - MyTool Setup
log_info "Setting up MyTool..."
VERSION="${MYTOOL_VERSION:-latest}"
if command -v mytool &> /dev/null; then
log_success "MyTool already installed"
return 0
fi
brew install mytool || {
log_error "Failed to install MyTool"
return 1
}
log_success "MyTool setup complete"