Created
March 11, 2011 15:59
-
-
Save fabiocerqueira/866074 to your computer and use it in GitHub Desktop.
Simple automatic deployment in bash using: git, ssh
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 | |
# dependence: apt-get install sshpass | |
#config | |
PROJECT_NAME='pugce' | |
HOST="localhost" | |
PORT=2222 | |
BRANCH="master" | |
LOCAL_PATH='/home/fabio/sandbox/pugce/' | |
REMOTE_PATH='/home/pollux/pugce' | |
read -p "user: " USER | |
read -sp "password: " PASSWORD | |
#helpers | |
remote_cmd() { | |
CMD="$*" | |
echo $USER@$HOST: $CMD | |
sshpass -p $PASSWORD ssh -p $PORT $USER@$HOST "$CMD" | |
} | |
# deploy | |
#backup | |
REMOTE_PATH_BKP=$REMOTE_PATH.`date +%Y%m%d_%H%M%S` | |
remote_cmd mv $REMOTE_PATH $REMOTE_PATH_BKP | |
#extract git files | |
TMP_PATH=/tmp/$PROJECT_NAME.`date +%Y%m%d_%H%M%S` | |
mkdir $TMP_PATH | |
git archive $BRANCH | tar -x -C $TMP_PATH | |
#replace something with sed here | |
#copy $TMP_PATH to remote path | |
sshpass -p $PASSWORD scp -P $PORT -Cr $TMP_PATH $USER@$HOST:$REMOTE_PATH | |
#remove local copy | |
rm -Rf $TMP_PATH | |
# test it here and do automatic rollback if necessary | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment