summaryrefslogtreecommitdiff
path: root/bin/stagit-new-repo
blob: e7cba72128f56204aa1e664099654661a9506530 (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
#!/bin/sh

# This script creates a initializes a new git 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

git init --bare "$srv/$repo.git"
cp "/usr/local/share/post-receive" "$srv/$repo.git/hooks/post-receive"
chmod u+x "$srv/$repo.git/hooks/post-receive"
echo "git@$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/"

[ -d "$www/$repo" ] && echo "$www/$repo already exists!" && exit 1
mkdir "$www/$repo"
chown -R git:git "$www/$repo"
/usr/local/bin/stagit-gen-index