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 read -p "Describe your project in one line: " DESCRIPTION
27 if [ ! -d ${GITDIR}/${PROJECT}.git
]; then
28 mkdir
${GITDIR}/${PROJECT}.git
30 cd ${GITDIR}/${PROJECT}.git
32 echo "Remember to insert a README.md file to explain what your project is about."
34 ln -s $MULTIMAIL custom-hooks
/git_multimail.py
35 touch hooks
/post-receive
36 cat > hooks
/post-receive
<<EOPR
38 /usr/bin/pee ${GITDIR}/${PROJECT}.git/custom-hooks/deploy.sh \
39 ${GITDIR}/${PROJECT}.git/custom-hooks/pip_install \
40 ${GITDIR}/${PROJECT}.git/custom-hooks/git_multimail.py
43 if [ $USEVENV == true
]; then
44 cat > custom-hooks
/pip_install
<< EOPIP
46 while read oldrev newrev refname; do
47 if [[ \$refname =~ .*/master$ ]]; then
48 # definitely updating master;
49 CHECKFILE=\$(git ls-tree --full-tree -r HEAD |grep requirements.txt |awk '{print \$3}')
50 TMPREQ=\$(git cat-file -p \$CHECKFILE > /tmp/${PROJECT}-req.txt)
51 if [ \$CHECKFILE ]; then
52 ${VENVSDIR}/${PROJECT}/bin/pip install -r /tmp/${PROJECT}-req.txt
54 if git diff-tree --name-only -r -z \$oldrev \$newrev \$CHECKFILE; then
55 ${VENVSDIR}/${PROJECT}/bin/pip install -r /tmp/${PROJECT}-req.txt
65 refchangeShowGraph = true
66 mailingList = "danixland@gmail.com"
67 commitEmailFormat = "html"
70 from = "danix@danix.xyz"
71 administrator = "danix@danix.xyz"
73 logFile = "/var/log/multimail.log"
74 errorLogFile = "/var/log/multimail_err.log"
76 touch custom-hooks
/deploy.sh
77 cat > custom-hooks
/deploy.sh
<<EODP
79 # Directory where to deploy files from repository
81 # Directory containing repository
82 DPGIT_DIR="${GITDIR}/${PROJECT}.git"
83 # Branch that is going to be deployed to server
86 while read oldrev newrev ref
88 # if DPTARGET is empty we don't want deploy for this project
89 if [[ ! "" == \$DPTARGET ]]; then
90 # let's check that we are deploying to the correct branch
91 if [[ \$ref = refs/heads/\${DPBRANCH} ]]; then
92 echo "Ref \$ref received. Deploying \${DPBRANCH} branch to production..."
93 git --work-tree=\$DPTARGET --git-dir=\$DPGIT_DIR checkout -f \$DPBRANCH
94 NOW=\$(date +"%d%m%Y-%H%M")
95 git tag release_\$NOW \$DPBRANCH
96 echo " /==============================="
97 echo " | DEPLOYMENT COMPLETED"
98 echo " | Target branch: \$DPTARGET"
99 echo " | Target folder: \$DPGIT_DIR"
100 echo " | Tag name : release_\$NOW"
101 echo " \=============================="
103 echo "Ref \$ref received. Doing nothing: only the \${DPBRANCH} branch may be deployed on this server."
106 echo "Target directory not declared. Skipping deploy to server."
111 chmod 0755 hooks
/post-receive custom-hooks
/deploy.sh
112 echo $DESCRIPTION > description
114 chown
-R ${GITUSER}:${GITGRP} ${GITDIR}/${PROJECT}.git
115 echo "All done, you can now work on \"${PROJECT}.git\""
120 if [ "python" == $1 ]; then
122 # this is a python project. Let's create a virtualenv
126 read -p 'Python project name: ' PROJECT
128 virtualenv
${VENVSDIR}/${PROJECT}
129 echo "virtual environment created inside ${VENVSDIR}/${PROJECT}"
134 read -p 'Project name: ' PROJECT
137 if [ ! -d ${GITDIR}/${PROJECT}.git
]; then
140 echo "Project directory ${PROJECT}.git already exists."
141 if [ $
(ls -A ${GITDIR}/${PROJECT}.git
) ]; then
142 if is_bare
${GITDIR}/${PROJECT}.git
144 echo "looks like \"${PROJECT}.git\" is an existing git project directory, choose another name."
147 echo "\"${PROJECT}.git\" is not empty, I can't create a Git Project in it. Choose another name."
151 echo "\"${PROJECT}.git\" is an empty directory. Do you want to initialize a Git Project here? [y/N]"
158 echo "Aborting due to user request."
162 # we assume no as default answer.
163 echo "you said \"$answer\" which I don't understand, so to me is no. Aborting."