#!/bin/bash

source /opt/scripts_local/shared_functions.sh

HOSTNAME=$(hostname)
export RCLONE_CONFIG=/opt/rclone/rclone.conf
# Create & config folders
sudo mkdir -p /opt/rclone \
/mnt/rclone_mount/rclone_{vmx-nas,vmx-load} \
/mnt/unionfs \
/rclone_cache \
/var/log/rclone
sudo chown root:sysadmin /opt/rclone \
/mnt/rclone_mount/rclone_{vmx-nas,vmx-load} \
/mnt/unionfs \
/rclone_cache \
/var/log/rclone
sudo chmod 770 /opt/rclone \
/mnt/rclone_mount/rclone_{vmx-nas,vmx-load} \
/mnt/unionfs \
/rclone_cache \
/var/log/rclone
# Copy config from vmx-nas
if [ "$HOSTNAME" == "vmx-nas" ]; then
  sudo rsync -avP /mnt/unionfs/shared/rclone/rclone.conf /opt/rclone/
else
  sudo rsync -avP -e "ssh -o StrictHostKeyChecking=no" root@vmx-nas.swallow-grue.ts.net:/mnt/unionfs/shared/rclone/rclone.conf /opt/rclone/
fi