Last active
February 3, 2023 21:29
-
-
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
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 | |
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..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HOSYNC
INSTALLATION
USAGE
PARAMETERS