clawdie-iso/firstboot/shell-system.sh
Sam & Claude c3599469e0 feat: rename cloud→vps, fix domain naming (Sam & Claude)
Breaking changes:
- --target cloud renamed to --target vps
- Default domain changed from "home.arpa" to "${agentname}.home.arpa"

Changes:
- build.cfg: TARGET="vps" (was cloud)
- build.sh: --target vps, error messages updated
- firstboot.sh: AGENT_DOMAIN defaults to ${agentname}.home.arpa
- vps/firstboot-vps.sh: TARGET=vps
- Rename cloud-path-test.sh → vps-path-test.sh
- Update integration-test.sh: clawdie.home.arpa
- Update MODULE-MANIFEST.md, shell-system.sh examples
- Update BUILD.md: "VPS target" (was "VPS/cloud target")

Why:
- "vps" is more precise than "cloud" (VPS != always cloud)
- ${agentname}.home.arpa follows mDNS standard
- .local collides with mDNS (as noted in shell-env.sh)

Migration: Update build scripts from --target cloud to --target vps
2026-06-04 20:04:22 +02:00

233 lines
6.6 KiB
Bash
Executable file

#!/bin/sh
# Clawdie Shell — System Configuration Module
# Purpose: System-level config (rc.conf, hostname, services, environment)
# Author: Clawdie Project
# POSIX-compliant (no bash-isms)
set -eu
# FreeBSD /bin/sh doesn't support trap ERR
# Configuration (can be overridden for testing)
RC_CONF="${RC_CONF:-/etc/rc.conf}"
HOSTNAME_FILE="${HOSTNAME_FILE:-/etc/hostname}"
PROFILE_DIR="${PROFILE_DIR:-/etc/profile.d}"
LOG_FILE="${LOG_FILE:-/var/log/clawdie-firstboot.log}"
PROGRESS_FILE="${PROGRESS_FILE:-/var/log/clawdie-firstboot.progress}"
# Derived from wizard inputs (caller sets these)
# TZ - Timezone (e.g., "Europe/Ljubljana")
# AGENT_DOMAIN - FQDN (e.g., "clawdie.home.arpa" for local, or public domain)
# DETECTED_GPU - GPU vendor from gpu module (intel, amd, nvidia, vmware, vesa)
# ============================================================================
# MAIN ENTRY POINT
# ============================================================================
clawdie_shell_system_config() {
# Main orchestrator
log_msg "[system] Starting system configuration"
if [ -z "${TZ:-}" ]; then
log_msg "[system] ERROR: TZ not set"
return 1
fi
if [ -z "${AGENT_DOMAIN:-}" ]; then
log_msg "[system] ERROR: AGENT_DOMAIN not set"
return 1
fi
# Write rc.conf with timezone and services
clawdie_shell_system_write_rcconf
log_msg "[system] Updated rc.conf"
# Set hostname
clawdie_shell_system_set_hostname
log_msg "[system] Set hostname"
# Setup environment
clawdie_shell_system_setup_env
log_msg "[system] Setup environment"
# Enable services
clawdie_shell_system_enable_services
log_msg "[system] Enabled services"
echo "[SYSTEM] COMPLETE" >> "$PROGRESS_FILE"
log_msg "[system] System configuration complete"
}
# ============================================================================
# RC.CONF CONFIGURATION
# ============================================================================
clawdie_shell_system_write_rcconf() {
# Update /etc/rc.conf with:
# - timezone
# - service configurations (dbus, hald, seatd, lightdm)
# - Lumina desktop settings
if [ ! -f "$RC_CONF" ]; then
log_msg "[system] Creating $RC_CONF"
touch "$RC_CONF"
fi
# Helper to set or update rc.conf variable
clawdie_shell_system_sysrc "timezone=$TZ"
clawdie_shell_system_sysrc "dbus_enable=YES"
clawdie_shell_system_sysrc "hald_enable=YES"
clawdie_shell_system_sysrc "seatd_enable=YES"
clawdie_shell_system_sysrc "display_manager=lightdm"
clawdie_shell_system_sysrc "lightdm_enable=YES"
log_msg "[system] Wrote rc.conf configuration"
}
clawdie_shell_system_sysrc() {
# Add or update a variable in rc.conf
# Input: VAR=VALUE
local var_assignment="$1"
local var_name var_value
var_name=$(echo "$var_assignment" | cut -d= -f1)
var_value=$(echo "$var_assignment" | cut -d= -f2-)
# Check if var already set (idempotence)
if grep -q "^${var_name}=" "$RC_CONF" 2>/dev/null; then
# Update existing (use | as delimiter to avoid issues with / in values)
sed -i '' "s|^${var_name}=.*|${var_assignment}|" "$RC_CONF"
else
# Append new
echo "$var_assignment" >> "$RC_CONF"
fi
}
# ============================================================================
# HOSTNAME CONFIGURATION
# ============================================================================
clawdie_shell_system_set_hostname() {
# Set /etc/hostname and apply live
if [ ! -f "$HOSTNAME_FILE" ]; then
touch "$HOSTNAME_FILE"
fi
# Write to file
echo "$AGENT_DOMAIN" > "$HOSTNAME_FILE"
# Apply live (if not in chroot)
if command -v hostname >/dev/null 2>&1; then
hostname "$AGENT_DOMAIN" 2>/dev/null || true
fi
log_msg "[system] Set hostname to $AGENT_DOMAIN"
}
# ============================================================================
# ENVIRONMENT SETUP
# ============================================================================
clawdie_shell_system_setup_env() {
# Create /etc/profile.d/clawdie.sh for environment variables
# Sets up npm global paths and other Clawdie-specific variables
if [ ! -d "$PROFILE_DIR" ]; then
mkdir -p "$PROFILE_DIR"
fi
local clawdie_profile="$PROFILE_DIR/clawdie.sh"
cat > "$clawdie_profile" <<'EOF'
# Clawdie-AI environment setup
# Adds npm global bin directory to PATH
export npm_config_prefix="${HOME}/.npm-global"
export PATH="${HOME}/.npm-global/bin:${PATH}"
EOF
chmod 644 "$clawdie_profile"
log_msg "[system] Created $clawdie_profile"
}
# ============================================================================
# SERVICE ENABLEMENT
# ============================================================================
clawdie_shell_system_enable_services() {
# Enable and start required services
# Safe to fail if running in chroot (first boot)
local services="dbus hald seatd lightdm"
for service in $services; do
if command -v service >/dev/null 2>&1; then
# Try to start service
service "$service" onestart 2>/dev/null || {
log_msg "[system] Could not start $service (expected in chroot)"
}
fi
done
log_msg "[system] Service enablement complete"
}
# ============================================================================
# VALIDATION
# ============================================================================
clawdie_shell_system_validate() {
# Verify system configuration completed
if [ ! -f "$RC_CONF" ]; then
echo "ERROR: rc.conf not found" >&2
return 1
fi
# Check timezone is set
if ! grep -q "^timezone=" "$RC_CONF"; then
echo "ERROR: timezone not set in rc.conf" >&2
return 1
fi
# Check hostname file exists
if [ ! -f "$HOSTNAME_FILE" ]; then
echo "ERROR: $HOSTNAME_FILE not created" >&2
return 1
fi
# Check environment profile exists
if [ ! -f "$PROFILE_DIR/clawdie.sh" ]; then
echo "ERROR: $PROFILE_DIR/clawdie.sh not created" >&2
return 1
fi
log_msg "[system] Validation passed"
return 0
}
# ============================================================================
# UTILITY: Logging
# ============================================================================
log_msg() {
local msg="$1"
echo "$msg" >> "$LOG_FILE" 2>/dev/null || true
}
# ============================================================================
# Export for use by firstboot.sh
# ============================================================================
case "${0##*/}" in
clawdie-shell-system.sh)
# Direct execution (for testing)
clawdie_shell_system_config
clawdie_shell_system_validate
;;
*)
# Sourced from another script — functions available
;;
esac