72 lines
2.8 KiB
Python
72 lines
2.8 KiB
Python
import subprocess
|
|
import socket
|
|
|
|
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"\nStandartport {port} nutzen? (y/j/PORT-Nr) ")
|
|
if port.lower() in ["ja","j","y"] or not port.isdigit():
|
|
port= "22"
|
|
|
|
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!")
|
|
name = input("Wie ist dein Name für den Remotehost? ")
|
|
mail = input("Wie ist deine E-Mail für den Remotehost? ")
|
|
else:
|
|
exit()
|
|
|
|
|
|
# Befehle für die SSH-Verbindung
|
|
commands = [
|
|
"cd ..",
|
|
"cd ..",
|
|
"cd ..",
|
|
f"cd share/Public/git",
|
|
f"mkdir {project_name}.git",
|
|
f"mkdir {project_name}",
|
|
f"cd {project_name}.git",
|
|
"git init --bare",
|
|
"cd ../",
|
|
f"cd {project_name}",
|
|
"git init",
|
|
f'git config --global user.email "{mail}"',
|
|
f'git config --global user.name "{name}"',
|
|
"touch README.txt",
|
|
"git add .",
|
|
'git commit -am "INIT"',
|
|
f"git remote add origin ssh://{username}@{hostname}/share/Public/git/{project_name}.git"
|
|
]
|
|
|
|
# SSH-Verbindung herstellen und Befehle ausführen
|
|
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()
|
|
|
|
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}")
|