Skip to content

Instantly share code, notes, and snippets.

@hakanbaysal
Last active February 3, 2023 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakanbaysal/99688e772481c405ef8be6b696425bab to your computer and use it in GitHub Desktop.
Save hakanbaysal/99688e772481c405ef8be6b696425bab to your computer and use it in GitHub Desktop.
hosync host='YOUR_HOST' username='root' port=YOUR_PORT directory=/sites/EPA-API destination=/sites/EPA-API noignore=true debug=true
#!/bin/bash
echo "sync started..."
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
KEY_LENGTH=${#KEY}
VALUE="${ARGUMENT:$KEY_LENGTH+1}"
export "$KEY"="$VALUE"
done
if [ -z "$host" ]
then
echo "host parameter not found!"
exit
fi
if [ -z "$username" ]
then
echo "username parameter not found!"
exit
fi
if [ -z "$port" ]
then
echo "port parameter not found!"
exit
fi
dir=$(pwd)
if [ ! -z "$directory" ]
then
dir="$directory"
fi
IFS='/'
read -a pwdarr <<< "$dir"
rootDir=${pwdarr[0]}
rootDirChar=${rootDir:0:1}
if [ "$rootDirChar" != "" ];
then
dir="$(pwd)/$dir"
fi
dest="/sites/${pwdarr[${#pwdarr[*]}-1]}"
if [ ! -z "$destination" ]
then
dest="$destination"
fi
excludeStr="--exclude-from='$dir/.gitignore'"
if [ "$noignore" == "true" ];
then
excludeStr=""
fi
cmd="rsync -arvz --progress --delete $excludeStr -e 'ssh -p $port' $dir/ $username@$host:$dest"
echo "$cmd"
if [ "$debug" != "true" ];
then
eval "$cmd"
fi
echo "sync finished..."
@hakanbaysal
Copy link
Author

hakanbaysal commented Feb 3, 2023

HOSYNC

INSTALLATION

git clone https://gist.github.com/99688e772481c405ef8be6b696425bab.git hosync && chmod +x ./hosync/hosync && sudo mv ./hosync/hosync /usr/local/bin/hosync

USAGE

hosync host='YOUR_HOST' username='root' port=YOUR_PORT directory=/sites/EPA-API destination=/sites/EPA-API noignore=true debug=true

PARAMETERS

host | ❗required
Your host
example: '192.168.1.1'


username | ❗required
Your username
example: 'root'


port | ❗ required
Your port
example: 23


directory
Your directory on your computer. If this parameter is blank, it will automatically retrieve the directory it is in.
example: /sites/EPA-API


destination
Your destination on remote host. If this parameter is blank, it will automatically retrieve the directory it is in.
example: /sites/EPA-API


noignore
If the directory parameter has .gitignore, by default it will sync to the remote host without files in the .gitignore list. But if you define this parameter like "noignore=true" you will sync all files with the remote host.
example: true


debug
You can use this parameter if you want to see the command to be executed or define alias in your .zshrc|.bashrc file.
example: true

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