-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewgit.sh
executable file
·81 lines (69 loc) · 1.91 KB
/
newgit.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# this script is based on code from the following blog post
# http://arvinderkang.com/2010/08/25/hosting-git-repositories-on-dreamhost/
# and http://gist.github.com/73622
set -e
# Please, configure a default GIT_REPOS_ROOT to match your config
#GIT_REPOS_ROOT="~/private_repos/"
DEFAULT_DESCRIPTION='no description :('
# describe how the script works
usage()
{
echo "Usage: $0 [ -h ] [ -r directory] [ -d description ] [ -n projectname ]"
echo ""
echo "If no projectname is given, the name of the parent folder will be used as project name."
echo ""
echo " -r directory : (root) directory holding your git repositories"
echo " -d description : description for gitweb"
echo " -h : print this screen"
echo " -n name : name of the project (should end in .git)"
echo ""
}
DESCRIPTION=${DEFAULT_DESCRIPTION}
# evaluate the options passed on the command line
while getopts r:d:n:h option
do
case "${option}"
in
r) GIT_REPOS_ROOT=${OPTARG};;
d) DESCRIPTION=${OPTARG};;
n) REPONAME=${OPTARG};;
h) usage
exit 1;;
esac
done
# check if repositories directory is given and is accessible
if [ -z $GIT_REPOS_ROOT ]; then
usage
exit 1
fi
if ! [ -d $GIT_REPOS_ROOT ]; then
echo "ERROR: '${GIT_REPOS_ROOT}' is not a directory"
echo ""
usage
exit 1
fi
# check if name of repository is given. if not, use folder name
if [ -z $REPONAME ]; then
REPONAME=$(basename $PWD)
fi
# Add .git at and if needed
if ! ( echo $REPONAME | grep -q '\.git$'); then
REPONAME="${REPONAME}.git"
fi
#
# Ready to go
#
REP_DIR="${GIT_REPOS_ROOT}/${REPONAME}"
mkdir ${REP_DIR}
pushd ${REP_DIR}
git --bare init
git --bare update-server-info
cp hooks/post-update.sample hooks/post-update
chmod a+x hooks/post-update
echo $DESCRIPTION > description
# This mark the repository as exportable.
# For more info refer to git-http-backend manpage
touch git-daemon-export-ok
popd
exit 0