Skip to content

Instantly share code, notes, and snippets.

@dantoncancella
Last active August 29, 2015 14:06
Show Gist options
  • Save dantoncancella/93688927749f2aa3827d to your computer and use it in GitHub Desktop.
Save dantoncancella/93688927749f2aa3827d to your computer and use it in GitHub Desktop.
#!/bin/bash
# To enable this hook, rename this file to "post-update".
project_folder="/var/www/example"; # Folder where the project live
project_name="Example Project"; # Project name
remote_upstream="stage"; # Remote server name
upstream_branch="develop"; # Remote upstream branch name
remote_branch="$remote_upstream/$upstream_branch"; # The upstream branch on remote server
apache_user=$(pstree -p | grep -E "apache|httpd" -m1 | rev | cut -d'(' -f1 | rev | tr -d ')' | xargs ps -o user h -p); # Apache user
cd $project_folder;
echo "Updating remote servers ...";
env -i git remote update -p && echo "Remote servers updated;";
echo "Forcing checkout on $upstream_branch branch ...";
env -i git checkout --force $upstream_branch && echo "Checkout $upstream_branch branch;";
echo "Pointing $upstream_branch branch to top of $remote_branch ...";
env -i git reset --hard $remote_branch && echo "$upstream_branch branch on top of $remote_branch;";
# After this point, run the script that rebuild your application, with full path
echo "Building the $project_name ...";
env -i php $project_folder/rebuild_example.php && echo "$project_name successful build;";
# Print the success message
echo "Stage server successful updated!";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment