#!/bin/bash
#
# lib/lvpn-push
#
# Copyright (c) 2011-2013 LibreVPN <vpn@hackcoop.com.ar>
#
# See AUTHORS for a list of contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General
# Public License along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
#
#
# Sincroniza los nodos de un nodo remoto o local
# Necesita acceso SSH, pensado para sincronizar nodos en un router con *WRT
# No usamos rsync porque no existe

. "${LVPN_LIBDIR}"/common

requires ssh scp

while getopts "dh" arg; do
    case $arg in
        h) help ${self} ; exit 0;;
    esac
done
let OPTIND--; shift ${OPTIND}

# Setear las opciones
node="$(get_node_name "$1")"; shift
host="$1"; shift
dir="$1"; shift

nodedir="$(get_node_dir ${node})"

# Crear el directorio
ssh ${host} mkdir -p "${dir:-${TINC}}/"
# Usamos un scp normal porque probablemente no haya rsync del otro lado
# scp normalmente pisa todos los archivos
scp -r "${nodedir}" ${host}:"${dir:-${TINC}}/"

exit $?
