From 81873de46fa20d0d13ee44659850c07c2b247816 Mon Sep 17 00:00:00 2001 From: danix Date: Tue, 18 Dec 2018 15:12:50 +0100 Subject: initial commit --- create | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100755 create (limited to 'create') diff --git a/create b/create new file mode 100755 index 0000000..04d299a --- /dev/null +++ b/create @@ -0,0 +1,170 @@ +#! /bin/bash + +# usage: create - create a git bare repository named PROJECT.git +# this command will setup the repo and send a mail for confirmation. + +GITDIR="/var/git" +MULTIMAIL="/usr/doc/git-2.14.5/contrib/hooks/multimail/git_multimail.py" +GITUSER="git" +GITGRP="git" +VENVSDIR="/usr/local/venvs" +USEVENV=false + +function is_bare() { + repodir=$1 + if "$(git --git-dir="$repodir" rev-parse --is-bare-repository)" = true + then + true + else + false + fi +} + +function git_init() { + PROJECT=$1 + echo "creating project \"${PROJECT}.git\"" + read -p "Describe your project in one line: " DESCRIPTION + if [ ! -d ${GITDIR}/${PROJECT}.git ]; then + mkdir ${GITDIR}/${PROJECT}.git + fi + cd ${GITDIR}/${PROJECT}.git + git init --bare + 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 < 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 + fi + cat >> config < custom-hooks/deploy.sh < description + cd ${GITDIR}/ + chown -R ${GITUSER}:${GITGRP} ${GITDIR}/${PROJECT}.git + echo "All done, you can now work on \"${PROJECT}.git\"" + exit 0 +} + +if [ ! -z $1 ]; then + if [ "python" == $1 ]; then + USEVENV=true + # this is a python project. Let's create a virtualenv + if [ ! -z $2 ]; then + PROJECT=$2 + else + read -p 'Python project name: ' PROJECT + fi + virtualenv ${VENVSDIR}/${PROJECT} + echo "virtual environment created inside ${VENVSDIR}/${PROJECT}" + else + PROJECT=$1 + fi +else + read -p 'Project name: ' PROJECT +fi + +if [ ! -d ${GITDIR}/${PROJECT}.git ]; then + git_init $PROJECT +else + echo "Project directory ${PROJECT}.git already exists." + if [ $(ls -A ${GITDIR}/${PROJECT}.git) ]; then + if is_bare ${GITDIR}/${PROJECT}.git + then + echo "looks like \"${PROJECT}.git\" is an existing git project directory, choose another name." + exit 171 + else + echo "\"${PROJECT}.git\" is not empty, I can't create a Git Project in it. Choose another name." + exit 172 + fi + else + echo "\"${PROJECT}.git\" is an empty directory. Do you want to initialize a Git Project here? [y/N]" + read answer + case $answer in + Y|y) + git_init $PROJECT + ;; + N|n) + echo "Aborting due to user request." + exit 173 + ;; + *) + # we assume no as default answer. + echo "you said \"$answer\" which I don't understand, so to me is no. Aborting." + exit 177 + ;; + esac + fi +fi + + -- cgit v1.2.3