summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2022-02-12 16:39:01 +0100
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2022-02-12 16:39:01 +0100
commit7d2476df8391ca8044b5ceec6dc990ac1e33f846 (patch)
tree9a3ce045a42ffb7094c75727863db26782d981de
parent6078ff6553e06e6d6f407f46067364c9bae0aafc (diff)
feat: add stagit-new-repo
-rwxr-xr-xbin/stagit-new-repo35
1 files changed, 35 insertions, 0 deletions
diff --git a/bin/stagit-new-repo b/bin/stagit-new-repo
new file mode 100755
index 0000000..fe5e7ab
--- /dev/null
+++ b/bin/stagit-new-repo
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+# This script creates a new repository and index it with stagit.
+
+while getopts ":r:d:o:u:h" o; do case "${o}" in
+ h) printf "Arguement for creating a new git repository:\\n -r: Repository name\\n -d: Short description of the project\\n -o: Name of the owner\\n -u: URI for cloning\\n -h: Show this message\\n" && exit 1 ;;
+ r) repo=${OPTARG} || exit 1 ;;
+ d) desc=${OPTARG} || exit 1 ;;
+ o) owner=${OPTARG} || exit 1 ;;
+ u) uri=${OPTARG} || exit 1 ;;
+ *) printf "Invalid option: -%s\\n" "$OPTARG" && exit 1 ;;
+esac done
+
+home="/home/git/"
+srv="/srv/git"
+www="/var/www/git"
+
+[ -d "$srv/$repo" ] && echo "$repo already exists!" && exit 1
+
+echo "Initializing git repository..."
+git init --bare "$srv/$repo.git"
+cp "$home/hooks/post-receive" "$srv/$repo.git/hooks/post-receive"
+chmod u+x "$srv/$repo.git/hooks/post-receive"
+echo "$uri:$repo.git" > "$srv/$repo.git/url"
+echo "$owner" > "$srv/$repo.git/owner"
+echo "$desc" > "$srv/$repo.git/description"
+chown -R git:git "$srv/$repo.git"
+ln -svf "$srv/$repo.git" "$home"
+
+echo "Creating a static page directory..."
+[ ! -d "$www/$repo" ] && echo "$repo already exists!" && exit 1
+mkdir "$www/$repo"
+chown -R git:git "$www/$repo"
+
+/usr/local/bin/stagit-gen-index