diff --git a/run_deploy.py b/run_deploy.py index 178ddcd..98ccf01 100644 --- a/run_deploy.py +++ b/run_deploy.py @@ -9,35 +9,53 @@ load_dotenv() HOST = os.getenv("SSH_HOST") USER = os.getenv("SSH_USER") KEY = os.getenv("SSH_KEY") +PASSPHRASE = os.getenv("SSH_KEY_PASSPHRASE") +root = tk.Tk() +root.withdraw() + +# 🛡 VĂ©rifie que le fichier existe +if not os.path.exists(KEY): + messagebox.showerror("❌ Erreur", f"ClĂ© SSH introuvable :\n{KEY}") + exit(1) + +# 🛡 VĂ©rifie que la clĂ© est lisible par paramiko +try: + paramiko.RSAKey.from_private_key_file(KEY, password=PASSPHRASE) +except paramiko.PasswordRequiredException: + messagebox.showerror("❌ ClĂ© protĂ©gĂ©e", "La clĂ© est protĂ©gĂ©e par une passphrase, mais aucune n'a Ă©tĂ© fournie.") + exit(1) +except paramiko.SSHException: + messagebox.showerror("❌ Erreur de format", "Le fichier de clĂ© n’est pas au format OpenSSH.\n\nSolution : Exporter depuis PuTTYgen → Conversions > Export OpenSSH key") + exit(1) +except Exception as e: + messagebox.showerror("❌ Autre erreur", f"{e}") + exit(1) + +# ✅ Si la clĂ© est valide, on continue client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: - client.connect(hostname=HOST, username=USER, key_filename=KEY) + client.connect( + hostname=HOST, + username=USER, + key_filename=KEY, + passphrase=PASSPHRASE + ) + stdin, stdout, stderr = client.exec_command("bash ~/travail/Gestion_sondes/scripts/deploy_all.sh") output = stdout.read().decode() errors = stderr.read().decode() if "DĂ©ploiement complet terminĂ© avec succĂšs" in output: - success = True + messagebox.showinfo("✅ DĂ©ploiement rĂ©ussi", "Le dĂ©ploiement s'est bien dĂ©roulĂ©.") else: - success = False - - # Affichage de la notification visuelle - root = tk.Tk() - root.withdraw() # cache la fenĂȘtre principale - - if success: - messagebox.showinfo("DĂ©ploiement terminĂ©", "✅ Le dĂ©ploiement s'est bien dĂ©roulĂ© !") - else: - messagebox.showwarning("DĂ©ploiement partiel", f"⚠ DĂ©ploiement incomplet. VĂ©rifiez les logs.\n\n{errors}") + messagebox.showwarning("⚠ DĂ©ploiement incomplet", f"VĂ©rifie les logs :\n\n{errors}") except Exception as e: - root = tk.Tk() - root.withdraw() - messagebox.showerror("Erreur SSH", f"❌ Erreur : {e}") + messagebox.showerror("❌ Erreur SSH", f"{e}") finally: client.close()