From d9674acff0e99fcd06f1d0619a0401bf95a6c36e Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Mon, 29 Apr 2024 16:29:44 +0200 Subject: [PATCH] evobackupctl: add "--init-jail-commands" --- client/bin/evobackupctl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/client/bin/evobackupctl b/client/bin/evobackupctl index b0b4e0c..3cd55ea 100644 --- a/client/bin/evobackupctl +++ b/client/bin/evobackupctl @@ -31,10 +31,39 @@ ${PROGNAME} helps managing evobackup scripts Options -h, --help print this message and exit -V, --version print version and exit + --init-jail-commands print jail init commands --copy-template=PATH copy the backup template to PATH END } +init_jail_commands() { + if [ ! -f /root/.ssh/id_ed25519.pub ]; then + ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -N '' + echo "" + fi + + SSH_KEY=$(cat /root/.ssh/id_ed25519.pub) + SERVER_NAME=$(hostname -s) + if [ "$(uname -s)" = "OpenBSD" ]; then + SERVER_IP=$(ifconfig egress | grep "inet " | head -1 | awk '{ print $2}') + else + SERVER_IP=$(curl -4 https://ifconfig.me 2> /dev/null || hostname -I | awk '{ print $1}') + fi + + echo "Copy-paste those lines on backup server(s) :" + echo "----------" + echo "SERVER_NAME=${SERVER_NAME}" + echo "SERVER_IP=${SERVER_IP}" + echo "echo '${SSH_KEY}' > /root/\${SERVER_NAME}.pub" + echo "bkctld init \${SERVER_NAME}" + echo "bkctld key \${SERVER_NAME} /root/\${SERVER_NAME}.pub" + echo "bkctld ip \${SERVER_NAME} \${SERVER_IP}" + echo "bkctld start \${SERVER_NAME}" + echo "bkctld status \${SERVER_NAME}" + echo "grep --quiet --extended-regexp \"^\\s?NODE=\" /etc/default/bkctld && bkctld sync \${SERVER_NAME}" + echo "----------" +} + copy_template() { dest_path=${1} dest_dir="$(dirname "${dest_path}")" @@ -78,6 +107,10 @@ main() { show_help exit 0 ;; + --init-jail-commands) + init_jail_commands + exit 0 + ;; --copy-template) # copy-template option, with value separated by space if [ -n "$2" ]; then