Skip to content

Commit a00b342

Browse files
committed
feat: add mios-overlay.sh and wire into Justfile targets
1 parent e6063c0 commit a00b342

2 files changed

Lines changed: 93 additions & 6 deletions

File tree

Justfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ flight-status:
2626

2727
# Unified initialization (Mode 2: User-space)
2828
init:
29-
@chmod +x tools/mios-init.sh
30-
@./tools/mios-init.sh user
29+
@chmod +x tools/mios-overlay.sh
30+
sudo ./tools/mios-overlay.sh
3131

3232
# System-wide deployment (Mode 1: FHS system install)
3333
deploy:
34-
@chmod +x tools/mios-init.sh
35-
@./tools/mios-init.sh deploy
34+
@chmod +x tools/mios-overlay.sh
35+
sudo ./tools/mios-overlay.sh
3636

3737
# Live ISO Initiation (Mode 0: Overlay onto root)
3838
live-init:
39-
@chmod +x tools/mios-init.sh
40-
@./tools/mios-init.sh live-init
39+
@chmod +x tools/mios-overlay.sh
40+
sudo ./tools/mios-overlay.sh
4141

4242
# Build OCI image locally
4343
build: artifact preflight flight-status

tools/mios-overlay.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
# ============================================================================
3+
# mios-overlay.sh - System-wide FHS Overlay
4+
# ----------------------------------------------------------------------------
5+
# Overlays the local repository (usr/, etc/, var/) onto the system root.
6+
# This "MiOS-ifies" a running host or build-root.
7+
# ============================================================================
8+
set -euo pipefail
9+
10+
# Colors for high-signal output
11+
BLUE="\033[1;34m"
12+
GREEN="\033[1;32m"
13+
YELLOW="\033[1;33m"
14+
RED="\033[1;31m"
15+
NC="\033[0m"
16+
17+
log() { echo -e "${BLUE}[mios-overlay]${NC} $1"; }
18+
warn() { echo -e "${YELLOW}[warn]${NC} $1"; }
19+
error() { echo -e "${RED}[error]${NC} $1"; exit 1; }
20+
21+
# --- Pre-flight ---
22+
[[ "$EUID" -eq 0 ]] || error "Must run as root/sudo"
23+
24+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
25+
cd "$REPO_ROOT"
26+
27+
log "Starting overlay from: $REPO_ROOT"
28+
29+
# --- 1. /usr (Infrastructure & Binaries) ---
30+
if [[ -d "usr" ]]; then
31+
log "Overlaying /usr (excluding /usr/local)..."
32+
tar -C "usr" -cf - --exclude="./local" . | tar -C /usr --no-overwrite-dir -xf -
33+
fi
34+
35+
# --- 2. /usr/local (Custom Binaries / persistent write-through) ---
36+
if [[ -d "usr/local" ]]; then
37+
log "Overlaying /usr/local..."
38+
if [[ -L /usr/local ]]; then
39+
TARGET="$(readlink -f /usr/local)"
40+
log " /usr/local is symlink -> $TARGET; writing through"
41+
mkdir -p "$TARGET"
42+
tar -C "usr/local" -cf - . | tar -C "$TARGET" --no-overwrite-dir -xf -
43+
else
44+
tar -C "usr/local" -cf - . | tar -C /usr/local --no-overwrite-dir -xf -
45+
fi
46+
fi
47+
48+
# --- 3. /etc (System Configuration) ---
49+
if [[ -d "etc" ]]; then
50+
log "Overlaying /etc..."
51+
tar -C "etc" -cf - . | tar -C /etc --no-overwrite-dir -xf -
52+
fi
53+
54+
# --- 4. /var (System State & tmpfiles initialization) ---
55+
# Note: var in repo is usually empty or template-only.
56+
# We rely on systemd-tmpfiles for actual directory creation.
57+
if [[ -d "var" ]] && [[ "$(ls -A var)" ]]; then
58+
log "Overlaying /var..."
59+
tar -C "var" -cf - . | tar -C /var --no-overwrite-dir -xf -
60+
fi
61+
62+
# --- 5. /home -> /var/home (bootc-style alignment) ---
63+
if [[ -d "home" ]]; then
64+
log "Overlaying /home templates to /var/home..."
65+
mkdir -p /var/home
66+
tar -C "home" -cf - . | tar -C /var/home --no-overwrite-dir -xf -
67+
68+
if [[ ! -L /home ]]; then
69+
warn "/home is not a symlink; expected /var/home for bootc parity."
70+
fi
71+
fi
72+
73+
# --- 6. Post-process ---
74+
log "Normalizing systemd unit permissions..."
75+
find /usr/lib/systemd -type f \( -name "*.service" -o -name "*.socket" -o -name "*.timer" \) -exec chmod 644 {} + 2>/dev/null || true
76+
77+
log "Triggering systemd-tmpfiles to initialize /var..."
78+
systemd-tmpfiles --create --prefix=/var 2>/dev/null || true
79+
80+
if command -v restorecon &>/dev/null; then
81+
log "Relabeling SELinux contexts..."
82+
restorecon -RF /usr /etc /var 2>/dev/null || true
83+
fi
84+
85+
echo -e "\n${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
86+
echo -e "${GREEN} ✅ MiOS Overlay Applied Successfully${NC}"
87+
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"

0 commit comments

Comments
 (0)