Last active
February 1, 2016 20:54
-
-
Save AsianChris/159227d39d972b0026b5 to your computer and use it in GitHub Desktop.
Git Repo Update
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 | |
# View Delimiter | |
DLM='-------------------------------------' | |
# Set Output Colors | |
red=`tput setaf 1` | |
green=`tput setaf 2` | |
blue=`tput setaf 4` | |
cyan=`tput setaf 6` | |
# Set config'd colors | |
color=${cyan} | |
error=${red} | |
reset=`tput sgr0` | |
# Set default branch | |
BRANCH='dev' | |
if [ ! -z "$1" ] | |
then | |
BRANCH=$1 | |
fi | |
# Function wrapper to get checksum | |
function getcksum() { | |
echo `cksum $1 | awk '{ print $1 }'` | |
} | |
# Clear screen | |
clear | |
echo "${green}Updating from UPSTREAM${reset}" | |
# Check Out $BRANCH Branch | |
echo $DLM | |
echo "${color}Checkout $BRANCH Branch${reset}" | |
git checkout $BRANCH | |
if [ $? -ne 0 ]; then | |
echo "${error}Error checking out $BRANCH branch${reset}" | |
exit 1 | |
fi | |
# Set Checksums as needed | |
if [ -f package.json ]; then | |
PACKAGE_CKSUM=$(getcksum package.json) | |
fi | |
if [ -f bower.json ]; then | |
BOWER_CKSUM=$(getcksum bower.json) | |
fi | |
if [ -f composer.json ]; then | |
COMPOSER_CKSUM=$(getcksum composer.json) | |
fi | |
# Fetch Upstream | |
echo $DLM | |
echo ${color}Fetch Upstream${reset} | |
git fetch upstream | |
if [ $? -ne 0 ]; then | |
echo "${error}Error getting upstream data${reset}" | |
exit 1 | |
fi | |
# Merge Update Stream $BRANCH to Local $BRANCH | |
echo $DLM | |
echo ${color}Merge Upstream $BRANCH${reset} | |
git merge upstream/$BRANCH | |
if [ $? -ne 0 ]; then | |
echo "${error}Error merging upstream $BRANCH branch to local${reset}" | |
exit 1 | |
fi | |
# NPM Install any new packages | |
if [ -f package.json ]; then | |
if [ ! -d node_modules ] || [ $PACKAGE_CKSUM != $(getcksum package.json) ]; then | |
echo $DLM | |
echo ${color}NPM Install${reset} | |
npm install --silent | |
if [ $? -ne 0 ]; then | |
echo "${error}Error installing NPM modules${reset}" | |
exit 1 | |
fi | |
fi | |
fi | |
# Bower install any new components | |
if [ -f bower.json ]; then | |
if [ ! -d bower_components ] || [ $BOWER_CKSUM != $(getcksum bower.json) ]; then | |
echo $DLM | |
echo ${color}Bower Install${reset} | |
bower install -q | |
if [ $? -ne 0 ]; then | |
echo "${error}Error installing Bower components${reset}" | |
exit 1 | |
fi | |
fi | |
fi | |
# Composer install any new components | |
if [ -f composer.json ]; then | |
if [ ! -d vendor ] || [ $COMPOSER_CKSUM != $(getcksum composer.json) ]; then | |
echo $DLM | |
echo ${color}Composer Install${reset} | |
composer install | |
if [ $? -ne 0 ]; then | |
echo "${error}Error installing Composer packages${reset}" | |
exit 1 | |
fi | |
fi | |
fi | |
# Push local $BRANCH to origin $BRANCH | |
echo $DLM | |
echo ${color}Push to Origin $BRANCH${reset} | |
git push origin $BRANCH | |
if [ $? -ne 0 ]; then | |
echo "${error}Error pushing $BRANCH branch to Github${reset}" | |
exit 1 | |
fi | |
# Show branches | |
echo $DLM | |
echo ${color}Branches${reset} | |
git branch | |
# END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment