Displays a confirmation dialogue if the user didn't explicitly
provide a valid ceph version via the `--version` flag and if
stdout is connected to a tty.

Signed-off-by: Max Carrara <m.carr...@proxmox.com>
---
 PVE/CLI/pveceph.pm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Note: This was tested in a VM, with and without --version flag.

diff --git a/PVE/CLI/pveceph.pm b/PVE/CLI/pveceph.pm
index afcc67e0..eaf7918e 100755
--- a/PVE/CLI/pveceph.pm
+++ b/PVE/CLI/pveceph.pm
@@ -157,6 +157,19 @@ __PACKAGE__->register_method ({
        } else {
            die "unsupported ceph version: $cephver";
        }
+
+       if (-t STDOUT && !$param->{version}) {
+           my $title_case_cephver = $cephver =~ s/(.)(.*?)/\U$1\L$2/r ;
+
+           print "This will install Ceph $title_case_cephver.\n" .
+               "Are you sure you want to proceed (yes/no)? ";
+
+           my $answer = <STDIN>;
+           my $valid = ($answer =~ m/^\s*yes\s*$/i) ? 1 : 0;
+
+           die "Aborting installation.\n" if !$valid;
+       }
+
        PVE::Tools::file_set_contents("/etc/apt/sources.list.d/ceph.list", 
$repolist);
 
        my $supported_re = join('|', $supported_ceph_versions->@*);
-- 
2.30.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to