Created
April 1, 2013 21:51
-
-
Save natchiketa/5288058 to your computer and use it in GitHub Desktop.
Checkout a git branch and rsync into place from a working copy on a server. Useful for a dev server, to run remotely from a dev's machine to update
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 | |
source $(dirname $0)/settings.sh | |
BRANCH="master"; | |
HELP=false; | |
while getopts b:d:th option | |
do | |
case "${option}" | |
in | |
b) BRANCH=${OPTARG};; | |
d) APP_SERVER=${OPTARG};; | |
t) TESTING=false;; | |
h) HELP=true;; | |
esac | |
done | |
if $HELP | |
then | |
echo -e "${BGreen}Options: ${Reset}" | |
echo -e "${Green} -b branchname : specify a branch on the Github repo to deploy (default is master) ${Reset}" | |
echo -e "${Green} -d directory : specify a destination host other than ${APP_SERVER} ${Reset}" | |
echo -e "${Green} -t : test mode - will not get or create git tags ${Reset}" | |
echo -e "${Green} -h : list available command line options (this page) ${Reset}" | |
echo '' | |
exit 1 | |
fi | |
PULL_CMD="cd /home/bitnami/pofdev ; git checkout ${BRANCH} ; git reset --hard HEAD; git pull" | |
RSYNC_CMD="/home/bitnami/pofdev/deploy/appsync.sh" | |
debug "$PULL_CMD" | |
debug "$RSYNC_CMD" | |
# SEND REMOTE COMMANDS TO THE APP SERVER IF NOT RUNNING THE SCRIPT FROM THERE | |
if [[ "$HERE" != "$APP_SERVER" ]] | |
then | |
echo -e "${BCyan}This doesn't look like the server, so we'll be doing a remote deployment, OK? ${Reset}" | |
read -t 10 -p "Hit ENTER or wait five seconds to proceed, or Ctrl-C to abort." | |
echo -e "${Yellow}Pulling from GitHub on the app server at ${APP_SERVER}...${Reset}" | |
ssh -t -i "$ID_FILE" bitnami@${APP_SERVER} $PULL_CMD | |
ssh -t -i "$ID_FILE" bitnami@${APP_SERVER} $RSYNC_CMD | |
# OTHERWISE, SCRIPT IS RUNNING FROM THE SERVER ITSELF, SO JUST RUN GIT AND SYNC SCRIPTS LOCALLY | |
else | |
echo -e "${IBlue} This looks like the app server, so deploying to /opt/bitnami/apps/pofpro on this machine...${Reset}" | |
read -t 10 -p "Hit ENTER or wait five seconds to proceed, or Ctrl-C to abort." | |
echo -e "${Yellow}Pulling from GitHub on the app server at ${APP_SERVER}...${Reset}" | |
cd $(dirname $0) | |
git reset --hard HEAD | |
git pull | |
$RSYNC_CMD | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment