#!/bin/bash
readonly PROJECT=volcano_old

readonly USAGE="
USAGE:
$(basename "$0") [UPLOAD or DOWNLOAD]"

function help_message() {
    echo "$USAGE"
}

PARAMETERS="UPLOAD DOWNLOAD upload download"

# check if there are all the parameters
if [ "$#" -ne 1 ]; then
    help_message
    exit 0
fi

# check if the systems parameter is valid
if ! echo "$PARAMETERS" | grep -w "$1" >/dev/null; then
    help_message
    exit 0
fi

# UPLOAD
if [ "$1" = upload ] || [ "$1" = UPLOAD ]; then
    printf "\n%s\n" "uploading $PROJECT"
    rsync -azmPu --delete -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT/
    rsync -azmPu -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT.all/
fi

if [ "$1" = download ] || [ "$1" = DOWNLOAD ]; then
    printf "%s\n" "downloading $PROJECT"
    rsync -azmP --delete -e 'ssh -p 4545' sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT/* .
fi