#!/bin/bash # source: https://gist.github.com/francoisromain/58cabf43c2977e48ef0804848dee46c3 # and another script to delete the directories created by this script # project-delete.sh: https://gist.github.com/francoisromain/e28069c18ebe8f3244f8e4bf2af6b2cb # Call this file with `bash ./project-create.sh project-name` # - project-name is mandatory # This will creates 4 directories and a git `post-receive` hook. # The 4 directories are: # - $GIT: a git repo # - $TMP: a temporary directory for deployment # - $WWW: a directory for the actual production files # - $ENV: a directory for the env variables # When you push your code to the git repo, # the `post-receive` hook will deploy the code # in the $TMP directory, then copy it to $WWW. DIR_TMP="/srv/tmp/" DIR_WWW="/srv/www/" DIR_GIT="/srv/git/" DIR_ENV="/srv/env/" function dir_create() { sudo mkdir -p "$1" cd "$1" || exit # Define group recursively to "users", on the directories sudo chgrp -R users . # Define permissions recursively, on the sub-directories # g = group, + add rights, r = read, w = write, X = directories only # . = curent directory as a reference sudo chmod -R g+rwX . } if [ $# -eq 0 ]; then echo 'No project name provided (mandatory)' exit 1 else echo "- Project name:" "$1" fi GIT=$DIR_GIT$1.git TMP=$DIR_TMP$1 WWW=$DIR_WWW$1 ENV=$DIR_ENV$1 echo "- git:" "$GIT" echo "- tmp:" "$TMP" echo "- www:" "$WWW" echo "- env:" "$ENV" export GIT export TMP export WWW export ENV # Create a directory for the env repository sudo mkdir -p "$ENV" cd "$ENV" || exit sudo touch .env # Create a directory for the git repository sudo mkdir -p "$GIT" cd "$GIT" || exit # Init the repo as an empty git repository sudo git init --bare # Define group recursively to "users", on the directories sudo chgrp -R users . # Define permissions recursively, on the sub-directories # g = group, + add rights, r = read, w = write, X = directories only # . = curent directory as a reference sudo chmod -R g+rwX . # Sets the setgid bit on all the directories # https://www.gnu.org/software/coreutils/manual/html_node/Directory-Setuid-and-Setgid.html sudo find . -type d -exec chmod g+s '{}' + # Make the directory a shared repo sudo git config core.sharedRepository group cd hooks || exit sudo touch post-receive # create a post-receive file sudo tee post-receive <