arnaucube
arnaucube/configsPublic Self-hosted repository
configs/bin/ssync
bin/ssyncRaw
 1#!/usr/bin/env bash
 2#
 3# ssync = ServerSync
 4# Script to copy repo files from laptop to server or viceversa, skipping the directories .git, target and node_modules.
 5#
 6# example of usage:
 7# > ssync sf down path/to/remote/folder
 8# > ssync sf up path/to/remote/folder
 9
10SERVER=$1
11DIRECTION=$2
12REMOTE_DIR=$3
13
14if [ -z $SERVER ] ; then
15	echo "missing 1st argument (SERVER), ie. the server to connect (from the ssh config)"
16	exit 1
17fi
18
19if [ -z $DIRECTION ] ; then
20	echo "missing 2nd argument (DIRECTION), ie. uploading (u) or downloading (d)"
21	exit 1
22fi
23
24if [ -z $REMOTE_DIR ] ; then
25	echo "missing 3rd argument, the remote directory in the server (REMOTE_DIR)"
26	exit 1
27fi
28
29case $DIRECTION in
30	"up" )
31		echo "upload files to $REMOTE_DIR"
32		rsync -a -P --exclude={'.git','target','node_modules'} ./* $SERVER:~/$REMOTE_DIR/;;
33	"down" )
34		echo "download files from $REMOTE_DIR"
35		rsync -a -P --exclude={'.git','target','node_modules'} $SERVER:~/$REMOTE_DIR/ ./;;
36esac