aboutsummaryrefslogtreecommitdiffstats
path: root/roles/jails/22_forge/files/git-shell-commands/new
diff options
context:
space:
mode:
Diffstat (limited to 'roles/jails/22_forge/files/git-shell-commands/new')
-rw-r--r--roles/jails/22_forge/files/git-shell-commands/new41
1 files changed, 32 insertions, 9 deletions
diff --git a/roles/jails/22_forge/files/git-shell-commands/new b/roles/jails/22_forge/files/git-shell-commands/new
index b8f73a5..331d546 100644
--- a/roles/jails/22_forge/files/git-shell-commands/new
+++ b/roles/jails/22_forge/files/git-shell-commands/new
@@ -1,17 +1,40 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: new [REPO_NAME]"
- echo "Tip: prefix with '.' to make private (e.g. new .dotfiles)"
+ echo "Tip: prefix with '.' to make private (e.g. new .myrepo)"
exit 1
fi
-if [ -d "$1.git" ]; then
- echo "Repository $1 already exists"
+
+REPO="$1"
+REPO_PATH="$HOME/$REPO.git"
+GROUP="r_$(echo "$REPO" | sed 's/^\.//' | sha1 -q | cut -c1-14)"
+
+if [ -d "$REPO_PATH" ]; then
+ echo "Repository $REPO already exists"
exit 1
fi
-git init --bare "$1.git"
-echo "$1" > "$1.git/description"
-echo "Created repository $1"
-echo "Clone: git@forge.jan.systems:$1.git"
-if [ "${1#.}" = "$1" ]; then
- echo "Web: https://forge.jan.systems/$1.git"
+
+# Create repo group
+pw groupadd "$GROUP" 2>/dev/null || true
+pw groupmod "$GROUP" -m "$USER" 2>/dev/null || true
+
+# Init bare repo
+git init --bare "$REPO_PATH"
+echo "$REPO" > "$REPO_PATH/description"
+
+# Set ownership and permissions
+chown -R "$USER:$GROUP" "$REPO_PATH"
+
+# Public: rwxr-x--- (group can read, others nothing)
+# Private (dot-prefix): rwx------ (only owner)
+if [ "${REPO#.}" = "$REPO" ]; then
+ chmod -R 2755 "$REPO_PATH"
+else
+ chmod -R 2700 "$REPO_PATH"
+fi
+
+echo "Created repository $REPO"
+echo "Clone: $USER@forge.jan.systems:$REPO.git"
+if [ "${REPO#.}" = "$REPO" ]; then
+ echo "Web: https://forge.jan.systems/$REPO.git"
fi