summaryrefslogtreecommitdiff
path: root/repo-create.py
blob: 271139f468c0b42333f3039f3bc9237f938df1aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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}")