edited multimail path to be version agnostic
[git_shell.git] / create
CommitLineData
81873de4 1#! /bin/bash
2
3# usage: create <PROJECT> - create a git bare repository named PROJECT.git
4# this command will setup the repo and send a mail for confirmation.
5
6GITDIR="/var/git"
d96d4d16 7BASEDIR=".gitbase"
ac06b109 8MULTIMAIL="/usr/doc/git-*/contrib/hooks/multimail/git_multimail.py"
81873de4 9GITUSER="git"
10GITGRP="git"
11VENVSDIR="/usr/local/venvs"
12USEVENV=false
13
14function is_bare() {
15 repodir=$1
16 if "$(git --git-dir="$repodir" rev-parse --is-bare-repository)" = true
17 then
18 true
19 else
20 false
21 fi
22}
23
24function git_init() {
25 PROJECT=$1
26 echo "creating project \"${PROJECT}.git\""
13686e1e 27 echo -n "Describe your project in one line: "
28 read DESCRIPTION
81873de4 29 if [ ! -d ${GITDIR}/${PROJECT}.git ]; then
30 mkdir ${GITDIR}/${PROJECT}.git
31 fi
32 cd ${GITDIR}/${PROJECT}.git
33 git init --bare
34 echo "Remember to insert a README.md file to explain what your project is about."
35 mkdir custom-hooks
36 ln -s $MULTIMAIL custom-hooks/git_multimail.py
81873de4 37
d96d4d16 38 # check if we are creating a python project
81873de4 39 if [ $USEVENV == true ]; then
d96d4d16 40 # if yes
41 cp ${GITDIR}/${BASEDIR}/post-receive-py hooks/post-receive
42 sed -i "s|{{GITDIR}}|${GITDIR}|g" hooks/post-receive
43 sed -i "s|{{PROJECT}}|${PROJECT}|g" hooks/post-receive
44 cp ${GITDIR}/${BASEDIR}/pip_install custom-hooks/pip_install
45 sed -i "s|{{VENVSDIR}}|${VENVSDIR}|g" custom-hooks/pip_install
46 sed -i "s|{{PROJECT}}|${PROJECT}|g" custom-hooks/pip_install
47 chmod 0755 custom-hooks/pip_install
48 else
49 # otherwise
50 cp ${GITDIR}/${BASEDIR}/post-receive hooks/post-receive
51 sed -i "s|{{GITDIR}}|${GITDIR}|g" hooks/post-receive
52 sed -i "s|{{PROJECT}}|${PROJECT}|g" hooks/post-receive
81873de4 53 fi
d96d4d16 54 # in any case we setup so that we can deploy
55 cp ${GITDIR}/${BASEDIR}/deploy.sh custom-hooks/deploy.sh
56 sed -i "s|{{GITDIR}}|${GITDIR}|g" custom-hooks/deploy.sh
57 sed -i "s|{{PROJECT}}|${PROJECT}|g" custom-hooks/deploy.sh
58 # add multimail settings to config
81873de4 59 cat >> config <<EOT
60
61[multimailhook]
62 mailer = "sendmail"
63 refchangeShowGraph = true
64 mailingList = "danixland@gmail.com"
65 commitEmailFormat = "html"
66 htmlInIntro = true
67 htmlInFooter = true
68 from = "danix@danix.xyz"
69 administrator = "danix@danix.xyz"
70 quiet = true
71 logFile = "/var/log/multimail.log"
72 errorLogFile = "/var/log/multimail_err.log"
73EOT
81873de4 74
d96d4d16 75 # fix permissions to post-receive and deploy.sh scripts
81873de4 76 chmod 0755 hooks/post-receive custom-hooks/deploy.sh
77 echo $DESCRIPTION > description
78 cd ${GITDIR}/
79 chown -R ${GITUSER}:${GITGRP} ${GITDIR}/${PROJECT}.git
80 echo "All done, you can now work on \"${PROJECT}.git\""
d4b62404 81 echo "You can now clone this repository at ssh://danix_git:/${GITDIR}/${PROJECT}.git"
81873de4 82 exit 0
83}
84
85if [ ! -z $1 ]; then
86 if [ "python" == $1 ]; then
87 USEVENV=true
88 # this is a python project. Let's create a virtualenv
89 if [ ! -z $2 ]; then
90 PROJECT=$2
91 else
92 read -p 'Python project name: ' PROJECT
93 fi
94 virtualenv ${VENVSDIR}/${PROJECT}
95 echo "virtual environment created inside ${VENVSDIR}/${PROJECT}"
96 else
97 PROJECT=$1
98 fi
99else
100 read -p 'Project name: ' PROJECT
101fi
102
103if [ ! -d ${GITDIR}/${PROJECT}.git ]; then
104 git_init $PROJECT
105else
106 echo "Project directory ${PROJECT}.git already exists."
107 if [ $(ls -A ${GITDIR}/${PROJECT}.git) ]; then
108 if is_bare ${GITDIR}/${PROJECT}.git
109 then
110 echo "looks like \"${PROJECT}.git\" is an existing git project directory, choose another name."
111 exit 171
112 else
113 echo "\"${PROJECT}.git\" is not empty, I can't create a Git Project in it. Choose another name."
114 exit 172
115 fi
116 else
117 echo "\"${PROJECT}.git\" is an empty directory. Do you want to initialize a Git Project here? [y/N]"
118 read answer
119 case $answer in
120 Y|y)
121 git_init $PROJECT
122 ;;
123 N|n)
124 echo "Aborting due to user request."
125 exit 173
126 ;;
127 *)
128 # we assume no as default answer.
129 echo "you said \"$answer\" which I don't understand, so to me is no. Aborting."
130 exit 177
131 ;;
132 esac
133 fi
134fi
135
136