Skip to content

Commit a3bd3f9

Browse files
committed
Migration service
1 parent 4805e36 commit a3bd3f9

5 files changed

Lines changed: 211 additions & 0 deletions

File tree

build_files/base/01-base-system.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ systemctl enable bluetooth.service
102102
systemctl enable power-profiles-daemon.service
103103
systemctl enable flatpak-add-flathub.service
104104
systemctl enable iwd.service
105+
systemctl enable hypercube-migrate.service
105106

106107
### Disable services we don't need
107108
systemctl disable gdm.service 2>/dev/null || true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Hypercube System Migrations
3+
DefaultDependencies=no
4+
Before=greetd.service
5+
After=local-fs.target
6+
7+
[Service]
8+
Type=oneshot
9+
ExecStart=/usr/bin/just --justfile /usr/share/ublue-os/justfile migrate
10+
RemainAfterExit=true
11+
12+
[Install]
13+
WantedBy=multi-user.target
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Migration: Remove cage references from greetd config
3+
4+
set -euo pipefail
5+
6+
CONFIG="/etc/greetd/config.toml"
7+
8+
# Skip if file doesn't exist
9+
[[ -f "$CONFIG" ]] || exit 0
10+
11+
# Skip if already migrated (no cage reference)
12+
grep -q "cage" "$CONFIG" || exit 0
13+
14+
echo "Updating greetd config to remove cage..."
15+
16+
cat > "$CONFIG" << 'EOF'
17+
[terminal]
18+
vt = 1
19+
20+
[default_session]
21+
command = "hypercube-greeter"
22+
user = "greeter"
23+
24+
[initial_session]
25+
command = "hypercube-onboard --config /usr/share/hypercube/config/hypercube-onboard/onboard.toml"
26+
user = "root"
27+
EOF
28+
29+
echo "greetd config updated"
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# vim: set ft=make :
2+
# Hypercube system migration commands
3+
4+
# Run all pending system migrations
5+
migrate:
6+
#!/usr/bin/bash
7+
set -uo pipefail
8+
9+
MIGRATIONS_DIR="/usr/share/hypercube/migrations"
10+
STATE_DIR="/var/lib/hypercube/migrations"
11+
COMPLETED_FILE="$STATE_DIR/completed"
12+
13+
log() { echo "[migrate] $*"; }
14+
warn() { echo "[migrate] WARNING: $*" >&2; }
15+
16+
mkdir -p "$STATE_DIR"
17+
touch "$COMPLETED_FILE"
18+
19+
if [[ ! -d "$MIGRATIONS_DIR" ]]; then
20+
log "No migrations directory found"
21+
exit 0
22+
fi
23+
24+
shopt -s nullglob
25+
migrations=("$MIGRATIONS_DIR"/*.sh)
26+
27+
if [[ ${#migrations[@]} -eq 0 ]]; then
28+
log "No migrations found"
29+
exit 0
30+
fi
31+
32+
failed=0
33+
for migration in "${migrations[@]}"; do
34+
name=$(basename "$migration")
35+
36+
if grep -qxF "$name" "$COMPLETED_FILE" 2>/dev/null; then
37+
continue
38+
fi
39+
40+
log "Running: $name"
41+
if bash "$migration"; then
42+
echo "$name" >> "$COMPLETED_FILE"
43+
log "$name completed"
44+
else
45+
warn "$name FAILED - will retry next boot"
46+
((failed++)) || true
47+
fi
48+
done
49+
50+
if [[ $failed -gt 0 ]]; then
51+
warn "$failed migration(s) failed"
52+
fi
53+
54+
# List all migrations and their status
55+
migrate-status:
56+
#!/usr/bin/bash
57+
set -euo pipefail
58+
59+
MIGRATIONS_DIR="/usr/share/hypercube/migrations"
60+
STATE_DIR="/var/lib/hypercube/migrations"
61+
COMPLETED_FILE="$STATE_DIR/completed"
62+
63+
mkdir -p "$STATE_DIR"
64+
touch "$COMPLETED_FILE"
65+
66+
echo "Hypercube Migrations"
67+
echo "===================="
68+
echo ""
69+
70+
pending=0
71+
completed=0
72+
73+
shopt -s nullglob
74+
for migration in "$MIGRATIONS_DIR"/*.sh; do
75+
name=$(basename "$migration")
76+
if grep -qxF "$name" "$COMPLETED_FILE" 2>/dev/null; then
77+
echo " [done] $name"
78+
((completed++)) || true
79+
else
80+
echo " [pending] $name"
81+
((pending++)) || true
82+
fi
83+
done
84+
85+
echo ""
86+
echo "Total: $completed completed, $pending pending"
87+
88+
# Mark a migration as completed (after manual fix)
89+
migrate-mark-done NAME:
90+
#!/usr/bin/bash
91+
set -euo pipefail
92+
93+
MIGRATIONS_DIR="/usr/share/hypercube/migrations"
94+
STATE_DIR="/var/lib/hypercube/migrations"
95+
COMPLETED_FILE="$STATE_DIR/completed"
96+
NAME="{{ NAME }}"
97+
98+
if [[ ! -f "$MIGRATIONS_DIR/$NAME" ]]; then
99+
echo "Error: Migration '$NAME' not found" >&2
100+
echo "Run 'ujust migrate-status' to see available migrations"
101+
exit 1
102+
fi
103+
104+
mkdir -p "$STATE_DIR"
105+
touch "$COMPLETED_FILE"
106+
107+
if grep -qxF "$NAME" "$COMPLETED_FILE" 2>/dev/null; then
108+
echo "Migration '$NAME' already marked as done"
109+
else
110+
echo "$NAME" >> "$COMPLETED_FILE"
111+
echo "Migration '$NAME' marked as done"
112+
fi
113+
114+
# Reset a migration to pending (will re-run on next boot)
115+
migrate-reset NAME:
116+
#!/usr/bin/bash
117+
set -euo pipefail
118+
119+
MIGRATIONS_DIR="/usr/share/hypercube/migrations"
120+
STATE_DIR="/var/lib/hypercube/migrations"
121+
COMPLETED_FILE="$STATE_DIR/completed"
122+
NAME="{{ NAME }}"
123+
124+
if [[ ! -f "$MIGRATIONS_DIR/$NAME" ]]; then
125+
echo "Error: Migration '$NAME' not found" >&2
126+
echo "Run 'ujust migrate-status' to see available migrations"
127+
exit 1
128+
fi
129+
130+
if grep -qxF "$NAME" "$COMPLETED_FILE" 2>/dev/null; then
131+
tmp=$(mktemp)
132+
grep -vxF "$NAME" "$COMPLETED_FILE" > "$tmp" || true
133+
sudo mv "$tmp" "$COMPLETED_FILE"
134+
echo "Migration '$NAME' reset to pending"
135+
else
136+
echo "Migration '$NAME' is already pending"
137+
fi
138+
139+
# Force re-run a specific migration now
140+
migrate-rerun NAME:
141+
#!/usr/bin/bash
142+
set -euo pipefail
143+
144+
MIGRATIONS_DIR="/usr/share/hypercube/migrations"
145+
STATE_DIR="/var/lib/hypercube/migrations"
146+
COMPLETED_FILE="$STATE_DIR/completed"
147+
NAME="{{ NAME }}"
148+
149+
if [[ ! -f "$MIGRATIONS_DIR/$NAME" ]]; then
150+
echo "Error: Migration '$NAME' not found" >&2
151+
echo "Run 'ujust migrate-status' to see available migrations"
152+
exit 1
153+
fi
154+
155+
mkdir -p "$STATE_DIR"
156+
touch "$COMPLETED_FILE"
157+
158+
echo "Running migration: $NAME"
159+
if sudo bash "$MIGRATIONS_DIR/$NAME"; then
160+
if ! grep -qxF "$NAME" "$COMPLETED_FILE" 2>/dev/null; then
161+
echo "$NAME" >> "$COMPLETED_FILE"
162+
fi
163+
echo "Migration '$NAME' completed"
164+
else
165+
echo "Migration '$NAME' FAILED" >&2
166+
exit 1
167+
fi

system_files/shared/usr/share/ublue-os/justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ import "/usr/share/ublue-os/just/50-akmods.just"
2727
import? "/usr/share/ublue-os/just/60-hypercube.just"
2828
import? "/usr/share/ublue-os/just/61-nvim.just"
2929
import? "/usr/share/ublue-os/just/62-ai.just"
30+
import? "/usr/share/ublue-os/just/63-migrate.just"

0 commit comments

Comments
 (0)