summaryrefslogtreecommitdiff
path: root/git-shell-commands/mkrepo
blob: ecadb0077327d6f1cb984761df36bd1a8aac48b3 (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
41
42
#!/bin/sh
# Copyright (C) 2024 dwlr <dweller@cabin.digital>
#
# BSD 3-Clause License (BSD-3-Clause)
# See LICENSE for details

set -e

#FIXME: this is wide open for exploits by using crafted paths like ../../../etc/passwd or something
#   But we should be okay since this is behind ssh, right? r- right..?


PREFIX="$HOME/repos"

if [ $# -lt 1 ]; then
    echo "Usage: $(basename "$0") <repo name> [description]"
    exit 1;
fi

case "$1" in
    *.git) reponame="$1"     ;;
    *)     reponame="$1.git" ;;
esac

netname=$(echo "$PREFIX/$reponame" | sed "s|$HOME/|:|")
reponame="$PREFIX/$reponame"


if [ ! -e "$reponame" ];
then
    mkdir -p "$reponame"
    cd "$reponame"
    git init -q --bare && echo "$netname" || echo "Failed to create repo '$netname' :("

    if [ $# -gt 1 ]; then
        shift
        echo "$@" > description
    fi
else
    echo "$netname exists!"
    exit 1
fi