summaryrefslogtreecommitdiff
path: root/init
blob: 61605c0203fd7e2ddd2406bef0d62ec4191e22a1 (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
#!/usr/bin/env bash

if [ $# -ne 1 ]; then
    echo "usage: init <name>"
    exit 1
fi

set -xe

base_dir="$HOME"
new_repo="${base_dir}/$1"

case $new_repo in
    *\.git)
	;;
    *)
	new_repo="${new_repo}.git"
	;;
esac

if [ -d "$new_repo" ]; then
    echo "$new_repo already exists"
    exit 1
fi

mkdir "$new_repo"
git init --bare "$new_repo" >/dev/null 2>&1\
    && echo "Initialized empty Git repository: git@$(uname -n):$1"

echo 'git push github -f --mirror' > "$new_repo/hooks/post-receive"
chmod +x "$new_repo/hooks/post-receive"