From 9a2dbceeed62d69419e6c12706fe87a8d108eb61 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 29 Apr 2021 08:43:58 +0200 Subject: [PATCH] new: [vps] allow usage of ``backup-*`` options on ``install backup`` Also, ``--ignore-ping-check`` is also available on the ``mailcow`` side as the check was also added. Signed-off-by: Valentin Lab --- bin/vps | 57 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/bin/vps b/bin/vps index d7b7f91..8a97d92 100755 --- a/bin/vps +++ b/bin/vps @@ -171,9 +171,28 @@ wrap() { } +ping_check() { + #global ignore_ping_check + local host="$1" + + ip=$(getent ahosts "$host" | egrep "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s+" | + head -n 1 | cut -f 1 -d " ") || return 1 + + my_ip=$(curl -s myip.kal.fr) + if [ "$ip" != "$my_ip" ]; then + if [ -n "$ignore_ping_check" ]; then + warn "IP of '$host' ($ip) doesn't match mine ($my_ip). Ignoring due to ``--ignore-ping-check`` option." + else + err "IP of '$host' ($ip) doesn't match mine ($my_ip). Use ``--ignore-ping-check`` to ignore check." + return 1 + fi + fi +} + + mailcow:install-backup() { - local BACKUP_SERVER="$1" mailcow_root DOMAIN + local BACKUP_SERVER="$1" ignore_ping_check="$2" mailcow_root DOMAIN ## find installation mailcow_root=$(mailcow:get-root) || { @@ -189,6 +208,7 @@ mailcow:install-backup() { return 1 } + ping_check "$DOMAIN" || return 1 MYSQL_ROOT_PASSWORD=$(cat "$mailcow_root/.env" | grep ^DBROOT= | cut -f 2 -d =) || { err "Couldn't find DBROOT in file \"$mailcow_root/.env\"." @@ -287,18 +307,7 @@ compose:install-backup() { fi fi - ip=$(getent ahosts "$host" | egrep "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s+" | - head -n 1 | cut -f 1 -d " ") || return 1 - - my_ip=$(curl -s myip.kal.fr) - if [ "$ip" != "$my_ip" ]; then - if [ -n "$ignore_ping_check" ]; then - warn "IP of '$host' ($ip) doesn't match mine ($my_ip). Ignoring due to ``--ignore-ping-check`` option." - else - err "IP of '$host' ($ip) doesn't match mine ($my_ip). Use ``--ignore-ping-check`` to ignore check." - return 1 - fi - fi + ping_check "$DOMAIN" || return 1 if [ -e "/root/.ssh/rsync_rsa" ]; then warn "deleting private key in /root/.ssh/rsync_rsa, has we are not using it anymore." @@ -386,6 +395,12 @@ cmdline.spec:install:cmd:backup:run() { : :posarg: BACKUP_SERVER 'Target backup server' + : :optfla: --ignore-domain-check \ + "Allow to bypass the domain check in + compose file (only used in compose + installation)." + : :optfla: --ignore-ping-check "Allow to bypass the ping check of host." + local vps_type vps_type=$(vps:get-type) || { @@ -397,7 +412,17 @@ cmdline.spec:install:cmd:backup:run() { return 1 fi - "cmdline.spec:install:cmd:$vps_type-backup:run" "$BACKUP_SERVER" + opts=() + + [ "$opt_ignore_ping_check" ] && + opts+=("--ignore-ping-check") + + if [ "$vps_type" == "compose" ]; then + [ "$opt_ignore_domain_check" ] && + opts+=("--ignore-domain-check") + fi + + "cmdline.spec:install:cmd:${vps_type}-backup:run" "${opts[@]}" "$BACKUP_SERVER" } @@ -442,7 +467,9 @@ cmdline.spec:install:cmd:mailcow-backup:run() { : :posarg: BACKUP_SERVER 'Target backup server' - "mailcow:install-backup" "$BACKUP_SERVER" + : :optfla: --ignore-ping-check "Allow to bypass the ping check of host." + + "mailcow:install-backup" "$BACKUP_SERVER" "$opt_ignore_ping_check" }