#!/usr/bin/env python3 """Recupere la liste des apps installees sur le serveur YunoHost et ajoute celles qui manquent dans src/config.json (dans "ungrouped"), sans toucher a celles deja placees dans un groupe, dans "pinned" ou deja presentes. Usage: python3 scripts/sync-apps.py [utilisateur@hote] [domaine] Toute la configuration vient de .env (SYNC_SSH_USER, SYNC_SSH_HOST, PORTAL_DOMAIN, REMOTE_USER) ; les arguments en ligne de commande, s'ils sont fournis, ont priorite sur .env. """ import json import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from yunohost_sync import CONFIG_PATH, build_app_list, fetch_remote_apps, known_urls, load_env, sync_target ENV = load_env() arg_target = sys.argv[1] if len(sys.argv) > 1 else None arg_domain = sys.argv[2] if len(sys.argv) > 2 else None SSH_TARGET, DOMAIN, SELF_APP_ID = sync_target(ENV, arg_target, arg_domain) if not SSH_TARGET or not DOMAIN: print( "Configuration manquante : renseigne SYNC_SSH_HOST (ou REMOTE_HOST) " "et PORTAL_DOMAIN dans .env (lance 'make config' si .env n'existe pas " "encore), ou passe-les en argument :\n" " python3 scripts/sync-apps.py utilisateur@hote domaine", file=sys.stderr, ) sys.exit(1) def main(): with open(CONFIG_PATH, encoding="utf-8") as f: config = json.load(f) try: remote = fetch_remote_apps(SSH_TARGET, DOMAIN) except (RuntimeError, json.JSONDecodeError) as exc: print(f"Erreur SSH: {exc}", file=sys.stderr) sys.exit(1) existing_urls = known_urls(config) to_add = build_app_list(remote, DOMAIN, SELF_APP_ID, exclude_urls=existing_urls) if not to_add: print("Rien a ajouter, config.json est deja a jour.") return config.setdefault("ungrouped", []).extend(to_add) with open(CONFIG_PATH, "w", encoding="utf-8") as f: json.dump(config, f, ensure_ascii=False, indent=2) f.write("\n") print(f"{len(to_add)} application(s) ajoutee(s) dans \"ungrouped\" :") for app in to_add: print(f" - {app['name']}") if __name__ == "__main__": main()