/post-receive Secret
Created
January 15, 2020 08:57
Star
You must be signed in to star a gist
GIT post-receive HOOK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| LANG="fr" | |
| ROOT_PATH="/home/gitjail" | |
| WWW_DIR="${ROOT_PATH}/www_public" | |
| FPV_BLEU_DIR="${WWW_DIR}/preprod" | |
| FPV_PROD_DIR="${WWW_DIR}/prod" | |
| GIT_DIR="${ROOT_PATH}/git/fpv.git" | |
| while read oldrev newrev ref | |
| do | |
| if [[ $ref =~ .*/master$ ]]; then | |
| # ______________________________ | |
| # Récupération de l'adresse IP de la connexion SSH | |
| if [[ -z $SSH_CLIENT ]] | |
| then | |
| echo "Les informations du client SSH n'ont pu être récupérées" | |
| #echo "The SSH client information could not be retrieved" | |
| exit 1 | |
| fi | |
| i=7 | |
| end=false | |
| while [ $i -le 15 ] && [ "$end" = false ] | |
| do | |
| char=${SSH_CLIENT:$i:1} | |
| if [[ $char == " " ]]; then | |
| end=true | |
| fi | |
| let i++ | |
| done | |
| if [ "$end" = false ] | |
| then | |
| echo "L'adresse IP du client de la connexion SSH n'a pu être déterminée" | |
| #echo "The IP address of the SSH connection client could not be determined" | |
| exit 1 | |
| fi | |
| ip_client=${SSH_CLIENT:0:$i} | |
| # ______________________________ | |
| # Vérification de l'habilitation | |
| # | |
| ALLOW=false | |
| allowed=('x' 'y') | |
| for ip_allow in "${allowed[@]}" | |
| do | |
| if [ $ip_client = $ip_allow ]; then | |
| ALLOW=true | |
| fi | |
| done | |
| if [ "$ALLOW" = false ] | |
| then | |
| echo "Vous n'êtes pas habilité à pousser du code au sein de la branche Master/PROD" | |
| #echo "You are not allowed to push code within the Master/PROD branch" | |
| exit 1 | |
| fi | |
| echo "Master/PROD a bien été récupéré." | |
| #echo "Master/PROD has been recovered well." | |
| echo "Déploiement de Master/PROD au sein du répertoire de l'exploitation de production..." | |
| #echo "Deploying master branch to production folder..." | |
| git --work-tree=$FPV_PROD_DIR --git-dir=$GIT_DIR checkout -f master | |
| echo "Master/PROD a été déployé avec succès !" | |
| #echo "Master/PROD has been successfully deployed." | |
| elif [[ $ref =~ .*/preprod$ ]]; then | |
| echo "PréPROD/Bleu a bien été récupéré." | |
| #echo "PréPROD/Bleu has been recovered well." | |
| echo "Déploiement de PréPROD/Bleu au sein du répertoire de l'exploitation de pré-production..." | |
| #echo "Deploying preprod branch to pre-production folder..." | |
| git --work-tree=$FPV_BLEU_DIR --git-dir=$GIT_DIR checkout -f preprod | |
| echo "PréPROD/Bleu a été déployé avec succès !" | |
| #echo "PréPROD/Bleu has been successfully deployed." | |
| else | |
| echo "Ref $ref reçu avec succès." | |
| #echo "Ref $ref successfully received." | |
| echo "" | |
| echo "Ne rien faire : seules les branches master et preprod peuvent être déployées sur ce serveur." | |
| #echo "Doing nothing: only the master and preprod branch may be deployed on this server." | |
| fi | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment