From 67a832062c233c6bbb6979080c17815146cf5ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannick=20E=C3=9Fer?= Date: Mon, 12 Jun 2023 08:37:45 +0200 Subject: [PATCH 1/3] added support for Remoteadress, multiuser and other port selection --- README.md | 8 +++++++- main.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f18ca8f..4616e0a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Dies erzeugt ein neues GIT Repository auf ein Asustor NAS (Only GIT installed). ## Version - V 1.1 + V 1.2 ## Installation @@ -12,6 +12,12 @@ Dies erzeugt ein neues GIT Repository auf ein Asustor NAS (Only GIT installed). ## Changelog +### V 1.1 **(WIP)** +- `main.py` + - Added Remote Adresse zu ändern (Local & Public) + - Added Multiuser + - Added Port ändern + ### V 1.1 - `README.md` erstellt - `main.py` -> Tippfehler korrigiert diff --git a/main.py b/main.py index 7b840dc..6088692 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,13 @@ import subprocess -project_name = input("Geben Sie den Projektnamen ein: ") -hostname = "192.168.2.106" -username = "yannick" -port = "22" # Anpassen, falls ein anderer Port verwendet wird +username = input("Hallo, wie lautet ihr anmelde Namen? (achte auf Groß und Kleinschrift): ") +hostname = input(f"Super, {username}. Jetzt bräuchte ich noch die Remote-adresse: ") +port= "22" +port = input(f"Standartport {port} nutzen? (y/j/PORT-Nr) ") +if port.lower() in ["ja","j","y"]: + port= "22" + +project_name = input("Perfekt, gibt mir bitte noch den Projektnamen: ") # Befehle für die SSH-Verbindung commands = [ From 9ee348848c0923710a06bb101fc77ae81c158cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannick=20E=C3=9Fer?= Date: Mon, 12 Jun 2023 10:40:48 +0200 Subject: [PATCH 2/3] V1.2.1 -error tracking and intercept illegal chars --- README.md | 12 ++++++++++-- main.py | 53 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4616e0a..bdb0b6c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Dies erzeugt ein neues GIT Repository auf ein Asustor NAS (Only GIT installed). ## Version - V 1.2 + V 1.2.1 ## Installation @@ -12,7 +12,15 @@ Dies erzeugt ein neues GIT Repository auf ein Asustor NAS (Only GIT installed). ## Changelog -### V 1.1 **(WIP)** +### V 1.2.1 **(WIP)** +- `main.py` + - Added " " zu "_" und Illigale Zeichen abfangen + - Ackknowlege vom User bekommen + - Added Try-Except block um SSH Ausführung + - **TODO:** User abfangen wenn Remote nicht erkennt. + - **TODO:** History einbauen + +### V 1.2 **(WIP)** - `main.py` - Added Remote Adresse zu ändern (Local & Public) - Added Multiuser diff --git a/main.py b/main.py index 6088692..86016c3 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,25 @@ import subprocess +import socket -username = input("Hallo, wie lautet ihr anmelde Namen? (achte auf Groß und Kleinschrift): ") -hostname = input(f"Super, {username}. Jetzt bräuchte ich noch die Remote-adresse: ") +username = input("Hallo, wie lautet ihr Username? (Achte bitte auf Groß und Kleinschrift): ") +hostname = input(f"\nSuper, {username}. Jetzt bräuchte ich noch die Remote-adresse: ") port= "22" -port = input(f"Standartport {port} nutzen? (y/j/PORT-Nr) ") -if port.lower() in ["ja","j","y"]: +port = input(f"\nStandartport {port} nutzen? (y/j/PORT-Nr) ") +if port.lower() in ["ja","j","y"] or not port.isdigit(): port= "22" -project_name = input("Perfekt, gibt mir bitte noch den Projektnamen: ") +iligal_signs = "/\\\"[]{}%&§=<>|" +ili_signs_tab = str.maketrans(iligal_signs,"-" * len(iligal_signs)) +project_name = input("\nPerfekt, gibt mir bitte noch den Projektnamen (Leerzeichen werden automatisch zu _ ersetzt): ") +project_name= project_name.replace(" ","_") +project_name= project_name.translate(ili_signs_tab) + +ack = input(f"\nOkay > {username} <, bitte prüfe ob der Name so richtig ist: > {project_name} <\nfür den Host > {hostname} < auf dem Port > {port} < (y/n)? ") +if ack.lower() == "y" or ack.lower() == "j": + print("\nSuper, ich lege los!") +else: + exit() + # Befehle für die SSH-Verbindung commands = [ @@ -31,12 +43,27 @@ commands = [ ] # SSH-Verbindung herstellen und Befehle ausführen -command_string = " && ".join(commands) -subprocess.run(["ssh", "-p", port, f"{username}@{hostname}", command_string]) -print("Bitte gehe selber per ssh auf das nas um ein >git push origin master< zu machen um das vollständig ab zu schließen") -print(f"cd share/Public/git/{project_name}") -print("git push origin master") -print(f'git clone "ssh://yannick@192.168.2.106/share/Public/git/{project_name}.git"') +try: + socket.gethostbyname(hostname) +except socket.gaierror as e: + print(f"Fehler beim Auflösen des Hostnames: {e}") +else: + try: + # TODO User abfangen wenn nicht existent + # command = f"ssh -p {port} {username}@{hostname} echo" + # completed_process = subprocess.run(command,shell=True,capture_output=True) + # if completed_process.returncode == 0: + # pass + # else: + # print(f"Der Benutzer {username} exsistiert nicht auf dem Server: {hostname}") + # exit() -# Temporäre Datei entfernen (nicht erforderlich, da direkt übergeben) -# subprocess.run(["del", "commands.sh"], shell=True) + command_string = " && ".join(commands) + subprocess.run(["ssh", "-p", port, f"{username}@{hostname}", command_string]) + print("Bitte gehe nun selber via ssh, etc. zum Git Repos, um ein >git push origin master< zu machen um das vollständig ab zu schließen") + print("Hier sind Hilfreiche Befehle:") + print(f"\ncd share/Public/git/{project_name}") + print("\ngit push origin master") + print(f'\ngit clone "ssh://yannick@192.168.2.106/share/Public/git/{project_name}.git"') + except subprocess.CalledProcessError as e: + print(f"Leider ist da was Fehlgeschlagen: {e}") From bed43b33dda02bee3ec24355d1448fe0b355f723 Mon Sep 17 00:00:00 2001 From: Yannick Date: Mon, 12 Jun 2023 21:38:25 +0200 Subject: [PATCH 3/3] V1.2.2 Added username and mail support --- README.md | 11 ++++++++++- main.py | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bdb0b6c..bdbd874 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,11 @@ Dies erzeugt ein neues GIT Repository auf ein Asustor NAS (Only GIT installed). ## Version - V 1.2.1 + V 1.2.2 + +## TODO +- **TODO:** User abfangen wenn Remote nicht erkennt. +- **TODO:** History einbauen ## Installation @@ -12,6 +16,11 @@ Dies erzeugt ein neues GIT Repository auf ein Asustor NAS (Only GIT installed). ## Changelog +### V 1.2.2 **(WIP)** +- `main.py` + - Added username and mail support + + ### V 1.2.1 **(WIP)** - `main.py` - Added " " zu "_" und Illigale Zeichen abfangen diff --git a/main.py b/main.py index 86016c3..49e2b61 100644 --- a/main.py +++ b/main.py @@ -17,6 +17,8 @@ project_name= project_name.translate(ili_signs_tab) ack = input(f"\nOkay > {username} <, bitte prüfe ob der Name so richtig ist: > {project_name} <\nfür den Host > {hostname} < auf dem Port > {port} < (y/n)? ") if ack.lower() == "y" or ack.lower() == "j": print("\nSuper, ich lege los!") + name = input("Wie ist dein Name für den Remotehost? ") + mail = input("Wie ist deine E-Mail für den Remotehost? ") else: exit() @@ -34,8 +36,8 @@ commands = [ "cd ../", f"cd {project_name}", "git init", - 'git config --global user.email "y-esser@t-online.de"', - 'git config --global user.name "Yannick"', + f'git config --global user.email "{mail}"', + f'git config --global user.name "{name}"', "touch README.txt", "git add .", 'git commit -am "INIT"',