Last active
December 17, 2015 10:48
-
-
Save vyder/5596959 to your computer and use it in GitHub Desktop.
Script to setup publishing a website via git
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
| #!/bin/bash | |
| user=`whoami` | |
| server=`hostname` | |
| path_to_repo_dir="/var/git/" | |
| path_to_www_dir="/var/www/" | |
| project_name=$1 | |
| # Init Git repository | |
| project="$path_to_www_dir$project_name" | |
| cd $project | |
| if [ ! -d "$project/.git" ]; then | |
| git init | |
| git add . | |
| git commit -m "Automated First Commit" | |
| fi | |
| # Init bare repo | |
| repo="$path_to_repo_dir$project_name"".git" | |
| mkdir $repo | |
| cd $repo | |
| git init --bare | |
| # Auto push | |
| cd $project | |
| git push $repo master | |
| # Add bare repo as remote to project's git repo | |
| gitconfig="$project/.git/config" | |
| cat <<EOF >> $gitconfig | |
| [remote "hub"] | |
| url = $repo | |
| fetch = +refs/heads/*:refs/remotes/hub/* | |
| EOF | |
| echo "Added hub as remotes/hub" | |
| # Git Hooks | |
| ## post-update | |
| post_update_hook="$repo/hooks/post-update" | |
| cat <<EOF >> $post_update_hook | |
| #!/bin/sh | |
| echo | |
| echo "**** Pulling changes into Live [Hub's post-update hook]" | |
| echo | |
| EOF | |
| echo "cd $project || exit" >> $post_update_hook | |
| cat <<EOF >> $post_update_hook | |
| unset GIT_DIR | |
| git pull hub master | |
| exec git-update-server-info | |
| EOF | |
| chmod +x $post_update_hook | |
| ## post-commit | |
| post_commit_hook="$repo/hooks/post-commit" | |
| cat <<EOF >> $post_commit_hook | |
| #!/bin/sh | |
| echo | |
| echo "**** pushing changes to Hub [Live's post-commit hook]" | |
| echo | |
| git push hub | |
| EOF | |
| chmod +x $post_commit_hook | |
| # Instructions: | |
| echo "All done on this end!" | |
| printf "\n" | |
| echo "Command to clone this repo on your dev box:" | |
| echo " git clone $user@$server:$repo $project_name" | |
| printf "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment