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.
7 MULTIMAIL
="/usr/doc/git-2.14.5/contrib/hooks/multimail/git_multimail.py"
10 VENVSDIR
="/usr/local/venvs"
15 if "$(git --git-dir="$repodir" rev-parse --is-bare-repository)" = true
25 echo "creating project \"${PROJECT}.git\""
26 echo -n "Describe your project in one line: "
28 if [ ! -d ${GITDIR}/${PROJECT}.git
]; then
29 mkdir
${GITDIR}/${PROJECT}.git
31 cd ${GITDIR}/${PROJECT}.git
33 echo "Remember to insert a README.md file to explain what your project is about."
35 ln -s $MULTIMAIL custom-hooks
/git_multimail.py
36 touch hooks
/post-receive
37 cat > hooks
/post-receive
<<EOPR
39 /usr/bin/pee ${GITDIR}/${PROJECT}.git/custom-hooks/deploy.sh \
40 ${GITDIR}/${PROJECT}.git/custom-hooks/pip_install \
41 ${GITDIR}/${PROJECT}.git/custom-hooks/git_multimail.py
44 if [ $USEVENV == true
]; then
45 cat > custom-hooks
/pip_install
<< EOPIP
47 while read oldrev newrev refname; do
48 if [[ \$refname =~ .*/master$ ]]; then
49 # definitely updating master;
50 CHECKFILE=\$(git ls-tree --full-tree -r HEAD |grep requirements.txt |awk '{print \$3}')
51 TMPREQ=\$(git cat-file -p \$CHECKFILE > /tmp/${PROJECT}-req.txt)
52 if [ \$CHECKFILE ]; then
53 ${VENVSDIR}/${PROJECT}/bin/pip install -r /tmp/${PROJECT}-req.txt
55 if git diff-tree --name-only -r -z \$oldrev \$newrev \$CHECKFILE; then
56 ${VENVSDIR}/${PROJECT}/bin/pip install -r /tmp/${PROJECT}-req.txt
66 refchangeShowGraph = true
67 mailingList = "danixland@gmail.com"
68 commitEmailFormat = "html"
71 from = "danix@danix.xyz"
72 administrator = "danix@danix.xyz"
74 logFile = "/var/log/multimail.log"
75 errorLogFile = "/var/log/multimail_err.log"
77 touch custom-hooks
/deploy.sh
78 cat > custom-hooks
/deploy.sh
<<EODP
80 # Directory where to deploy files from repository
82 # Directory containing repository
83 DPGIT_DIR="${GITDIR}/${PROJECT}.git"
84 # Branch that is going to be deployed to server
87 while read oldrev newrev ref
89 # if DPTARGET is empty we don't want deploy for this project
90 if [[ ! "" == \$DPTARGET ]]; then
91 # let's check that we are deploying to the correct branch
92 if [[ \$ref = refs/heads/\${DPBRANCH} ]]; then
93 echo "Ref \$ref received. Deploying \${DPBRANCH} branch to production..."
94 git --work-tree=\$DPTARGET --git-dir=\$DPGIT_DIR checkout -f \$DPBRANCH
95 NOW=\$(date +"%d%m%Y-%H%M")
96 git tag release_\$NOW \$DPBRANCH
97 echo " /==============================="
98 echo " | DEPLOYMENT COMPLETED"
99 echo " | Target branch: \$DPTARGET"
100 echo " | Target folder: \$DPGIT_DIR"
101 echo " | Tag name : release_\$NOW"
102 echo " \=============================="
104 echo "Ref \$ref received. Doing nothing: only the \${DPBRANCH} branch may be deployed on this server."
107 echo "Target directory not declared. Skipping deploy to server."
112 chmod 0755 hooks
/post-receive custom-hooks
/deploy.sh
113 echo $DESCRIPTION > description
115 chown
-R ${GITUSER}:${GITGRP} ${GITDIR}/${PROJECT}.git
116 echo "All done, you can now work on \"${PROJECT}.git\""
121 if [ "python" == $1 ]; then
123 # this is a python project. Let's create a virtualenv
127 read -p 'Python project name: ' PROJECT
129 virtualenv
${VENVSDIR}/${PROJECT}
130 echo "virtual environment created inside ${VENVSDIR}/${PROJECT}"
135 read -p 'Project name: ' PROJECT
138 if [ ! -d ${GITDIR}/${PROJECT}.git
]; then
141 echo "Project directory ${PROJECT}.git already exists."
142 if [ $
(ls -A ${GITDIR}/${PROJECT}.git
) ]; then
143 if is_bare
${GITDIR}/${PROJECT}.git
145 echo "looks like \"${PROJECT}.git\" is an existing git project directory, choose another name."
148 echo "\"${PROJECT}.git\" is not empty, I can't create a Git Project in it. Choose another name."
152 echo "\"${PROJECT}.git\" is an empty directory. Do you want to initialize a Git Project here? [y/N]"
159 echo "Aborting due to user request."
163 # we assume no as default answer.
164 echo "you said \"$answer\" which I don't understand, so to me is no. Aborting."