-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminitel-sim
More file actions
executable file
·78 lines (67 loc) · 2.21 KB
/
minitel-sim
File metadata and controls
executable file
·78 lines (67 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
# MinitelOS Simulator — build (si besoin) et lance le simulateur natif
#
# Usage:
# ./minitel-sim [OPTIONS]
#
# Options:
# -b, --baud <rate> Vitesse simulée en bauds (1200, 2400, 4800, 9600)
# --baud=<rate> Même effet
# --ctf Mode CTF (env native-ctf, sim_fs/)
# --reset Réinitialise les fichiers de session du mode courant
# --build Force un rebuild complet avant le lancement
# -h, --help Affiche cette aide
#
# Exemples:
# ./minitel-sim Lancement standard avec first boot
# ./minitel-sim --ctf Lancement en mode CTF
# ./minitel-sim --baud=1200 Simule une connexion à 1200 bauds
# ./minitel-sim --reset Remet à zéro la session courante
# ./minitel-sim --ctf --reset Reset du mode CTF
set -euo pipefail
ENV="native"
BINARY=".pio/build/native/program"
SIM_FS="sim_fs_standard"
print_help() {
grep '^#' "$0" | sed 's/^# \?//'
exit 0
}
rebuild() {
echo "[sim] Build en cours (pio run -e ${ENV})..."
pio run -e "${ENV}"
}
reset_fs() {
echo "[sim] Réinitialisation de ${SIM_FS}..."
rm -f "${SIM_FS}/etc/shadow" \
"${SIM_FS}/root/.groups" \
"${SIM_FS}/etc/sudoers" \
"${SIM_FS}/root/.fsmeta" 2>/dev/null || true
rm -rf "${SIM_FS}/tmp"/* "${SIM_FS}/home"/*/ 2>/dev/null || true
echo "[sim] Fait."
}
FORCE_BUILD=false
FORWARD_ARGS=()
for arg in "$@"; do
case "$arg" in
--help|-h) print_help ;;
--build) FORCE_BUILD=true ;;
--reset) RESET=true ;;
--ctf) ENV="native-ctf"; BINARY=".pio/build/native-ctf/program"; SIM_FS="sim_fs" ;;
*) FORWARD_ARGS+=("$arg") ;;
esac
done
${RESET:-false} && reset_fs
if [ ! -f "$BINARY" ] || [ "$FORCE_BUILD" = true ]; then
if ! command -v pio &>/dev/null; then
echo "[sim] Erreur : PlatformIO (pio) introuvable. Installe-le via :" >&2
echo " pip install platformio" >&2
exit 1
fi
rebuild
fi
if [ ! -f "$BINARY" ]; then
echo "[sim] Erreur : binaire introuvable après build." >&2
exit 1
fi
echo "[sim] Démarrage MinitelOS (${ENV})..."
exec "$BINARY" "${FORWARD_ARGS[@]+"${FORWARD_ARGS[@]}"}"