steps.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. # -*- coding: utf-8 -*-
  2. """
  3. Installations-Schritte pro Modus.
  4. Definiert gewichtete Schritte fuer den InstallRunner.
  5. """
  6. from __future__ import annotations
  7. from dataclasses import dataclass
  8. @dataclass
  9. class InstallationStep:
  10. """Ein einzelner Installationsschritt."""
  11. id: str
  12. name: str
  13. description: str
  14. weight: int
  15. command_fn: str # Name der Runner-Methode
  16. def get_steps(mode: str) -> list[InstallationStep]:
  17. """Gibt die Schrittliste fuer den jeweiligen Modus zurueck."""
  18. stop_service_step = InstallationStep(
  19. id="stop_service",
  20. name="Laufenden Service stoppen",
  21. description="Stoppt einen bestehenden trixy-Service vor dem Update",
  22. weight=2,
  23. command_fn="step_stop_service",
  24. )
  25. start_service_step = InstallationStep(
  26. id="start_service",
  27. name="Service starten",
  28. description="Startet den trixy-Service nach der Installation",
  29. weight=2,
  30. command_fn="step_start_service",
  31. )
  32. common_steps = [
  33. InstallationStep(
  34. id="extract",
  35. name="Quellcode entpacken",
  36. description="Entpacke .tar.gz nach Installationspfad",
  37. weight=10,
  38. command_fn="step_extract",
  39. ),
  40. InstallationStep(
  41. id="apt_packages",
  42. name="System-Pakete",
  43. description="Installiere benoetigte apt-Pakete",
  44. weight=25,
  45. command_fn="step_apt_packages",
  46. ),
  47. InstallationStep(
  48. id="hostname",
  49. name="Hostname setzen",
  50. description="Setze System-Hostname",
  51. weight=2,
  52. command_fn="step_hostname",
  53. ),
  54. ]
  55. wifi_step = InstallationStep(
  56. id="wifi_ap",
  57. name="WiFi-Hotspot",
  58. description="Konfiguriere hostapd, dnsmasq, dhcpcd und NAT",
  59. weight=8,
  60. command_fn="step_wifi_ap",
  61. )
  62. venv_step = InstallationStep(
  63. id="venv",
  64. name="Python venv",
  65. description="Erstelle venv und installiere Kern-Requirements",
  66. weight=15,
  67. command_fn="step_venv",
  68. )
  69. plugin_step = InstallationStep(
  70. id="plugin_deps",
  71. name="Plugin-Abhaengigkeiten",
  72. description="Installiere Requirements der ausgewaehlten Plugins",
  73. weight=20,
  74. command_fn="step_plugin_deps",
  75. )
  76. dirs_step = InstallationStep(
  77. id="directories",
  78. name="Verzeichnisse",
  79. description="Erstelle Verzeichnisse und setze Berechtigungen",
  80. weight=5,
  81. command_fn="step_directories",
  82. )
  83. systemd_step = InstallationStep(
  84. id="systemd",
  85. name="systemd-Service",
  86. description="Erstelle und aktiviere systemd-Service",
  87. weight=5,
  88. command_fn="step_systemd",
  89. )
  90. models_step = InstallationStep(
  91. id="download_models",
  92. name="Modelle herunterladen",
  93. description="Lade ML-Modelle herunter (optional)",
  94. weight=15,
  95. command_fn="step_download_models",
  96. )
  97. wifi_connect_step = InstallationStep(
  98. id="wifi_connect",
  99. name="WLAN-Verbindung",
  100. description="Konfiguriere WLAN-Verbindung (wpa_supplicant)",
  101. weight=5,
  102. command_fn="step_wifi_connect",
  103. )
  104. swap_check_step = InstallationStep(
  105. id="check_swap",
  106. name="Speicher-Check",
  107. description="Pruefe RAM+Swap und lege bei Bedarf Swap-Datei an",
  108. weight=3,
  109. command_fn="step_check_swap",
  110. )
  111. swap_cleanup_step = InstallationStep(
  112. id="cleanup_swap",
  113. name="Swap abschliessen",
  114. description="Swap-Datei permanent behalten oder entfernen",
  115. weight=2,
  116. command_fn="step_cleanup_swap",
  117. )
  118. verify_step = InstallationStep(
  119. id="verify",
  120. name="Verifizierung",
  121. description="Pruefe installierte Abhaengigkeiten",
  122. weight=10,
  123. command_fn="step_verify",
  124. )
  125. if mode == "server":
  126. return [
  127. stop_service_step,
  128. swap_check_step,
  129. *common_steps,
  130. wifi_step,
  131. venv_step,
  132. plugin_step,
  133. dirs_step,
  134. models_step,
  135. systemd_step,
  136. start_service_step,
  137. verify_step,
  138. swap_cleanup_step,
  139. ]
  140. if mode == "client":
  141. return [
  142. stop_service_step,
  143. swap_check_step,
  144. common_steps[0], # extract
  145. common_steps[1], # apt
  146. common_steps[2], # hostname
  147. wifi_connect_step,
  148. venv_step,
  149. dirs_step,
  150. systemd_step,
  151. start_service_step,
  152. verify_step,
  153. swap_cleanup_step,
  154. ]
  155. if mode == "standalone":
  156. return [
  157. stop_service_step,
  158. swap_check_step,
  159. *common_steps,
  160. wifi_connect_step,
  161. venv_step,
  162. plugin_step,
  163. dirs_step,
  164. models_step,
  165. systemd_step,
  166. start_service_step,
  167. verify_step,
  168. swap_cleanup_step,
  169. ]
  170. if mode == "config":
  171. return [
  172. common_steps[0], # extract
  173. venv_step,
  174. verify_step,
  175. ]
  176. return common_steps