extra scripts are now separated from main create script.
authordanix <danix@danix.xyz>
Wed, 19 Dec 2018 07:16:14 +0000 (08:16 +0100)
committerdanix <danix@danix.xyz>
Wed, 19 Dec 2018 07:16:14 +0000 (08:16 +0100)
create
gitbase/deploy.sh [new file with mode: 0644]
gitbase/pip_install [new file with mode: 0644]
gitbase/post-receive [new file with mode: 0644]
gitbase/post-receive-py [new file with mode: 0644]

diff --git a/create b/create
index f3fa041f814553f1f663bca568b545026373ee21..a98db20b12a50d5ff949807398463ef1cf5b4a4c 100755 (executable)
--- a/create
+++ b/create
@@ -4,6 +4,7 @@
 #              this command will setup the repo and send a mail for confirmation.
 
 GITDIR="/var/git"
 #              this command will setup the repo and send a mail for confirmation.
 
 GITDIR="/var/git"
+BASEDIR=".gitbase"
 MULTIMAIL="/usr/doc/git-2.14.5/contrib/hooks/multimail/git_multimail.py"
 GITUSER="git"
 GITGRP="git"
 MULTIMAIL="/usr/doc/git-2.14.5/contrib/hooks/multimail/git_multimail.py"
 GITUSER="git"
 GITGRP="git"
@@ -33,32 +34,28 @@ function git_init() {
        echo "Remember to insert a README.md file to explain what your project is about."
        mkdir custom-hooks
        ln -s $MULTIMAIL custom-hooks/git_multimail.py
        echo "Remember to insert a README.md file to explain what your project is about."
        mkdir custom-hooks
        ln -s $MULTIMAIL custom-hooks/git_multimail.py
-       touch hooks/post-receive
-       cat > hooks/post-receive <<EOPR
-#!/bin/sh
-/usr/bin/pee ${GITDIR}/${PROJECT}.git/custom-hooks/deploy.sh \
-       ${GITDIR}/${PROJECT}.git/custom-hooks/pip_install \
-       ${GITDIR}/${PROJECT}.git/custom-hooks/git_multimail.py
 
 
-EOPR
+       # check if we are creating a python project
        if [ $USEVENV == true ]; then
        if [ $USEVENV == true ]; then
-               cat > custom-hooks/pip_install << EOPIP
-#!/bin/sh
-while read oldrev newrev refname; do
-       if [[ \$refname =~ .*/master$ ]]; then
-               # definitely updating master;
-               CHECKFILE=\$(git ls-tree --full-tree -r HEAD |grep requirements.txt |awk '{print \$3}')
-               TMPREQ=\$(git cat-file -p \$CHECKFILE > /tmp/${PROJECT}-req.txt)
-               if [ \$CHECKFILE ]; then
-                       ${VENVSDIR}/${PROJECT}/bin/pip install -r /tmp/${PROJECT}-req.txt
-               fi
-               if git diff-tree --name-only -r -z \$oldrev \$newrev \$CHECKFILE; then
-                       ${VENVSDIR}/${PROJECT}/bin/pip install -r /tmp/${PROJECT}-req.txt
-               fi
-       fi
-done
-EOPIP
+               # if yes
+               cp ${GITDIR}/${BASEDIR}/post-receive-py hooks/post-receive
+               sed -i "s|{{GITDIR}}|${GITDIR}|g" hooks/post-receive
+               sed -i "s|{{PROJECT}}|${PROJECT}|g" hooks/post-receive
+               cp ${GITDIR}/${BASEDIR}/pip_install custom-hooks/pip_install
+               sed -i "s|{{VENVSDIR}}|${VENVSDIR}|g" custom-hooks/pip_install
+               sed -i "s|{{PROJECT}}|${PROJECT}|g" custom-hooks/pip_install
+               chmod 0755 custom-hooks/pip_install
+       else
+               # otherwise
+               cp ${GITDIR}/${BASEDIR}/post-receive hooks/post-receive
+               sed -i "s|{{GITDIR}}|${GITDIR}|g" hooks/post-receive
+               sed -i "s|{{PROJECT}}|${PROJECT}|g" hooks/post-receive
        fi
        fi
+       # in any case we setup so that we can deploy
+       cp ${GITDIR}/${BASEDIR}/deploy.sh custom-hooks/deploy.sh
+       sed -i "s|{{GITDIR}}|${GITDIR}|g" custom-hooks/deploy.sh
+       sed -i "s|{{PROJECT}}|${PROJECT}|g" custom-hooks/deploy.sh
+       # add multimail settings to config
        cat >> config <<EOT
 
 [multimailhook]
        cat >> config <<EOT
 
 [multimailhook]
@@ -74,41 +71,8 @@ EOPIP
        logFile = "/var/log/multimail.log"
        errorLogFile = "/var/log/multimail_err.log"
 EOT
        logFile = "/var/log/multimail.log"
        errorLogFile = "/var/log/multimail_err.log"
 EOT
-       touch custom-hooks/deploy.sh
-       cat > custom-hooks/deploy.sh <<EODP
-#!/bin/bash
-# Directory where to deploy files from repository
-DPTARGET=""
-# Directory containing repository
-DPGIT_DIR="${GITDIR}/${PROJECT}.git"
-# Branch that is going to be deployed to server
-DPBRANCH="master"
-
-while read oldrev newrev ref
-do
-       # if DPTARGET is empty we don't want deploy for this project
-       if [[ ! "" == \$DPTARGET ]]; then
-               # let's check that we are deploying to the correct branch
-               if [[ \$ref = refs/heads/\${DPBRANCH} ]]; then
-                       echo "Ref \$ref received. Deploying \${DPBRANCH} branch to production..."
-                       git --work-tree=\$DPTARGET --git-dir=\$DPGIT_DIR checkout -f \$DPBRANCH
-                       NOW=\$(date +"%d%m%Y-%H%M")
-                       git tag release_\$NOW \$DPBRANCH
-                       echo "   /==============================="
-                       echo "   | DEPLOYMENT COMPLETED"
-                       echo "   | Target branch: \$DPTARGET"
-                       echo "   | Target folder: \$DPGIT_DIR"
-                       echo "   | Tag name     : release_\$NOW"
-                       echo "   \=============================="
-               else
-                       echo "Ref \$ref received. Doing nothing: only the \${DPBRANCH} branch may be deployed on this server."
-               fi
-       else
-               echo "Target directory not declared. Skipping deploy to server."
-       fi
-done
 
 
-EODP
+       # fix permissions to post-receive and deploy.sh scripts
        chmod 0755 hooks/post-receive custom-hooks/deploy.sh
        echo $DESCRIPTION > description
        cd ${GITDIR}/
        chmod 0755 hooks/post-receive custom-hooks/deploy.sh
        echo $DESCRIPTION > description
        cd ${GITDIR}/
diff --git a/gitbase/deploy.sh b/gitbase/deploy.sh
new file mode 100644 (file)
index 0000000..6ee3a17
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+# Directory where to deploy files from repository
+DPTARGET=""
+# Directory containing repository
+DPGIT_DIR="{{GITDIR}}/{{PROJECT}}.git"
+# Branch that is going to be deployed to server
+DPBRANCH="master"
+
+while read oldrev newrev ref
+do
+       # if DPTARGET is empty we don't want deploy for this project
+       if [[ ! "" == $DPTARGET ]]; then
+               # let's check that we are deploying to the correct branch
+               if [[ $ref = refs/heads/${DPBRANCH} ]]; then
+                       echo "Ref $ref received. Deploying ${DPBRANCH} branch to production..."
+                       git --work-tree=$DPTARGET --git-dir=$DPGIT_DIR checkout -f $DPBRANCH
+                       NOW=$(date +"%d%m%Y-%H%M")
+                       git tag release_$NOW $DPBRANCH
+                       echo "   /==============================="
+                       echo "   | DEPLOYMENT COMPLETED"
+                       echo "   | Target branch: $DPTARGET"
+                       echo "   | Target folder: $DPGIT_DIR"
+                       echo "   | Tag name     : release_$NOW"
+                       echo "   \=============================="
+               else
+                       echo "Ref $ref received. Doing nothing: only the ${DPBRANCH} branch may be deployed on this server."
+               fi
+       else
+               echo "Target directory not declared. Skipping deploy to server."
+       fi
+done
diff --git a/gitbase/pip_install b/gitbase/pip_install
new file mode 100644 (file)
index 0000000..07a6374
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+while read oldrev newrev refname; do
+       if [[ $refname =~ .*/master$ ]]; then
+               # definitely updating master;
+               CHECKFILE=$(git ls-tree --full-tree -r HEAD |grep requirements.txt |awk '{print $3}')
+               TMPREQ=$(git cat-file -p $CHECKFILE > /tmp/{{PROJECT}}-req.txt)
+               if [ $CHECKFILE ]; then
+                       {{VENVSDIR}}/{{PROJECT}}/bin/pip install -r /tmp/{{PROJECT}}-req.txt
+               fi
+               if git diff-tree --name-only -r -z $oldrev $newrev $CHECKFILE; then
+                       {{VENVSDIR}}/{{PROJECT}}/bin/pip install -r /tmp/{{PROJECT}}-req.txt
+               fi
+       fi
+done
diff --git a/gitbase/post-receive b/gitbase/post-receive
new file mode 100644 (file)
index 0000000..d9da8cb
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+/usr/bin/pee {{GITDIR}}/{{PROJECT}}.git/custom-hooks/deploy.sh \
+       {{GITDIR}}/{{PROJECT}}.git/custom-hooks/git_multimail.py
diff --git a/gitbase/post-receive-py b/gitbase/post-receive-py
new file mode 100644 (file)
index 0000000..37ac6cf
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+/usr/bin/pee {{GITDIR}}/{{PROJECT}}.git/custom-hooks/deploy.sh \
+       {{GITDIR}}/{{PROJECT}}.git/custom-hooks/pip_install \
+       {{GITDIR}}/{{PROJECT}}.git/custom-hooks/git_multimail.py