2025-04-29 17:35:21 +02:00
|
|
|
|
#
|
|
|
|
|
|
# Erminig - Initialisation des utilisateurs et répertoires
|
|
|
|
|
|
# Copyright (C) 2025 L0m1g
|
|
|
|
|
|
# Sous licence DOUARN - Voir le fichier LICENCE pour les détails
|
|
|
|
|
|
#
|
|
|
|
|
|
# Ce fichier fait partie du projet Erminig.
|
|
|
|
|
|
# Libre comme l’air, stable comme un menhir, et salé comme le beurre.
|
|
|
|
|
|
#
|
|
|
|
|
|
|
2025-04-29 17:15:19 +02:00
|
|
|
|
import os
|
|
|
|
|
|
import subprocess
|
|
|
|
|
|
import sys
|
|
|
|
|
|
from pathlib import Path
|
2025-05-03 18:33:53 +02:00
|
|
|
|
from erminig.core.security import check_root, check_user_exists
|
|
|
|
|
|
from erminig.core.config import Config
|
2025-04-29 17:15:19 +02:00
|
|
|
|
|
|
|
|
|
|
PAK_USER = Config.PAK_USER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_user_pak():
|
|
|
|
|
|
"""Crée l'utilisateur pak si nécessaire."""
|
|
|
|
|
|
if check_user_exists(PAK_USER):
|
|
|
|
|
|
print(f"[INIT] Utilisateur '{PAK_USER}' existe déjà.")
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
print(f"[INIT] Création de l'utilisateur '{PAK_USER}'...")
|
|
|
|
|
|
subprocess.run(
|
|
|
|
|
|
[
|
|
|
|
|
|
"useradd",
|
|
|
|
|
|
"-r",
|
|
|
|
|
|
"-d",
|
|
|
|
|
|
str(Config.LIB_DIR),
|
|
|
|
|
|
"-s",
|
|
|
|
|
|
"/usr/sbin/nologin",
|
|
|
|
|
|
PAK_USER,
|
|
|
|
|
|
],
|
|
|
|
|
|
check=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
print(f"[INIT] Utilisateur '{PAK_USER}' créé.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup_directories():
|
|
|
|
|
|
"""Crée les dossiers nécessaires et assigne les permissions."""
|
|
|
|
|
|
for directory in [Config.LIB_DIR, Config.CACHE_DIR]:
|
|
|
|
|
|
if not directory.exists():
|
|
|
|
|
|
print(f"[INIT] Création du dossier {directory}...")
|
|
|
|
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
print(f"[INIT] Attribution de {directory} à '{PAK_USER}'...")
|
|
|
|
|
|
subprocess.run(
|
|
|
|
|
|
["chown", "-R", f"{PAK_USER}:{PAK_USER}", str(directory)], check=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
check_root()
|
|
|
|
|
|
|
|
|
|
|
|
create_user_pak()
|
|
|
|
|
|
setup_directories()
|
|
|
|
|
|
|
|
|
|
|
|
print("[INIT] Environnement Erminig initialisé avec succès.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
main()
|