blob: 331d5462b196f78344eb24c61b968ea3a81da974 (
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
|
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: new [REPO_NAME]"
echo "Tip: prefix with '.' to make private (e.g. new .myrepo)"
exit 1
fi
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
# 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
|