You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
955 B

2 weeks ago
  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. SERVER=$1
  10. DIRECTION=$2
  11. REMOTE_DIR=$3
  12. if [ -z $SERVER ] ; then
  13. echo "missing 1st argument (SERVER), ie. the server to connect (from the ssh config)"
  14. exit 1
  15. fi
  16. if [ -z $DIRECTION ] ; then
  17. echo "missing 2nd argument (DIRECTION), ie. uploading (u) or downloading (d)"
  18. exit 1
  19. fi
  20. if [ -z $REMOTE_DIR ] ; then
  21. echo "missing 3rd argument, the remote directory in the server (REMOTE_DIR)"
  22. exit 1
  23. fi
  24. case $DIRECTION in
  25. "up" )
  26. echo "upload files to $REMOTE_DIR"
  27. rsync -a -P --exclude={'.git','target','node_modules'} ./* $SERVER:~/$REMOTE_DIR/;;
  28. "down" )
  29. echo "download files from $REMOTE_DIR"
  30. rsync -a -P --exclude={'.git','target','node_modules'} $SERVER:~/$REMOTE_DIR/ ./;;
  31. esac