all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 2/2] bin: auto-format code using perltidy with Proxmox style guide
Date: Mon,  7 Jul 2025 13:01:37 +0200	[thread overview]
Message-ID: <20250707110146.800467-3-c.heiss@proxmox.com> (raw)
In-Reply-To: <20250707110146.800467-1-c.heiss@proxmox.com>

Done using `make -C bin tidy`.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 bin/pve-init-ceph-crash | 127 +++++++++++++-------------
 bin/pvebanner           |   2 +-
 bin/pvedaemon           |   2 +-
 bin/pveperf             | 198 ++++++++++++++++++++--------------------
 bin/pveproxy            |  10 +-
 bin/pvereport           |   2 +-
 bin/pveupdate           | 118 +++++++++++++-----------
 bin/pveupgrade          |  36 ++++----
 bin/pveversion          |  37 ++++----
 bin/spiceproxy          |  12 +--
 10 files changed, 275 insertions(+), 269 deletions(-)

diff --git a/bin/pve-init-ceph-crash b/bin/pve-init-ceph-crash
index 4ec95a2de..d25201d98 100755
--- a/bin/pve-init-ceph-crash
+++ b/bin/pve-init-ceph-crash
@@ -13,7 +13,6 @@ use PVE::RPCEnvironment;
 my $ceph_cfg_file = 'ceph.conf';
 my $keyring_value = '/etc/pve/ceph/$cluster.$name.keyring';
 
-
 sub try_adapt_cfg {
     my ($cfg) = @_;
 
@@ -23,39 +22,38 @@ sub try_adapt_cfg {
     print("Checking whether the configuration for '$entity' needs to be updated.\n");
 
     my $add_keyring = sub {
-	print("Setting keyring path to '$keyring_value'.\n");
-	$cfg->{$entity}->{keyring} = $keyring_value;
+        print("Setting keyring path to '$keyring_value'.\n");
+        $cfg->{$entity}->{keyring} = $keyring_value;
     };
 
     if (!exists($cfg->{$entity})) {
-	print("Adding missing section for '$entity'.\n");
-	$add_keyring->();
-	return 1;
+        print("Adding missing section for '$entity'.\n");
+        $add_keyring->();
+        return 1;
     }
 
     if (exists($cfg->{$entity}->{key})) {
-	print("Removing existing usage of key.\n");
-	delete($cfg->{$entity}->{key});
-	$removed_key = 1;
+        print("Removing existing usage of key.\n");
+        delete($cfg->{$entity}->{key});
+        $removed_key = 1;
     }
 
     if (!exists($cfg->{$entity}->{keyring})) {
-	print("Keyring path is missing from configuration.\n");
-	$add_keyring->();
-	return 1;
+        print("Keyring path is missing from configuration.\n");
+        $add_keyring->();
+        return 1;
     }
 
     my $current_keyring_value = $cfg->{$entity}->{keyring};
     if ($current_keyring_value ne $keyring_value) {
-	print("Current keyring path differs from expected path.\n");
-	$add_keyring->();
-	return 1;
+        print("Current keyring path differs from expected path.\n");
+        $add_keyring->();
+        return 1;
     }
 
     return $removed_key;
 }
 
-
 sub main {
     # PVE::RADOS expects an active RPC Environment because it forks itself
     # and may want to clean up after
@@ -68,15 +66,13 @@ sub main {
 
     my $ceph_cfg_path = PVE::Ceph::Tools::get_config('pve_ceph_cfgpath');
     if (PVE::Ceph::Tools::check_ceph_installed('ceph_mon', 1) && -f $ceph_cfg_path) {
-	my $pve_ceph_cfgdir = PVE::Ceph::Tools::get_config('pve_ceph_cfgdir');
-	if (! -d $pve_ceph_cfgdir) {
-	    File::Path::make_path($pve_ceph_cfgdir);
-	}
+        my $pve_ceph_cfgdir = PVE::Ceph::Tools::get_config('pve_ceph_cfgdir');
+        if (!-d $pve_ceph_cfgdir) {
+            File::Path::make_path($pve_ceph_cfgdir);
+        }
     }
 
-    eval {
-        PVE::Ceph::Tools::check_ceph_inited();
-    };
+    eval { PVE::Ceph::Tools::check_ceph_inited(); };
     if ($@) {
         print("Ceph is not initialized. No action required.\n");
         exit 0;
@@ -87,44 +83,49 @@ sub main {
 
     my $inner_err = '';
 
-    my $rval = PVE::Cluster::cfs_lock_file($ceph_cfg_file, undef, sub {
-	eval {
-	    my $cfg = PVE::Cluster::cfs_read_file($ceph_cfg_file);
+    my $rval = PVE::Cluster::cfs_lock_file(
+        $ceph_cfg_file,
+        undef,
+        sub {
+            eval {
+                my $cfg = PVE::Cluster::cfs_read_file($ceph_cfg_file);
 
-	    if (!defined($rados)) {
-		my $has_mon_host = defined($cfg->{global}) && defined($cfg->{global}->{mon_host});
-		if ($has_mon_host && $cfg->{global}->{mon_host} ne '') {
-		    die "Connection to RADOS failed even though a monitor is configured.\n" .
-			"Please verify whether your configuration in '$ceph_cfg_file' is correct.\n"
-		}
+                if (!defined($rados)) {
+                    my $has_mon_host =
+                        defined($cfg->{global}) && defined($cfg->{global}->{mon_host});
+                    if ($has_mon_host && $cfg->{global}->{mon_host} ne '') {
+                        die "Connection to RADOS failed even though a monitor is configured.\n"
+                            . "Please verify whether your configuration in '$ceph_cfg_file' is correct.\n";
+                    }
 
-		print(
-		    "Connection to RADOS failed and no monitor is configured in '$ceph_cfg_file'.\n".
-		    "Assuming that things are fine. No action required.\n"
-		);
-		return;
-	    }
+                    print(
+                        "Connection to RADOS failed and no monitor is configured in '$ceph_cfg_file'.\n"
+                            . "Assuming that things are fine. No action required.\n");
+                    return;
+                }
 
-	    my $updated_keyring = PVE::Ceph::Tools::create_or_update_crash_keyring_file($rados);
+                my $updated_keyring =
+                    PVE::Ceph::Tools::create_or_update_crash_keyring_file($rados);
 
-	    if ($updated_keyring) {
-		print("Keyring file '$ceph_crash_key_path' was updated.\n");
-	    }
+                if ($updated_keyring) {
+                    print("Keyring file '$ceph_crash_key_path' was updated.\n");
+                }
 
-	    my $changed = try_adapt_cfg($cfg);
+                my $changed = try_adapt_cfg($cfg);
 
-	    if ($changed) {
-		print("Committing updated configuration to '$ceph_cfg_file'.\n");
-		PVE::Cluster::cfs_write_file($ceph_cfg_file, $cfg);
-		print("Successfully updated configuration for 'ceph-crash.service'.\n");
-	    } else {
-		print("Configuration in '$ceph_cfg_file' does not need to be updated.\n");
-	    }
-	};
-	$inner_err = $@;
+                if ($changed) {
+                    print("Committing updated configuration to '$ceph_cfg_file'.\n");
+                    PVE::Cluster::cfs_write_file($ceph_cfg_file, $cfg);
+                    print("Successfully updated configuration for 'ceph-crash.service'.\n");
+                } else {
+                    print("Configuration in '$ceph_cfg_file' does not need to be updated.\n");
+                }
+            };
+            $inner_err = $@;
 
-	return 1;
-    });
+            return 1;
+        },
+    );
 
     # cfs_lock_file sets $@ explicitly to undef
     my $err = $@ // '';
@@ -132,18 +133,18 @@ sub main {
     my $has_err = !defined($rval) || $inner_err || $err;
 
     if ($has_err) {
-	$err =~ s/\n*$//;
-	$inner_err =~ s/\n*$//;
+        $err =~ s/\n*$//;
+        $inner_err =~ s/\n*$//;
 
-	if (!defined($rval)) {
-	    warn("Error while acquiring or releasing lock for '$ceph_cfg_file'.\n");
-	    warn("Error: $err\n") if $err ne '';
-	}
+        if (!defined($rval)) {
+            warn("Error while acquiring or releasing lock for '$ceph_cfg_file'.\n");
+            warn("Error: $err\n") if $err ne '';
+        }
 
-	warn("Failed to configure keyring for 'ceph-crash.service'.\nError: $inner_err\n")
-	    if $inner_err ne '';
+        warn("Failed to configure keyring for 'ceph-crash.service'.\nError: $inner_err\n")
+            if $inner_err ne '';
 
-	exit 1;
+        exit 1;
     }
 }
 
diff --git a/bin/pvebanner b/bin/pvebanner
index cd5b763a8..7e8526101 100755
--- a/bin/pvebanner
+++ b/bin/pvebanner
@@ -33,4 +33,4 @@ print ISSUE $banner;
 
 close(ISSUE);
 
-exit (0);
+exit(0);
diff --git a/bin/pvedaemon b/bin/pvedaemon
index ffccb34fb..c45cba675 100755
--- a/bin/pvedaemon
+++ b/bin/pvedaemon
@@ -2,7 +2,7 @@
 
 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
 
-delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};  
+delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
 
 use strict;
 use warnings;
diff --git a/bin/pveperf b/bin/pveperf
index 0b84e7035..39b020e05 100755
--- a/bin/pveperf
+++ b/bin/pveperf
@@ -18,22 +18,22 @@ my $path = $ARGV[0] || '/';
 sub drop_cache {
     # free pagecache,dentries,inode cache
     if (-f '/proc/sys/vm/drop_caches') {
-	system ("echo 3 > /proc/sys/vm/drop_caches");
+        system("echo 3 > /proc/sys/vm/drop_caches");
     }
 }
 
 sub test_bogomips {
     my $bogomips = 0;
 
-    open (TMP, "/proc/cpuinfo");
+    open(TMP, "/proc/cpuinfo");
 
     while (my $line = <TMP>) {
-	if ($line =~ m/^bogomips\s*:\s*(\d+\.\d+)\s*$/) {
-	    $bogomips += $1;
-	}
+        if ($line =~ m/^bogomips\s*:\s*(\d+\.\d+)\s*$/) {
+            $bogomips += $1;
+        }
     }
 
-    close (TMP);
+    close(TMP);
 
     printf "CPU BOGOMIPS:      %.2f\n", $bogomips;
 }
@@ -47,12 +47,12 @@ sub test_regex {
 
     for (;; $count++) {
 
-	my $str = int(rand(1000000)) . time();
-	if ($str =~ m/(.+)123.?123/) {
-	}
-	$elapsed = tv_interval ($starttime);
-	
-	last if $elapsed > 3;
+        my $str = int(rand(1000000)) . time();
+        if ($str =~ m/(.+)123.?123/) {
+        }
+        $elapsed = tv_interval($starttime);
+
+        last if $elapsed > 3;
     }
 
     printf "REGEX/SECOND:      %d\n", $count;
@@ -61,45 +61,45 @@ sub test_regex {
 sub test_fsync {
     my $basedir = shift;
 
-    drop_cache ();
+    drop_cache();
 
     my $dir = "$basedir/ptest.$$";
 
     eval {
-	mkdir $dir;
+        mkdir $dir;
 
-	my $data = ('A' x 4000) . "\n";
+        my $data = ('A' x 4000) . "\n";
 
-	my $starttime = [gettimeofday];
+        my $starttime = [gettimeofday];
 
-	my $count;
-	my $elapsed = 0;
+        my $count;
+        my $elapsed = 0;
 
-	for ($count=1;;$count++) {
-	    my $m = $count % 300;
+        for ($count = 1;; $count++) {
+            my $m = $count % 300;
 
-	    my $filename = "$dir/tf_$m.dat";
+            my $filename = "$dir/tf_$m.dat";
 
-	    open (TMP, ">$filename") || die "open failed: $!\n";
- 
-	    print TMP $data;
+            open(TMP, ">$filename") || die "open failed: $!\n";
 
-	    PVE::Tools::fsync(fileno(\*TMP));
+            print TMP $data;
 
-	    close (TMP);
+            PVE::Tools::fsync(fileno(\*TMP));
 
-	    $elapsed = tv_interval ($starttime);
+            close(TMP);
 
-	    last if $elapsed > 3;
-	}
-	my $sps = $count /$elapsed; # fsync per second
+            $elapsed = tv_interval($starttime);
 
-	printf "FSYNCS/SECOND:     %.2f\n", $sps;
+            last if $elapsed > 3;
+        }
+        my $sps = $count / $elapsed; # fsync per second
+
+        printf "FSYNCS/SECOND:     %.2f\n", $sps;
     };
 
     my $err = $@;
 
-    system ("rm -rf $dir");
+    system("rm -rf $dir");
 
     die $err if $err;
 }
@@ -107,73 +107,72 @@ sub test_fsync {
 sub test_seektime {
     my ($rootdev, $hdsize) = @_;
 
-    drop_cache ();
+    drop_cache();
 
-    open (ROOTHD, "<$rootdev") || die "unable to open HD '$rootdev': $!\n";
+    open(ROOTHD, "<$rootdev") || die "unable to open HD '$rootdev': $!\n";
 
     my $starttime = [gettimeofday];
     my $count;
     my $elapsed = 0;
     my $readbuf;
 
-    for ($count=1;;$count++) {
+    for ($count = 1;; $count++) {
 
-	my $pos = int (rand (int($hdsize/512))) * 512;
+        my $pos = int(rand(int($hdsize / 512))) * 512;
 
-	sysseek (ROOTHD, $pos, 0);
+        sysseek(ROOTHD, $pos, 0);
 
-	(sysread (ROOTHD, $readbuf, 512) == 512) || die "read failed: $!\n";
+        (sysread(ROOTHD, $readbuf, 512) == 512) || die "read failed: $!\n";
 
-	$elapsed = tv_interval ($starttime);
-	
-	last if $elapsed > 3;
+        $elapsed = tv_interval($starttime);
+
+        last if $elapsed > 3;
     }
 
-    close (ROOTHD);
+    close(ROOTHD);
 
-    my $rps = $count /$elapsed; # blocks per second
-    my $ast = (1000/$rps);
+    my $rps = $count / $elapsed; # blocks per second
+    my $ast = (1000 / $rps);
     printf "AVERAGE SEEK TIME: %.2f ms\n", $ast;
 }
 
 sub test_read {
     my $rootdev = shift;
 
-    drop_cache ();
+    drop_cache();
 
     my $starttime = [gettimeofday];
     my $bytes = 0;
     my $elapsed = 0;
     my $readbuf;
 
-
-    open (ROOTHD, "<$rootdev") || die "unable to open HD '$rootdev': $!\n";
+    open(ROOTHD, "<$rootdev") || die "unable to open HD '$rootdev': $!\n";
 
     for (;;) {
-	my $c = sysread (ROOTHD, $readbuf, 2 * 1024 *1024);
-	die "read failed: $!\n" if $c < 0;
+        my $c = sysread(ROOTHD, $readbuf, 2 * 1024 * 1024);
+        die "read failed: $!\n" if $c < 0;
 
-	$bytes += $c;
+        $bytes += $c;
 
-	$elapsed = tv_interval ($starttime);
-	last if $elapsed > 3;
+        $elapsed = tv_interval($starttime);
+        last if $elapsed > 3;
     }
 
-    close (ROOTHD);
+    close(ROOTHD);
 
-    my $bps = $bytes /($elapsed * 1024 * 1024); # MB per second
+    my $bps = $bytes / ($elapsed * 1024 * 1024); # MB per second
     printf "BUFFERED READS:    %.2f MB/sec\n", $bps;
 }
 
 sub get_address {
     my ($resolv, $dns) = @_;
 
-    if (my $a = $resolv->send ($dns, 'A')) {
-	foreach my $rra ($a->answer) {
-	    if ($rra->type eq 'A') {
-		return $rra->address;
-	    }
-	}
+    if (my $a = $resolv->send($dns, 'A')) {
+        foreach my $rra ($a->answer) {
+            if ($rra->type eq 'A') {
+                return $rra->address;
+            }
+        }
     }
 
     return undef;
@@ -182,19 +181,19 @@ sub get_address {
 sub test_dns {
 
     my %dnsargs = (
-		   tcp_timeout => 10,
-		   udp_timeout => 10,
-		   retry => 1,
-		   retrans => 0,
-		   dnsrch => 0,
-		   defnames => 0,
-		   debug => 0,
-		   );
+        tcp_timeout => 10,
+        udp_timeout => 10,
+        retry => 1,
+        retrans => 0,
+        dnsrch => 0,
+        defnames => 0,
+        debug => 0,
+    );
 
     #$dnsargs{nameservers} = [ qw (208.67.222.222) ];
     #$dnsargs{nameservers} = [ qw (127.0.0.1) ];
 
-    my $resolv = Net::DNS::Resolver->new (%dnsargs);
+    my $resolv = Net::DNS::Resolver->new(%dnsargs);
 
     my $starttime = [gettimeofday];
 
@@ -204,62 +203,61 @@ sub test_dns {
     my $uid = time() . int(rand(1000000));
     my $domain = "nonexistent$uid.com";
 
-    for ($count=1;;$count++) {
+    for ($count = 1;; $count++) {
 
-	my $hid = int(rand(1000000));
-	my $hname = "test${hid}.$domain";
-	get_address ($resolv, $hname);
-	$elapsed = tv_interval ($starttime);
-	
-	last if ($count > 100) || ($elapsed > 3);
+        my $hid = int(rand(1000000));
+        my $hname = "test${hid}.$domain";
+        get_address($resolv, $hname);
+        $elapsed = tv_interval($starttime);
+
+        last if ($count > 100) || ($elapsed > 3);
     }
 
-    printf "DNS EXT:           %0.2f ms\n", ($elapsed * 1000)/$count;
+    printf "DNS EXT:           %0.2f ms\n", ($elapsed * 1000) / $count;
 
     my $resolv_conf = `cat /etc/resolv.conf`;
     ($domain) = $resolv_conf =~ m/^search\s+(\S+)\s*$/mg;
 
     if ($domain) {
-	$starttime = [gettimeofday];
-	$elapsed = 0;
+        $starttime = [gettimeofday];
+        $elapsed = 0;
 
-	for ($count=1;;$count++) {
+        for ($count = 1;; $count++) {
 
-	    my $hid = int(rand(1000000));
-	    my $hname = "test${hid}.$domain";
-	    get_address ($resolv, $hname);
-	    $elapsed = tv_interval ($starttime);
-	
-	    last if ($count > 100) || ($elapsed > 3);
-	}
+            my $hid = int(rand(1000000));
+            my $hname = "test${hid}.$domain";
+            get_address($resolv, $hname);
+            $elapsed = tv_interval($starttime);
 
-	printf "DNS INT:           %0.2f ms (%s)\n", 
-	($elapsed * 1000)/ $count, $domain;
+            last if ($count > 100) || ($elapsed > 3);
+        }
+
+        printf "DNS INT:           %0.2f ms (%s)\n", ($elapsed * 1000) / $count, $domain;
     }
 }
 
-test_bogomips ();
-test_regex ();
+test_bogomips();
+test_regex();
 
 my $hd = `df -P '$path'`;
 
-my ($rootdev, $hdo_total, $hdo_used, $hdo_avail) = $hd =~
-    m/^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+\S+\s+.*$/mg;
+my ($rootdev, $hdo_total, $hdo_used, $hdo_avail) =
+    $hd =~ m/^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+\S+\s+.*$/mg;
 
 if ($rootdev) {
-    my $hdsize = $hdo_total*1024;
-    printf "HD SIZE:           %.2f GB ($rootdev)\n", ($hdsize / (1024*1024*1024));
+    my $hdsize = $hdo_total * 1024;
+    printf "HD SIZE:           %.2f GB ($rootdev)\n", ($hdsize / (1024 * 1024 * 1024));
 
     if ($rootdev =~ m|^/dev/|) {
-	test_read ($rootdev);
+        test_read($rootdev);
 
-	test_seektime ($rootdev, $hdsize);
+        test_seektime($rootdev, $hdsize);
 
     }
 }
 
-test_fsync ($path) if $hdo_avail;
+test_fsync($path) if $hdo_avail;
 
-test_dns ();
+test_dns();
 
-exit (0);
+exit(0);
diff --git a/bin/pveproxy b/bin/pveproxy
index 20e8f2ab2..4fb5bb2e4 100755
--- a/bin/pveproxy
+++ b/bin/pveproxy
@@ -2,7 +2,7 @@
 
 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
 
-delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};  
+delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
 
 use strict;
 use warnings;
@@ -20,11 +20,11 @@ $SIG{'__WARN__'} = sub {
 };
 
 my $prepare = sub {
-    my $rundir="/var/run/pveproxy";
+    my $rundir = "/var/run/pveproxy";
     if (mkdir($rundir, 0700)) { # only works at first start if we are root)
-	my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
-	my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
-	chown($uid, $gid, $rundir);
+        my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
+        my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
+        chown($uid, $gid, $rundir);
     }
 };
 
diff --git a/bin/pvereport b/bin/pvereport
index 990fc876f..8658a0424 100755
--- a/bin/pvereport
+++ b/bin/pvereport
@@ -5,7 +5,7 @@ use warnings;
 
 use PVE::Report;
 
-($> == 0 ) || die "please run as root\n";
+($> == 0) || die "please run as root\n";
 
 print PVE::Report::generate();
 
diff --git a/bin/pveupdate b/bin/pveupdate
index a2a2abbc4..757cac868 100755
--- a/bin/pveupdate
+++ b/bin/pveupdate
@@ -23,7 +23,7 @@ use PVE::API2::ACME;
 use PVE::API2::APT;
 use PVE::API2::Subscription;
 
-initlog ('pveupdate', 'daemon');
+initlog('pveupdate', 'daemon');
 
 die "please run as root\n" if $> != 0;
 
@@ -41,13 +41,13 @@ my $nodename = PVE::INotify::nodename();
 
 eval { PVE::API2::Subscription->update({ node => $nodename }); };
 if (my $err = $@) {
-    syslog ('err', "update subscription info failed: $err");
+    syslog('err', "update subscription info failed: $err");
 }
 
 my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg');
 eval { PVE::APLInfo::update($dccfg->{http_proxy}); };
 if (my $err = $@) {
-    syslog ('err', "update appliance info failed - see /var/log/pveam.log for details");
+    syslog('err', "update appliance info failed - see /var/log/pveam.log for details");
 }
 
 my $info = eval { PVE::API2::Subscription::read_etc_subscription() };
@@ -66,65 +66,73 @@ if ($notify_on eq 'auto') {
 }
 eval { PVE::API2::APT->update_database({ node => $nodename, notify => $notify, quiet => 1 }); };
 if (my $err = $@) {
-    syslog ('err', "update apt database failed: $err");
+    syslog('err', "update apt database failed: $err");
 }
 
 eval {
     my $node_config = PVE::NodeConfig::load_config($nodename);
     my $acme_node_config = PVE::NodeConfig::get_acme_conf($node_config);
     if ($acme_node_config && $acme_node_config->{domains}) {
-	my $cert = PVE::CertHelpers::cert_path_prefix($nodename).".pem";
-	if (-e $cert) {
-	    if (PVE::Certificate::check_expiry($cert, time() + 30*24*60*60)) {
-		PVE::API2::ACME->renew_certificate({ node => $nodename });
-	    } else {
-		syslog ('info', 'Custom certificate does not expire soon, skipping ACME renewal.');
-	    }
-	} else {
-	    syslog ('info', 'ACME config found for node, but no custom certificate exists. Skipping ACME renewal until initial certificate has been deployed.');
-	}
+        my $cert = PVE::CertHelpers::cert_path_prefix($nodename) . ".pem";
+        if (-e $cert) {
+            if (PVE::Certificate::check_expiry($cert, time() + 30 * 24 * 60 * 60)) {
+                PVE::API2::ACME->renew_certificate({ node => $nodename });
+            } else {
+                syslog(
+                    'info',
+                    'Custom certificate does not expire soon, skipping ACME renewal.',
+                );
+            }
+        } else {
+            syslog(
+                'info',
+                'ACME config found for node, but no custom certificate exists. Skipping ACME renewal until initial certificate has been deployed.',
+            );
+        }
     }
 };
-syslog ('err', "Renewing ACME certificate failed: $@") if $@;
+syslog('err', "Renewing ACME certificate failed: $@") if $@;
 
 eval {
-    my $certpath = PVE::CertHelpers::default_cert_path_prefix($nodename).".pem";
+    my $certpath = PVE::CertHelpers::default_cert_path_prefix($nodename) . ".pem";
     my $capath = "/etc/pve/pve-root-ca.pem";
 
     my $renew = sub {
-	my ($msg) = @_;
+        my ($msg) = @_;
 
-	# get CA info
-	my $cainfo = PVE::Certificate::get_certificate_info($capath);
+        # get CA info
+        my $cainfo = PVE::Certificate::get_certificate_info($capath);
 
-	# get cert and check issuer and chain metadata
-	my $certinfo = PVE::Certificate::get_certificate_info($certpath);
-	if ($certinfo->{issuer} ne $cainfo->{subject}) {
-	    die "SSL certificate ($certpath) is not issued by root CA ($capath)!\n";
-	}
+        # get cert and check issuer and chain metadata
+        my $certinfo = PVE::Certificate::get_certificate_info($certpath);
+        if ($certinfo->{issuer} ne $cainfo->{subject}) {
+            die "SSL certificate ($certpath) is not issued by root CA ($capath)!\n";
+        }
 
-	# check if cert is really signed by the ca
-	# TODO: replace by low level ssleay interface if version 1.86 is available
-	PVE::Tools::run_command(['/usr/bin/openssl', 'verify', '-CAfile', $capath, $certpath]);
+        # check if cert is really signed by the ca
+        # TODO: replace by low level ssleay interface if version 1.86 is available
+        PVE::Tools::run_command(['/usr/bin/openssl', 'verify', '-CAfile', $capath, $certpath]);
 
-	print "PVE certificate $msg\n";
-	# create new certificate
-	my $ip = PVE::Cluster::remote_node_ip($nodename);
-	PVE::Cluster::Setup::gen_pve_ssl_cert(1, $nodename, $ip);
+        print "PVE certificate $msg\n";
+        # create new certificate
+        my $ip = PVE::Cluster::remote_node_ip($nodename);
+        PVE::Cluster::Setup::gen_pve_ssl_cert(1, $nodename, $ip);
 
-	print "Restarting pveproxy after renewing certificate\n";
-	PVE::Tools::run_command(['systemctl', 'reload-or-restart', 'pveproxy']);
+        print "Restarting pveproxy after renewing certificate\n";
+        PVE::Tools::run_command(['systemctl', 'reload-or-restart', 'pveproxy']);
     };
 
-    if (PVE::Certificate::check_expiry($certpath, time() + 14*24*60*60)) {
-	# expires in next 2 weeks
-	$renew->("expires soon, renewing...");
-    } elsif (!PVE::Certificate::check_expiry($certpath, time() + 2*365*24*60*60)) {
-	# expires in more than 2 years
-	$renew->("expires in more than 2 years, renewing to reduce certificate life-span for client compatibility...");
+    if (PVE::Certificate::check_expiry($certpath, time() + 14 * 24 * 60 * 60)) {
+        # expires in next 2 weeks
+        $renew->("expires soon, renewing...");
+    } elsif (!PVE::Certificate::check_expiry($certpath, time() + 2 * 365 * 24 * 60 * 60)) {
+        # expires in more than 2 years
+        $renew->(
+            "expires in more than 2 years, renewing to reduce certificate life-span for client compatibility..."
+        );
     }
 };
-syslog ('err', "Checking/Renewing SSL certificate failed: $@") if $@;
+syslog('err', "Checking/Renewing SSL certificate failed: $@") if $@;
 
 sub cleanup_tasks {
 
@@ -136,10 +144,10 @@ sub cleanup_tasks {
 
     my $endtime = 0;
     while (defined(my $line = <$fh>)) {
-	if ($line =~ m/^(\S+)(\s([0-9A-Za-z]{8})(\s(\S.*))?)?$/) {
-	    $endtime = hex($3);
-	    last;
-	}
+        if ($line =~ m/^(\S+)(\s([0-9A-Za-z]{8})(\s(\S.*))?)?$/) {
+            $endtime = hex($3);
+            last;
+        }
     }
     close($fh);
 
@@ -150,27 +158,27 @@ sub cleanup_tasks {
     my $count = 0;
 
     my $wanted = sub {
-	my $filename = $_;
+        my $filename = $_;
 
-	return if $filename !~ m/^UPID:/;
+        return if $filename !~ m/^UPID:/;
 
-	my $st;
-	if (($st = stat($filename)) && ($st->mtime < $endtime)) {
-	    unlink($filename);
-	    $count++;
-	}
+        my $st;
+        if (($st = stat($filename)) && ($st->mtime < $endtime)) {
+            unlink($filename);
+            $count++;
+        }
     };
 
     foreach my $subdir (qw(0 1 2 3 4 5 6 7 8 9 A B C D E F)) {
-	my $path = "$taskdir/$subdir";
-	find($wanted, $path);
+        my $path = "$taskdir/$subdir";
+        find($wanted, $path);
     }
 
     if ($count) {
-	syslog('info', "cleanup removed $count task logs");
+        syslog('info', "cleanup removed $count task logs");
     }
 }
 
 cleanup_tasks();
 
-exit (0);
+exit(0);
diff --git a/bin/pveupgrade b/bin/pveupgrade
index 04b3f7ac3..8e88f1f73 100755
--- a/bin/pveupgrade
+++ b/bin/pveupgrade
@@ -26,17 +26,17 @@ my $rpcenv = PVE::RPCEnvironment->init('cli');
 
 $rpcenv->init_request();
 $rpcenv->set_language($ENV{LANG});
-$rpcenv->set_user('root@pam'); 
+$rpcenv->set_user('root@pam');
 
 my $start_shell;
 
-if (!GetOptions ("shell" => \$start_shell)) {
+if (!GetOptions("shell" => \$start_shell)) {
     print "Usage: $0 [--shell]\n";
     exit(-1);
 }
 
 my $st = File::stat::stat("/var/cache/apt/pkgcache.bin");
-if (!$st || (time() - $st->mtime) > (3*24*3600)) {
+if (!$st || (time() - $st->mtime) > (3 * 24 * 3600)) {
 
     print "\nYour package database is out of date. Please update that first.\n\n";
 
@@ -46,36 +46,37 @@ if (!$st || (time() - $st->mtime) > (3*24*3600)) {
 
     print "Starting system upgrade: apt-get dist-upgrade\n";
 
-    my $oldlist = PVE::API2::APT->list_updates({ node => $nodename});
+    my $oldlist = PVE::API2::APT->list_updates({ node => $nodename });
 
-    system('apt-get', 'dist-upgrade'); 
+    system('apt-get', 'dist-upgrade');
 
-    my $pkglist = PVE::API2::APT->list_updates({ node => $nodename});
+    my $pkglist = PVE::API2::APT->list_updates({ node => $nodename });
 
     print "\n";
     if (my $count = scalar(@$pkglist)) {
-	print "System not fully up to date (found $count new packages)\n\n";
+        print "System not fully up to date (found $count new packages)\n\n";
     } else {
-	print "Your System is up-to-date\n\n";
+        print "Your System is up-to-date\n\n";
     }
 
     my $newkernel;
     foreach my $p (@$oldlist) {
-	if (($p->{Package} =~ m/^(?:pve|proxmox)-kernel/) && 
-	    !grep { $_->{Package} eq $p->{Package} } @$pkglist) {
-	    $newkernel = 1;
-	    last;
-	}	    
+        if (
+            ($p->{Package} =~ m/^(?:pve|proxmox)-kernel/)
+            && !grep { $_->{Package} eq $p->{Package} } @$pkglist
+        ) {
+            $newkernel = 1;
+            last;
+        }
     }
 
     if ($newkernel) {
-	print "\n";
-	print "Seems you installed a kernel update - Please consider rebooting\n" .
-	    "this node to activate the new kernel.\n\n";
+        print "\n";
+        print "Seems you installed a kernel update - Please consider rebooting\n"
+            . "this node to activate the new kernel.\n\n";
     }
 }
 
-
 if ($start_shell) {
     print "starting shell\n";
     system('/bin/bash -l');
@@ -83,7 +84,6 @@ if ($start_shell) {
 
 exit 0;
 
-
 __END__
 
 =head1 NAME
diff --git a/bin/pveversion b/bin/pveversion
index c08661f76..f8d278609 100755
--- a/bin/pveversion
+++ b/bin/pveversion
@@ -6,34 +6,34 @@ use POSIX;
 use Getopt::Long;
 use PVE::API2::APT;
 
-my $pkgarray = PVE::API2::APT->versions({ node => 'localhost'});
+my $pkgarray = PVE::API2::APT->versions({ node => 'localhost' });
 my $pkglist = {};
 foreach my $pkg (@$pkgarray) {
-    $pkglist->{$pkg->{Package}} = $pkg;
+    $pkglist->{ $pkg->{Package} } = $pkg;
 }
 
 sub print_status {
     my ($pkg) = @_;
 
-    my $pkginfo =  $pkglist->{$pkg};
+    my $pkginfo = $pkglist->{$pkg};
 
     if (!$pkginfo) {
-	print "$pkg: unknown package - internal error\n";
-	return;
+        print "$pkg: unknown package - internal error\n";
+        return;
     }
     my $version = "not correctly installed";
     if ($pkginfo->{OldVersion} && $pkginfo->{CurrentState} eq 'Installed') {
-	$version = $pkginfo->{OldVersion};
+        $version = $pkginfo->{OldVersion};
     } elsif ($pkginfo->{CurrentState} eq 'ConfigFiles') {
-	$version = 'residual config';
+        $version = 'residual config';
     }
 
     if ($pkginfo->{RunningKernel}) {
-	print "$pkg: $version (running kernel: $pkginfo->{RunningKernel})\n";
+        print "$pkg: $version (running kernel: $pkginfo->{RunningKernel})\n";
     } elsif ($pkginfo->{ManagerVersion}) {
-	print "$pkg: $version (running version: $pkginfo->{ManagerVersion})\n";
+        print "$pkg: $version (running version: $pkginfo->{ManagerVersion})\n";
     } else {
-	print "$pkg: $version\n";
+        print "$pkg: $version\n";
     }
 }
 
@@ -47,23 +47,22 @@ sub print_usage {
 
 my $opt_verbose;
 
-if (!GetOptions ('verbose' => \$opt_verbose)) {
-    print_usage ();
-    exit (-1);
+if (!GetOptions('verbose' => \$opt_verbose)) {
+    print_usage();
+    exit(-1);
 }
 
-if (scalar (@ARGV) != 0) {
-    print_usage ();
-    exit (-1);
+if (scalar(@ARGV) != 0) {
+    print_usage();
+    exit(-1);
 }
 
-my $ver =  PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text();
+my $ver = PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text();
 my (undef, undef, $kver) = POSIX::uname();
 
-
 if (!$opt_verbose) {
     print "$ver (running kernel: $kver)\n";
-    exit (0);
+    exit(0);
 }
 
 foreach my $pkg (@$pkgarray) {
diff --git a/bin/spiceproxy b/bin/spiceproxy
index 790c6dffe..6cc827ea6 100755
--- a/bin/spiceproxy
+++ b/bin/spiceproxy
@@ -2,7 +2,7 @@
 
 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
 
-delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};  
+delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
 
 use strict;
 use warnings;
@@ -18,12 +18,12 @@ $SIG{'__WARN__'} = sub {
     $@ = $err;
 };
 
-my $prepare  = sub {
-    my $rundir="/var/run/pveproxy";
+my $prepare = sub {
+    my $rundir = "/var/run/pveproxy";
     if (mkdir($rundir, 0700)) { # only works at first start if we are root)
-	my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
-	my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
-	chown($uid, $gid, $rundir);
+        my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
+        my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
+        chown($uid, $gid, $rundir);
     }
 };
 
-- 
2.49.0



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


  parent reply	other threads:[~2025-07-07 11:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 11:01 [pve-devel] [PATCH manager 0/2] bin: auto-format code using perltidy Christoph Heiss
2025-07-07 11:01 ` [pve-devel] [PATCH manager 1/2] buildsys: add target for auto-formatting bin/ scripts Christoph Heiss
2025-07-07 18:52   ` [pve-devel] applied: " Thomas Lamprecht
2025-07-07 11:01 ` Christoph Heiss [this message]
2025-07-07 11:23 ` [pve-devel] [PATCH manager 0/2] bin: auto-format code using perltidy Thomas Lamprecht
2025-07-07 11:44   ` Christoph Heiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250707110146.800467-3-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal