Add: Start govel build packages
This commit is contained in:
parent
865ec5def5
commit
c26fcdc1db
18 changed files with 37 additions and 26 deletions
0
erminig/core/__init__.py
Normal file
0
erminig/core/__init__.py
Normal file
28
erminig/core/config.py
Normal file
28
erminig/core/config.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#
|
||||
# Erminig - Configuration de l'application
|
||||
# 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.
|
||||
#
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class Config:
|
||||
LIB_DIR = Path("/var/lib/erminig")
|
||||
CACHE_DIR = Path("/var/cache/erminig")
|
||||
BASE_DIR = Path("/opt/erminig")
|
||||
DB_PATH = LIB_DIR / "erminig.db"
|
||||
PAKVA_DIR = LIB_DIR / "pakva"
|
||||
GOVEL_DIR = LIB_DIR / "govel"
|
||||
REPO_DIR = LIB_DIR / "keo"
|
||||
BUILD_DIR = Path("/tmp/erminig/build")
|
||||
PAK_USER = "pak"
|
||||
|
||||
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
|
||||
|
||||
RETRY_MAX_ATTEMPTS = 2 # Pour toutes les opérations réseau
|
||||
RETRY_DELAY_SECONDS = 2
|
||||
0
erminig/core/package.py
Normal file
0
erminig/core/package.py
Normal file
44
erminig/core/retry.py
Normal file
44
erminig/core/retry.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# Erminig - Décorateur pour relancer un téléchargement
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
import time
|
||||
import requests
|
||||
from erminig.core.config import Config
|
||||
|
||||
|
||||
def retry_on_failure():
|
||||
def decorator(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
attempt = 1
|
||||
while attempt <= Config.RETRY_MAX_ATTEMPTS + 1:
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except requests.exceptions.RequestException as e:
|
||||
name = getattr(args[0], "name", "Unknown")
|
||||
print(
|
||||
f"[{name}] Erreur réseau tentative {attempt}: {e.__class__.__name__}"
|
||||
)
|
||||
if attempt <= Config.RETRY_MAX_ATTEMPTS:
|
||||
print(
|
||||
f"[{name}] Nouvelle tentative dans {Config.RETRY_DELAY_SECONDS}s..."
|
||||
)
|
||||
time.sleep(Config.RETRY_DELAY_SECONDS)
|
||||
attempt += 1
|
||||
else:
|
||||
print(f"[{name}] Abandon après {attempt} tentatives.")
|
||||
return None
|
||||
except Exception as e:
|
||||
name = getattr(args[0], "name", "Unknown")
|
||||
print(f"[{name}] Erreur inconnue dans {func.__name__}: {e}")
|
||||
return None
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
65
erminig/core/security.py
Normal file
65
erminig/core/security.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#
|
||||
# Erminig - Fonctions pour gérer les utilisateurs système.
|
||||
# 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.
|
||||
#
|
||||
|
||||
import os
|
||||
import pwd
|
||||
import sys
|
||||
import functools
|
||||
|
||||
|
||||
def check_root():
|
||||
"""Vérifie si on est root, sinon quitte."""
|
||||
if os.geteuid() != 0:
|
||||
print("[SECURITY] Ce programme doit être exécuté en tant que root.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_user_exists(username):
|
||||
"""Vérifie si l'utilisateur spécifié existe."""
|
||||
try:
|
||||
pwd.getpwnam(username)
|
||||
return True
|
||||
except KeyError:
|
||||
print(f"[SECURITY] Utilisateur '{username}' introuvable.")
|
||||
return False
|
||||
|
||||
|
||||
def run_as_user(username):
|
||||
"""Décorateur : Fork et drop privileges pour exécuter une fonction sous un autre utilisateur."""
|
||||
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
# Parent : attendre le child, ne pas exit, juste return proprement
|
||||
_, status = os.waitpid(pid, 0)
|
||||
return (
|
||||
status >> 8
|
||||
) # récupère le code retour du fils (comme exit code)
|
||||
|
||||
# Child
|
||||
pw_record = pwd.getpwnam(username)
|
||||
user_uid = pw_record.pw_uid
|
||||
user_gid = pw_record.pw_gid
|
||||
|
||||
os.setgid(user_gid)
|
||||
os.setuid(user_uid)
|
||||
|
||||
result = func(*args, **kwargs)
|
||||
os._exit(0 if result is None else int(bool(result)))
|
||||
|
||||
except OSError as e:
|
||||
print(f"[SECURITY] Fork échoué : {e}")
|
||||
os._exit(1)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
Loading…
Add table
Add a link
Reference in a new issue