Inicializa repositorio de git con 2 ramas (master / dev). Crea un repositorio remoto. Sincroniza htdocs (/var/www/sitio o /var/www/sitio-dev). Necesita el nombre del repo, usuario y ajustar las rutas.
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 | |
SITIO="$1" | |
PRUEBAS="${1}-dev" | |
USUARIO="$2" | |
PUERTO="22" | |
REPOSITORIO_REMOTO="/var/repo/$SITIO" | |
SHEBANG="#!/bin/bash" | |
BRANCH='\$branch' | |
REF2='\${ref[2]}' | |
REF2_UP='\${REF[2]}' | |
SITIO_HTDOCS="/var/www/$SITIO" | |
SITIO_PRUEBAS="/var/www/$PRUEBAS" | |
read -r -d '' HOOK <<EOF | |
${SHEBANG} | |
if ! [ -t 0 ]; then | |
read -a ref | |
fi | |
IFS='/' read -ra REF <<< "\"$REF2\"" | |
branch="\"$REF2_UP\"" | |
echo "$branch" | |
if [ "\"$BRANCH\"" == 'master' ]; then | |
echo ' * * * Actualizando $SITIO_HTDOCS * * * ' | |
GIT_WORK_TREE=$SITIO_HTDOCS git checkout -f | |
echo ' * * * ¡ Hecho ! * * * ' | |
fi | |
if [ "\"$BRANCH\"" == 'dev' ]; then | |
echo ' * * * Actualizando $SITIO_PRUEBAS * * * ' | |
GIT_WORK_TREE=$SITIO_PRUEBAS git checkout -f | |
echo ' * * * ¡ Hecho ! * * * ' | |
fi | |
EOF | |
# Repositorio local | |
git init | |
echo ".DS_Store" > .gitignore | |
git add . | |
git commit -m "Repositorio local inicializado" | |
git branch dev | |
# Repositorio Remoto | |
ssh -p $PUERTO $USUARIO "mkdir -m 0775 $SITIO_HTDOCS; mkdir -m 0775 $SITIO_PRUEBAS; mkdir $REPOSITORIO_REMOTO; cd $REPOSITORIO_REMOTO; git init --bare; echo \"$HOOK\" > $REPOSITORIO_REMOTO/hooks/post-receive; chmod +x $REPOSITORIO_REMOTO/hooks/post-receive; exit;" | |
wait | |
# Repositorio local | |
git remote add origin ssh://$USUARIO:$PUERTO$REPOSITORIO_REMOTO | |
git push origin +master:refs/heads/master | |
git remote add dev ssh://$USUARIO:$PUERTO$REPOSITORIO_REMOTO | |
git push origin +dev:refs/heads/dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment