summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejavu Moe <[email protected]>2023-05-11 23:17:59 +0800
committerDejavu Moe <[email protected]>2023-05-11 23:17:59 +0800
commit91a876ff74fc5c8ae649be424362dd5705311fd3 (patch)
tree0313efc1c0982bbd9fa7b507f547a0ea7958debe
parentf7b2a86c56dcedb023be09fea960077a6a62b8d9 (diff)
downloadself-hosted-91a876ff74fc5c8ae649be424362dd5705311fd3.tar.gz
self-hosted-91a876ff74fc5c8ae649be424362dd5705311fd3.zip
add cgit/git-bare
-rw-r--r--cgit/git-bare42
1 files changed, 42 insertions, 0 deletions
diff --git a/cgit/git-bare b/cgit/git-bare
new file mode 100644
index 0000000..a4f757a
--- /dev/null
+++ b/cgit/git-bare
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+set -eu
+
+# /usr/local/bin/git-bare
+
+# Check if the running user is root or sudo user
+if [ "$(id -u)" -ne 0 ]; then
+ if ! sudo -v &> /dev/null; then
+ echo "Please run the script as root or with sudo user"
+ exit 1
+ fi
+fi
+
+# Check if git is installed
+if ! command -v git &> /dev/null; then
+ echo "Git is not installed, please install Git first."
+ exit 1
+fi
+
+read -p "Please enter the repository name (without .git)." reponame
+
+if [ -d "/home/git/${reponame}.git" ]; then
+ echo "Repository ${reponame} already exists"
+ exit 1
+else
+ git init --bare "/home/git/${reponame}.git"
+ cd "/home/git/${reponame}.git"
+
+ read -p "Please enter the repository description:" description
+ echo "${description}." | sudo tee "description" > /dev/null
+
+ # Update the Git repository info
+ if ! git update-server-info &> /dev/null; then
+ echo "Failed to update Git repository information, exiting..."
+ exit 1
+ fi
+
+ chown -R git:www-data "/home/git/${reponame}.git"
+ chmod -R ug+rwx,o-rwx "/home/git/${reponame}.git"
+ echo "The repository was created successfully."
+fi \ No newline at end of file