summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroskar <oskar@debian-git-web>2024-10-07 15:57:42 +0200
committeroskar <oskar@debian-git-web>2024-10-07 15:57:42 +0200
commitbb15ca3599a4dd0115bc184efb1d75bdcc9bdeb5 (patch)
tree40aba6a07aa7d83d40fcc9e55f548dabef4ab777
parent167c1f2600f961147cbeb6e7c4f8f00eb46f51a7 (diff)
script to create repository on my serverHEADmaster
-rwxr-xr-xrepo-create.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/repo-create.py b/repo-create.py
new file mode 100755
index 0000000..271139f
--- /dev/null
+++ b/repo-create.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python3
+import sys
+import subprocess
+
+def run_command(command):
+ try:
+ # Run the command and capture the output
+ result = subprocess.run(command, shell=True, check=True, text=True, capture_output=True)
+ # Output the command's stdout
+ print(f"Command succeeded with output:\n{result.stdout}")
+ # Optionally return the output
+ return result.stdout
+ except subprocess.CalledProcessError as e:
+ # Handle the case where the command fails
+ print(f"Command failed with return code {e.returncode}")
+ print(f"Error output: {e.stderr}")
+ return None
+
+def choice():
+ while 1:
+ user_input = input("[Y / N] ? ").strip()
+ if user_input == "\n":
+ continue
+ if user_input == "y" or user_input == "Y":
+ return 0
+ if user_input == "n" or user_input == "N":
+ return 1
+
+if len(sys.argv) < 2 or len(sys.argv) > 2:
+ print(f"{sys.argv[0]} [REPO NAME]", file=sys.stderr)
+ exit(-1);
+
+reponame = sys.argv[1];
+reponame_len = len(reponame)
+dotgitstr = ".git"
+nodotgit = True
+gitdir = "/srv/git/"
+
+if len(reponame) >= 4 and reponame[-4:] == dotgitstr:
+ nodotgit = False
+
+if nodotgit:
+ reponame += dotgitstr
+
+print(f"The final repository name will be ---> \'{reponame}\'\n Do you want to create it?")
+if choice() == 1:
+ print("Exiting...")
+
+run_command(f"cd {gitdir} && git init --bare {reponame} && chown -R git:git {reponame}")