🐛 MakeMKV: le parametre lu est app_Key (pas app_MakeMKV_key) + variable MAKEMKV_KEY ecrite par l'entrypoint
This commit is contained in:
1 parent
87fd6b39fd
commit
10830f3562
5 files changed
+80
-38
No files matched your search
+50
-22
@@ -15,32 +15,60 @@ puisse créer, supprimer et lier des fichiers dedans, sans que le bit
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
puid = int(os.environ.get("PUID", "0") or "0")
|
||||
pgid = int(os.environ.get("PGID", "0") or "0")
|
||||
config_dir = os.environ.get("MKVTOOL_CONFIG_DIR", "/config")
|
||||
|
||||
if os.geteuid() == 0 and puid:
|
||||
if os.path.isdir(config_dir):
|
||||
subprocess.run(
|
||||
["chown", "-R", f"{puid}:{pgid or puid}", config_dir], check=False
|
||||
)
|
||||
# Entree passwd pour PUID: certains binaires (MakeMKV) resolvent le
|
||||
# repertoire utilisateur via getpwuid et non via $HOME. Sans entree,
|
||||
# makemkvcon ne trouve pas sa configuration (/config/.MakeMKV).
|
||||
try:
|
||||
with open("/etc/passwd", encoding="utf-8") as handle:
|
||||
known_uids = {line.split(":")[2] for line in handle if ":" in line}
|
||||
if str(puid) not in known_uids:
|
||||
with open("/etc/passwd", "a", encoding="utf-8") as handle:
|
||||
handle.write(
|
||||
f"mkvtool:x:{puid}:{pgid or puid}::{config_dir}:/usr/sbin/nologin\n"
|
||||
)
|
||||
except OSError:
|
||||
pass
|
||||
os.setgroups([pgid] if pgid else [])
|
||||
if pgid:
|
||||
os.setgid(pgid)
|
||||
os.setuid(puid)
|
||||
|
||||
def write_makemkv_key() -> None:
|
||||
"""Ecrit la cle MakeMKV (env MAKEMKV_KEY) dans settings.conf.
|
||||
|
||||
MakeMKV lit ``app_Key`` dans ``/config/.MakeMKV/settings.conf``
|
||||
(la commande ``makemkvcon reg <cle>`` est peu fiable sur Linux).
|
||||
La cle bêta courante: forum officiel MakeMKV, fil « MakeMKV is free
|
||||
while in beta » (rotation tous les un a deux mois).
|
||||
"""
|
||||
key = os.environ.get("MAKEMKV_KEY", "").strip()
|
||||
if not key:
|
||||
return
|
||||
settings_path = Path(config_dir) / ".MakeMKV" / "settings.conf"
|
||||
settings_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
lines = []
|
||||
if settings_path.exists():
|
||||
lines = [
|
||||
line
|
||||
for line in settings_path.read_text(encoding="utf-8").splitlines()
|
||||
if not line.strip().startswith("app_Key")
|
||||
]
|
||||
lines.append(f'app_Key = "{key}"')
|
||||
settings_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
if os.geteuid() == 0:
|
||||
write_makemkv_key()
|
||||
if puid:
|
||||
if os.path.isdir(config_dir):
|
||||
subprocess.run(
|
||||
["chown", "-R", f"{puid}:{pgid or puid}", config_dir], check=False
|
||||
)
|
||||
# Entree passwd pour PUID: certains binaires (MakeMKV) resolvent le
|
||||
# repertoire utilisateur via getpwuid et non via $HOME. Sans entree,
|
||||
# makemkvcon ne trouve pas sa configuration (/config/.MakeMKV).
|
||||
try:
|
||||
with open("/etc/passwd", encoding="utf-8") as handle:
|
||||
known_uids = {line.split(":")[2] for line in handle if ":" in line}
|
||||
if str(puid) not in known_uids:
|
||||
with open("/etc/passwd", "a", encoding="utf-8") as handle:
|
||||
handle.write(
|
||||
f"mkvtool:x:{puid}:{pgid or puid}::{config_dir}:/usr/sbin/nologin\n"
|
||||
)
|
||||
except OSError:
|
||||
pass
|
||||
os.setgroups([pgid] if pgid else [])
|
||||
if pgid:
|
||||
os.setgid(pgid)
|
||||
os.setuid(puid)
|
||||
|
||||
os.execvp(sys.argv[1], sys.argv[1:])
|
||||
Reference in new issue
Block a user