Last active
August 2, 2016 21:08
-
-
Save marcoslhc/4158366 to your computer and use it in GitHub Desktop.
Create a git managed website in webfaction
This file contains hidden or 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
# based in the joe maller method of | |
# managing a live website through | |
# git: | |
# | |
# http://joemaller.com/990/a-web-focused-git-workflow/ | |
# | |
#!/bin/bash | |
print_help(){ | |
echo | |
echo | |
echo "Usage: $1 app_name $2 git_repo_app" | |
echo | |
echo "-----------------------------------------------------------" | |
echo | |
echo "The git app and the app you want to store the repo" | |
echo "must be created before running the script" | |
echo "You must configure the script after creating the git app" | |
echo "changing the \$HUB variable for something like:" | |
echo | |
echo " \${HOME}/webapps/git_repo_app/repos " | |
echo | |
echo "where git_repo_app is the name of your git app" | |
echo | |
echo "-----------------------------------------------------------" | |
echo | |
echo "# @Autor: Marcos Hernández @email:[email protected]" | |
echo "# @Licencia:" | |
echo "# Está obra está sujeta a la licencia " | |
echo "# Reconocimiento-NoComercial-CompartirIgual 3.0 Unported de Creative Commons." | |
echo "# Para ver una copia de esta licencia, visite " | |
echo "# http://creativecommons.org/licenses/by-nc-sa/3.0/." | |
echo | |
} | |
[ $# -eq 0 ] && { print_help; exit 999; } | |
PRIME=${HOME}'/webapps/'${1} | |
HUB=${HOME}'/webapps/'${2}'/repos/'${1}'.git' | |
echo | |
echo "--*-- Creating the live repo (Primary) --*--" | |
echo | |
cd $PRIME || exit | |
filename=$(date|md5) | |
echo -e 'It is OK to delete this file' > $filename | |
git init | |
git add . | |
git commit -m 'First Commit' | |
echo | |
echo "--*-- Creating the Bare repo (HUB) --*--" | |
echo | |
mkdir $HUB && cd $HUB || exit | |
git --bare init | |
echo | |
echo "--*-- Adding HUB as a PRIME's remote --*--" | |
echo | |
cd $PRIME | |
git remote add hub $HUB | |
git push hub master | |
echo | |
echo "--*-- Creating HOOKS --*--" | |
echo | |
echo | |
echo "***" | |
echo "* HUB post-update" | |
echo "* Creating Script" | |
echo "***" | |
echo | |
cd $HUB/HOOKS | |
echo -e "#~/bin/sh" > post-update | |
echo -e "" >> post-update | |
echo -e "echo" >> post-update | |
echo -e "echo -- * -- Pulling changes into Prime -- * --" >> post-update | |
echo -e "echo" >> post-update | |
echo -e "" >> post-update | |
echo -e "cd "${PRIME} >> post-update | |
echo -e "unset GIT_DIR" >> post-update | |
echo -e "git pull hub master" >> post-update | |
echo -e "" >> post-update | |
echo -e "exec git-update-server-info" >> post-update | |
echo "***" | |
echo "* HUB post-update" | |
echo "* setting Script's permissions" | |
echo "***" | |
echo | |
chmod a+x post-update | |
echo "***" | |
echo "* PRIME post-commit" | |
echo "* Creating script" | |
echo "***" | |
echo | |
cd $PRIME/.git/HOOKS | |
echo -e "#~/bin/sh" > post-commit | |
echo -e "" >> post-commit | |
echo -e "echo" >> post-commit | |
echo -e "echo -- * -- Pushing changes into HUB -- * --" >> post-commit | |
echo -e "echo" >> post-commit | |
echo -e "" >> post-commit | |
echo -e "git push hub" >> post-commit | |
chmod a+x post-commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment