Skip to content

Instantly share code, notes, and snippets.

@11808s8
Last active February 18, 2020 20:41
Show Gist options
  • Select an option

  • Save 11808s8/dc1ac5625f1d73b62a7f7318f3cf02d8 to your computer and use it in GitHub Desktop.

Select an option

Save 11808s8/dc1ac5625f1d73b62a7f7318f3cf02d8 to your computer and use it in GitHub Desktop.
Base BashScript for updating a remote project using RSYNC and a local git repo. It also verifies if your local GIT REPO is up to date.
#!/bin/bash
# Base script for remote project updating
#
# What it does?
# - Make a versioning folder, if you don't have one
# - Create a .txt file in the specified versioning folder with the current git HEAD
# that will be uploaded to the remote server
# - uses rsync to connect to the remote and update the files there
#
# Version 1.0.0
# author: Adriano Gomes da Silva <[email protected]>
usage() {
cat <<EOM
Usage:
$(basename $0) VERSIONING_FOLDER PROJECT_FOLDER DESTINY_FOLDER SSH_USER SSH_IP SSH_PORT PROJECT_NAME
EOM
}
clear
if [ "$#" -ne 7 ]
then
usage
exit 1
fi
_VERSIONING_FOLDER="$( getent passwd "$USER" | cut -d: -f6 )/${1}"
if [ ! -d "$_VERSIONING_FOLDER" ]
then
echo "Versioning doesn't exist! Creating it..."
mkdir $_VERSIONING_FOLDER
echo "Versioning folder created!"
fi
_PROJECT_FOLDER="${2}"
_PROJECT_DESTINY_FOLDER="${3}"
_USER="${4}"
_IP="${5}"
_PORT="${6}"
. localgitupdate.sh $_PROJECT_FOLDER
cd $_PROJECT_FOLDER
_FILENAME="${7##*/}"
git rev-parse HEAD > $_VERSIONING_FOLDER/committed_version_$_FILENAME.txt
rsync -Cravzp --del --exclude 'templates_c' --exclude 'nbproject' --exclude '.htaccess' $_PROJECT_FOLDER* $_USER@$_IP:$_PROJECT_DESTINY_FOLDER --rsh='ssh -p$_PORT'
echo "Project update was succesful!"
@11808s8
Copy link
Author

11808s8 commented Feb 18, 2020

Depends on the existence of this gist in the same folder of this script to run 100%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment