#!/usr/bin/env bash die() { echo "$1" exit 1 } if [ "$1" = "" ]; then echo "The first argument must be the remote containing the production configs" die "Other arguments are ignored" else REMOTE="$1" fi which rsync 1>/dev/null || die "This script needs rsync" getent hosts "${REMOTE}" 1>/dev/null || die "The remote ${REMOTE} is not resolvable" if [ ! -d /etc/wireguard/ ]; then mkdir -p /etc/wireguard/ fi RSYNC_OPTIONS="-aX" SSH_OPTIONS="-o PreferredAuthentications=publickey" rsync ${RSYNC_OPTIONS} -e "ssh ${SSH_OPTIONS}" \ ${REMOTE}:/etc/wireguard/ /etc/wireguard/ || \ die "rsync /etc/wireguard/ failed" rsync ${RSYNC_OPTIONS} -e "ssh ${SSH_OPTIONS}" \ ${REMOTE}:/etc/conf.d/net.wg* /etc/conf.d/ || \ die 'rsync /etc/conf.d/net.wg* failed' for i in /etc/conf.d/net.wg*; do # We need the file from the init.d dir INITD="${i/conf/init}" if [ ! -h ${INITD} ]; then ln -s /etc/init.d/net.lo "${INITD}" # We only need the file name rc-update add $(basename "${INITD}") rc-service $(basename "${INITD}") start fi done