jean-cloud-services/services/backup-borg-client/deploy.sh
Adrian Amaglio 66e0e9a4da leftovers
2024-02-22 01:44:24 +01:00

27 lines
785 B
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -euo pipefail
pubkeyfile="/root/.ssh/authorized_keys"
separator="# backup-borg-begin DO NOT EDIT UNDER THIS LINE"
mkdir -p "$DATA_DIR/pubkeys" "$DATA_DIR/.ssh"
# Create ssh key if not found
if [ ! -e "$DATA_DIR/.ssh/borg-client" ] ; then
ssh-keygen -f "$DATA_DIR/.ssh/borg-client" -C "SSH key for backup trigger" -P ''
fi
# Remove separator and automated lines if found
if [ -n "$(grep "$separator" "$pubkeyfile")" ] ; then
sed -i "/$separator/,//d" "$pubkeyfile"
fi
# Place separator back
echo "$separator" >> "$pubkeyfile"
# Foreach borg server key
while read serverkey ; do
# Add authorized_keys line
echo "command=\"$DOCKER_DIR/script-sauvegarde.sh $serverkey\" $(cat "$DATA_DIR/pubkeys/$serverkey")" >> "$pubkeyfile"
done < <(ls "$DATA_DIR/pubkeys")