aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rwxr-xr-xadd_git_key5
-rwxr-xr-xdel_repo9
-rwxr-xr-xgitscripts.conf.example9
-rwxr-xr-xmake_repo.py125
-rwxr-xr-xrequirements.txt2
l---------rm_repo1
-rwxr-xr-xshow_gitkey.py8
8 files changed, 161 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index b6e4761..b94508d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+gitscripts.conf
+
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
diff --git a/add_git_key b/add_git_key
new file mode 100755
index 0000000..6c2f3c4
--- /dev/null
+++ b/add_git_key
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+gh ssh-key add $1 --title $2
+
+rm $1
diff --git a/del_repo b/del_repo
new file mode 100755
index 0000000..4bf9cca
--- /dev/null
+++ b/del_repo
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+echo -n "Input repo name to delete: "
+read repo
+
+rm -fvr /srv/git/$repo
+rm -fvr ~/$repo
+rm -fvr ~/$repo.git
+
diff --git a/gitscripts.conf.example b/gitscripts.conf.example
new file mode 100755
index 0000000..a2596a4
--- /dev/null
+++ b/gitscripts.conf.example
@@ -0,0 +1,9 @@
+[git]
+repo_path = /srv/git
+domain = git.eda.gay
+gitignore_templates = /srv/www/gitignore
+license_templates = /srv/www/license-templates/templates
+
+[github]
+user = jwansek
+key = ****************************** \ No newline at end of file
diff --git a/make_repo.py b/make_repo.py
new file mode 100755
index 0000000..4ba01d0
--- /dev/null
+++ b/make_repo.py
@@ -0,0 +1,125 @@
+#!/usr/bin/env python3
+
+import subprocess
+import configparser
+import datetime
+import tempfile
+import urllib
+import shutil
+import jinja2
+import os
+
+class ChangeCWD:
+ def __init__(self, new_cwd):
+ self.new_cwd = new_cwd
+ self.old_cwd = os.getcwd()
+
+ def __enter__(self):
+ os.chdir(self.new_cwd)
+
+ def __exit__(self, type, value, traceback):
+ os.chdir(self.old_cwd)
+
+conf_path = os.path.join(os.path.dirname(__file__), "gitscripts.conf")
+if not os.path.exists(conf_path):
+ conf_path = os.path.join(os.path.dirname(os.readlink(__file__)), "gitscripts.conf")
+
+CONFIG = configparser.ConfigParser()
+CONFIG.read(conf_path)
+
+repo_name = urllib.parse.quote_plus(input("Input repository name: "))
+if not repo_name.endswith(".git"):
+ repo_name += ".git"
+repo_dir = os.path.join(CONFIG.get("git", "repo_path"), repo_name)
+repo_url = "git@%s:%s" % (CONFIG.get("git", "domain"), repo_name)
+
+if os.path.exists(repo_dir):
+ print("ERROR: A repository with that name already exists. Please try another")
+ exit()
+os.mkdir(repo_dir)
+
+subprocess.run(["ln", "-s", repo_dir, repo_name[:-4]])
+subprocess.run(["ln", "-s", repo_dir, repo_name])
+
+private = input("Would you like the repository to appear on the web version %s? <y/n>: " % CONFIG.get("git", "domain")).lower() == "n"
+
+with ChangeCWD(repo_dir):
+ subprocess.run(["git", "init", "--bare"])
+
+ description = input("Input repository description: ")
+ author = input("Input repository author: ")
+ author_email = input("Input author email: ")
+
+ with open(os.path.join(repo_dir, "description"), "w") as f:
+ f.write(description)
+
+ with open(os.path.join(repo_dir, "author"), "w") as f:
+ f.write(author)
+
+ with open(os.path.join(repo_dir, "url"), "w") as f:
+ f.write(repo_url)
+
+ with open(os.path.join(repo_dir, "config"), "a") as f:
+ f.write("[gitweb]\n\towner = %s <%s>" % (author, author_email))
+
+if input("Would you like the repository to remain bare? Useful for making mirrors of Github repos. <y/n>: ").lower() != "y":
+ with tempfile.TemporaryDirectory() as tempdir:
+ subprocess.run(["git", "clone", repo_url, tempdir])
+ with ChangeCWD(tempdir):
+
+ with open("README.md", "w") as f:
+ f.write("# %s\n\n%s\n" % (repo_name, description))
+
+ gitignore_templates_dir = CONFIG.get("git", "gitignore_templates")
+ templates = sorted([f[:-10] for f in os.listdir(gitignore_templates_dir) if f.endswith(".gitignore")])
+ templates.insert(0, "[None]")
+ for i, template in enumerate(templates, 1):
+ print("%3d: %-23s" % (i, template), end = "")
+ if i % 3 == 0:
+ print("")
+
+ selected_index = int(input("\nSelect .gitignore template: "))
+ if selected_index != 0:
+ shutil.copy(os.path.join(gitignore_templates_dir, templates[selected_index - 1]) + ".gitignore", ".gitignore", follow_symlinks = True)
+
+ licenses_templates_dir = CONFIG.get("git", "license_templates")
+ templates = sorted([f[:-4] for f in os.listdir(licenses_templates_dir) if not f.endswith("-header.txt")])
+ templates.insert(0, "[None]")
+ for i, template in enumerate(templates, 1):
+ print("%2d: %-22s" % (i, template), end = "")
+ if i % 4 == 0:
+ print("")
+
+ selected_index = int(input("\nSelect license template: "))
+ if selected_index != 0:
+ with open(os.path.join(licenses_templates_dir, templates[selected_index - 1]) + ".txt", "r") as f:
+ jinja_template = jinja2.Template(f.read())
+
+ with open("LICENSE", "w") as f:
+ f.write(jinja_template.render(**{
+ "year": str(datetime.datetime.today().year),
+ "organization": author,
+ "project": repo_name
+ }))
+
+ subprocess.run(["git", "add", "-A"])
+ subprocess.run(["git", "commit", "-m", "Initialized repository"])
+ subprocess.run(["git", "push", "origin", "master"])
+
+print("""
+Repository created. You can now clone or add remote:
+ git remote add other %s
+ git clone %s
+And add github mirror (insecure method, keys are stored locally):
+ git remote add github https://%s:%s@github.com/%s/%s
+Add a github mirror (secure method using SSH):
+ git remote add github git@github.com:%s/%s
+ """ % (
+ repo_url, repo_url, CONFIG.get("github", "user"), CONFIG.get("github", "key"),
+ CONFIG.get("github", "user"), repo_name, CONFIG.get("github", "user"), repo_name
+ ))
+
+
+
+
+
diff --git a/requirements.txt b/requirements.txt
new file mode 100755
index 0000000..8422bcb
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+jinja2
+
diff --git a/rm_repo b/rm_repo
new file mode 120000
index 0000000..872ba03
--- /dev/null
+++ b/rm_repo
@@ -0,0 +1 @@
+del_repo \ No newline at end of file
diff --git a/show_gitkey.py b/show_gitkey.py
new file mode 100755
index 0000000..0ba9e25
--- /dev/null
+++ b/show_gitkey.py
@@ -0,0 +1,8 @@
+#!/usr/bin/env python3
+
+import configparser
+
+gitconf = configparser.ConfigParser()
+gitconf.read("/srv/www/docker-cgit/gitscripts.conf")
+
+print("git remote add github https://%s:%s@github.com/%s/" % (gitconf.get("github", "user"), gitconf.get("github", "key"), gitconf.get("github", "user")))