diff --git a/bin/0km b/bin/0km index 7f92c29..8b25eeb 100755 --- a/bin/0km +++ b/bin/0km @@ -867,6 +867,10 @@ cmdline.spec::cmd:vps-setup:run() { : :posarg: HOST 'Target host to check/fix ssh-access' + : :optfla: --force,-f "Will force domain name change, even if + current hostname was not recognized as + an ovh domain name. " + depends sshpass shyaml KEY_PATH="ssh-access.public-keys" @@ -968,19 +972,22 @@ cmdline.spec::cmd:vps-setup:run() { if ! is_ovh_domain_name "$HOST" && ! str_is_ipv4 "$HOST"; then Section Checking hostname Elt "Checking /etc/hostname..." - if [ "$old" != "$HOST" ]; then - old="$(ssh:run "$host" -- $sudo_if_necessary cat /etc/hostname)" - Elt "Hostname is '$old'" - if is_ovh_hostname "$old"; then - Elt "Hostname '$old' --> '$HOST'" + old_etc_hostname="$(ssh:run "$host" -- $sudo_if_necessary cat /etc/hostname)" + if [ "$old_etc_hostname" != "$HOST" ]; then + Elt "/etc/hostname is '$old_etc_hostname'" + if is_ovh_hostname "$old_etc_hostname" || [ -n "$opt_force" ]; then + Elt "Hostname '$old_etc_hostname' --> '$HOST'" print_info "creating" echo "$HOST" | ssh:run "$host" -- $sudo_if_necessary tee /etc/hostname >/dev/null && ssh:run "$host" -- $sudo_if_necessary hostname "$HOST" Feedback || return 1 else - print_info "not changing" + Elt "Hostname '$old_etc_hostname' isn't an ovh domain" + print_info "no change" print_status noop Feed + warn "Domain name was not changed because it was already set" + echo " (use \`-f\` or \`--force\`) to force domain name change to $HOST." >&2 fi else