Verified Commit 20bde6f9 authored by Silvio Rhatto's avatar Silvio Rhatto
Browse files

Feat: adds sync-from-remotes (Closes #19)

parent 55af2cf1
Loading
Loading
Loading
Loading

bin/sync-from-remotes

0 → 100755
+50 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash
#
# Sync Onionmine to remote servers.
#
# Copyright (C) 2022 Silvio Rhatto <rhatto@torproject.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or 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 General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Parameters
BASENAME="`basename $0`"
DIRNAME="`dirname $0`"
source $DIRNAME/params

# Check
if [ -z "$REMOTE_HOSTS_RSYNC" ] || [ "$REMOTE_HOSTS_RSYNC" == 0 ]; then
  echo "$BASENAME: please enable REMOTE_HOSTS_RSYNC at onionmine.conf"
  exit 1
fi

# Check remotes
if [ -z "$REMOTE_HOSTS" ]; then
  echo "$BASENAME: need to configure REMOTE_HOSTS parameter"
  exit 1
fi

# Check base dir
if [ -z "$REMOTE_HOSTS_BASEDIR" ]; then
  echo "$BASENAME: need to configure REMOTE_HOSTS_BASEDIR parameter"
  exit 1
fi

# Iterate over all defined hosts
for host in $REMOTE_HOSTS; do
  if [ ! -z "$REMOTE_HOSTS_RSYNC" ] && [ "$REMOTE_HOSTS_RSYNC" != 0 ]; then
    # Sync the pools
    $REMOTE_HOSTS_RSYNC_COMMAND $RSYNC_EXCLUDES $host:$REMOTE_HOSTS_BASEDIR/pools/ $BASEDIR/pools/
  fi
done