]> git.proxmox.com Git - dab.git/blobdiff - DAB.pm
refactor/cleanup constructor
[dab.git] / DAB.pm
diff --git a/DAB.pm b/DAB.pm
index 16466e0ea0c85338a8143d742c7e561306f50943..76b64c3a0ff00a9b72131526e1a579485dcfbc2e 100644 (file)
--- a/DAB.pm
+++ b/DAB.pm
@@ -59,9 +59,14 @@ sub __url_to_filename {
 
 # defaults:
 #  origin: debian
+#  flags:
+#    systemd: true (except for devuan ostypes)
 my $supported_suites = {
+    'bookworm' => {
+       ostype => "debian-12",
+    },
     'bullseye' => {
-       ostype => "debian-11.0",
+       ostype => "debian-11",
     },
     'buster' => {
        ostype => "debian-10",
@@ -73,19 +78,31 @@ my $supported_suites = {
        ostype => "debian-8.0",
     },
     'wheezy' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "debian-7.0",
     },
     'squeeze' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "debian-6.0",
     },
     'lenny' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "debian-5.0",
     },
     'etch' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "debian-4.0",
     },
 
-# DEVUAN
+# DEVUAN (imply systemd = 0 default)
     'devuan-jessie' => {
        suite => 'jessie',
        ostype => "devuan-1.0",
@@ -103,25 +120,43 @@ my $supported_suites = {
     'chimaera' => {
        ostype => "devuan-4.0",
     },
+    'daedalus' => {
+       ostype => "devuan-5.0",
+    },
 
 # UBUNTU
     'hardy' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "ubuntu-8.04",
        origin => 'ubuntu',
     },
     'intrepid' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "ubuntu-8.10",
        origin => 'ubuntu',
     },
     'jaunty' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "ubuntu-9.04",
        origin => 'ubuntu',
     },
     'precise' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "ubuntu-12.04",
        origin => 'ubuntu',
     },
     'trusty' => {
+       flags => {
+           systemd => 0,
+       },
        ostype => "ubuntu-14.04",
        origin => 'ubuntu',
     },
@@ -177,6 +212,18 @@ my $supported_suites = {
        ostype => "ubuntu-21.04",
        origin => 'ubuntu',
     },
+    'impish' => {
+       ostype => "ubuntu-21.10",
+       origin => 'ubuntu',
+    },
+    'jammy' => {
+       ostype => "ubuntu-22.04",
+       origin => 'ubuntu',
+    },
+    'kinetic' => {
+       ostype => "ubuntu-22.10",
+       origin => 'ubuntu',
+    },
 };
 
 sub get_suite_info {
@@ -188,20 +235,24 @@ sub get_suite_info {
     $suiteinfo->{origin} //= 'debian';
     $suiteinfo->{suite} //= $suite;
 
+    $suiteinfo->{flags} //= {};
+    if ($suiteinfo->{ostype} =~ /^devuan/) {
+       $suiteinfo->{flags}->{systemd} //= 0;
+    } else {
+       $suiteinfo->{flags}->{systemd} //= 1;
+    }
+
     return $suiteinfo;
 }
 
 sub download {
     my ($self, $url, $path) = @_;
+    my $tmpfn = "$path.tmp$$";
 
     $self->logmsg ("download: $url\n");
-    my $tmpfn = "$path.tmp$$";
-    eval {
-       $self->run_command ("wget -q '$url'  -O '$tmpfn'"); 
-    };
 
-    my $err = $@;
-    if ($err) {
+    eval { $self->run_command ("wget -q '$url'  -O '$tmpfn'") };
+    if (my $err = $@) {
        unlink $tmpfn;
        die $err;
     }
@@ -320,7 +371,7 @@ sub run_command {
     print $writer $input if defined $input;
     close $writer;
 
-    my $select = new IO::Select;
+    my $select = IO::Select->new();
     $select->add ($reader);
     $select->add ($error);
 
@@ -431,28 +482,61 @@ sub __allocate_ve {
     return $self->{veid};
 }
 
+# just use some simple heuristic for now, merge usr for releases newer than ubuntu 21.x or debian 11
+sub can_usr_merge {
+    my ($self) = @_;
+
+    my $ostype = $self->{config}->{ostype};
+
+    # FIXME: add configuration override posibillity
+
+    if ($ostype =~ m/^debian-(\d+)/) {
+       return int($1) >= 11;
+    } elsif ($ostype =~ m/^ubuntu-(\d+)/) {
+       return int($1) >= 21;
+    }
+    return; # false
+}
+
+sub setup_usr_merge {
+    my ($self) = @_;
+
+    my $rootfs = $self->{rootfs};
+    my $arch = $self->{config}->{architecture};
+
+    # similar to https://salsa.debian.org/installer-team/debootstrap/-/blob/master/functions#L1354
+    my @merged_dirs = qw(bin sbin lib);
+
+    if ($arch eq 'amd64') {
+       push @merged_dirs, qw(lib32 lib64 libx32);
+    } elsif ($arch eq 'i386') {
+       push @merged_dirs, qw(lib64 libx32);
+    }
+
+    $self->logmsg ("setup usr-merge symlinks for '" . join("', '", @merged_dirs) . "'\n");
+
+    for my $dir (@merged_dirs) {
+       symlink("usr/$dir", "$rootfs/$dir") or warn "could not create symlink - $!\n";
+       mkpath "$rootfs/usr/$dir";
+    }
+}
+
 sub new {
     my ($class, $config) = @_;
 
     $class = ref ($class) || $class;
-
-    my $self = {};
-
     $config = read_config ('dab.conf') if !$config;
 
-    $self->{config} = $config;
-
+    my $self = {
+       config => $config,
+    };
     bless $self, $class;
 
     $self->{logfile} = "logfile";
-    $self->{logfd} = IO::File->new (">>$self->{logfile}") ||
-       die "unable to open log file";
-
-    my $arch = $config->{architecture};
-    die "no 'architecture' specified\n" if !$arch;
+    $self->{logfd} = IO::File->new (">>$self->{logfile}") || die "unable to open log file";
 
-    die "unsupported architecture '$arch'\n" 
-       if $arch !~ m/^(i386|amd64)$/;
+    my $arch = $config->{architecture} ||die "no 'architecture' specified\n";
+    die "unsupported architecture '$arch'\n" if $arch !~ m/^(i386|amd64)$/;
 
     my $suite = $config->{suite} || die "no 'suite' specified\n";
 
@@ -461,21 +545,18 @@ sub new {
     $config->{ostype} = $suiteinfo->{ostype};
 
     my $name = $config->{name} || die "no 'name' specified\n";
+    $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ || die "illegal characters in name '$name'\n";
 
-    $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ || 
-       die "illegal characters in name '$name'\n";
-
+    # assert required dab.conf keys exist
+    for my $key (qw(version section headline maintainer)) {
+       die "no '$key' specified\n" if !$config->{$key};
+    }
     my $version = $config->{version};
-    die "no 'version' specified\n" if !$version;
-    die "no 'section' specified\n" if !$config->{section};
-    die "no 'description' specified\n" if !$config->{headline};
-    die "no 'maintainer' specified\n" if !$config->{maintainer};
 
     if ($name =~ m/^$config->{ostype}/) {
        $self->{targetname} = "${name}_${version}_$config->{architecture}";
     } else {
-       $self->{targetname} = "$config->{ostype}-${name}_" .
-           "${version}_$config->{architecture}";
+       $self->{targetname} = "$config->{ostype}-${name}_${version}_$config->{architecture}";
     }
 
     if (!$config->{source}) {
@@ -485,7 +566,7 @@ sub new {
                    'http://ftp.debian.org/debian SUITE main contrib',
                    'http://security.debian.org SUITE/updates main contrib',
                );
-           } elsif ($suite eq 'bullseye') {
+           } elsif ($suite eq 'bullseye' || $suite eq 'bookworm') {
                push @{$config->{source}}, (
                    "http://ftp.debian.org/debian SUITE main contrib",
                    "http://ftp.debian.org/debian SUITE-updates main contrib",
@@ -550,53 +631,41 @@ sub new {
            die "syntax error in mirror spezification '$m'\n";
        }
     }
-
     $self->{sources} = $sources;
-
     $self->{infodir} = "info";
 
-    $self->__allocate_ve ();
+    $self->__allocate_ve();
 
     $self->{cachedir} = ($config->{cachedir} || 'cache')  . "/$suite";;
 
     my $incl = [qw (less ssh openssh-server logrotate)];
+    my $excl = [qw (modutils reiserfsprogs ppp pppconfig pppoe pppoeconf nfs-common mtools ntp)];
 
-    my $excl = [qw (modutils reiserfsprogs ppp pppconfig pppoe
-                   pppoeconf nfs-common mtools ntp)];
-
-    # ubuntu has too many dependencies on udev, so
-    # we cannot exclude it (instead we disable udevd)
-
-    if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
-       $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
-       $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
-       $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
-       || $suite eq 'hirsute'
-    ) {
+    # ubuntu has too many dependencies on udev, so we cannot exclude it (instead we disable udevd)
+    if (lc($suiteinfo->{origin}) eq 'ubuntu' && $suiteinfo->{flags}->{systemd}) {
        push @$incl, 'isc-dhcp-client';
-       push @$excl, qw(libmodule-build-perl);
+       push @$excl, qw(libmodule-build-perl libdrm-common libdrm2 libplymouth5 plymouth plymouth-theme-ubuntu-text powermgmt-base);
+       if ($suite eq 'jammy') {
+           push @$excl, qw(fuse); # avoid fuse2 <-> fuse3 conflict
+       }
     } elsif ($suite eq 'trusty') {
        push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
    } elsif ($suite eq 'precise') {
        push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
     } elsif ($suite eq 'hardy') {
        push @$excl, qw(kbd);
-       push @$excl, qw(apparmor apparmor-utils ntfs-3g
-                       friendly-recovery);
+       push @$excl, qw(apparmor apparmor-utils ntfs-3g friendly-recovery);
     } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
-       push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl 
-                       libntfs-3g28 ntfs-3g friendly-recovery);
+       push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl libntfs-3g28);
+       push @$excl, qw(ntfs-3g friendly-recovery);
     } elsif ($suite eq 'jessie') {
        push @$incl, 'sysvinit-core'; # avoid systemd and udev
        push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
-       push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm 
-                       memtest86+ parted);
-    } elsif ($suite eq 'stretch' || $suite eq 'buster' || $suite eq 'bullseye') {
-       push @$excl, qw(module-init-tools pciutils hdparm
-                       memtest86+ parted);
+       push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm memtest86+ parted);
+    } elsif ($suite eq 'stretch' || $suite eq 'buster' || $suite eq 'bullseye' || $suite eq 'bookworm') {
+       push @$excl, qw(module-init-tools pciutils hdparm memtest86+ parted);
      } else {
-       push @$excl, qw(udev module-init-tools pciutils hdparm 
-                       memtest86+ parted);
+       push @$excl, qw(udev module-init-tools pciutils hdparm memtest86+ parted);
     }
 
     $self->{incl} = $incl;
@@ -618,17 +687,16 @@ sub initialize {
     my $logfd = $self->{logfd} = IO::File->new (">$self->{logfile}") ||
        die "unable to open log file";
 
-    # FIXME: seems a bit like a hacky way??
-    my $COMPRESSOR = {
-       ext => 'gz',
-       decomp => 'gzip -d',
-    };
-    if ($self->{config}->{suite} eq 'bullseye') {
-       $COMPRESSOR = {
+    my $COMPRESSORS = [
+       {
            ext => 'xz',
            decomp => 'xz -d',
-       };
-    }
+       },
+       {
+           ext => 'gz',
+           decomp => 'gzip -d',
+       },
+    ];
 
     foreach my $ss (@{$self->{sources}}) {
        my $src = $ss->{mirror} || $ss->{source};
@@ -646,11 +714,20 @@ sub initialize {
        };
 
        foreach my $comp (@{$ss->{comp}}) {
-           $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$COMPRESSOR->{ext}";
-           $target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
-           my $pkgsrc = "$src/$path";
-           $self->download ($pkgsrc, $target);
-           $self->run_command ("$COMPRESSOR->{decomp} '$target'");
+           foreach my $compressor (@$COMPRESSORS) {
+               $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
+               $target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
+               my $pkgsrc = "$src/$path";
+               eval {
+                   $self->download ($pkgsrc, $target);
+                   $self->run_command ("$compressor->{decomp} '$target'");
+               };
+               if (my $err = $@) {
+                   print $logfd "could not download Packages.$compressor->{ext}\n";
+               } else {
+                   last;
+               }
+           }
        }
     }
 }
@@ -762,14 +839,9 @@ sub finalize {
     $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
 
     unlink "$rootdir/sbin/defenv";
-
     unlink <$rootdir/root/dead.letter*>;
-
     unlink "$rootdir/var/log/init.log";
-
-    unlink "$rootdir/aquota.group";
-
-    unlink "$rootdir/aquota.user";
+    unlink "$rootdir/aquota.group", "$rootdir/aquota.user";
 
     write_file ("", "$rootdir/var/log/syslog");
 
@@ -796,13 +868,22 @@ sub finalize {
     my $compressor = $opts->{compressor} // 'gz';
     my $compressor2cmd_map = {
        gz => 'gzip',
-       zst => 'zstd',
+       gzip => 'gzip',
+       zst => 'zstd -9',
+       zstd => 'zstd -9',
+       'zstd-max' => 'zstd -19 -T0', # maximal level where the decompressor can still run efficiently
+    };
+    my $compressor2ending = {
+       gzip => 'gz',
+       zstd => 'zst',
+       'zstd-max' => 'zst',
     };
     my $compressor_cmd = $compressor2cmd_map->{$compressor};
     die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
        if !defined($compressor_cmd);
 
-    my $final_archive = "${target}.${compressor}";
+    my $ending = $compressor2ending->{$compressor} // $compressor;
+    my $final_archive = "${target}.${ending}";
     unlink $target;
     unlink $final_archive;
 
@@ -824,18 +905,17 @@ sub read_installed {
 
     my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
     local $/ = '';
-    open (PKGLST, "<$pkgfilelist") ||
-       die "unable to open '$pkgfilelist'";
+    open(my $PKGLST, '<', $pkgfilelist) or die "unable to open '$pkgfilelist' - $!";
 
     my $pkglist = {};
 
-    while (my $rec = <PKGLST>) {
+    while (my $rec = <$PKGLST>) {
        chomp $rec;
        $rec =~ s/\n\s+/ /g;
        $rec .= "\n";
        my $res = {};
 
-       while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
+       while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
            $res->{lc $1} = $2;
        }
 
@@ -849,7 +929,7 @@ sub read_installed {
        }
     }
 
-    close (PKGLST);    
+    close ($PKGLST);
 
     return $pkglist;
 }
@@ -878,7 +958,7 @@ sub ve_status {
        }
     }
     close($fh);
-    
+
     return $res;
 }
 
@@ -890,9 +970,9 @@ sub ve_command {
 
     if (ref ($cmd) eq 'ARRAY') {
        unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
-       $self->run_command ($cmd, $input);      
+       $self->run_command($cmd, $input);
     } else {
-       $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
+       $self->run_command("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
     }
 }
 
@@ -1026,17 +1106,16 @@ sub __parse_packages {
     my ($pkginfo, $filename, $src) = @_;
 
     local $/ = '';
-    open (PKGLST, "<$filename") ||
-       die "unable to open '$filename'";
+    open(my $PKGLST, '<', $filename) or die "unable to open '$filename' - $!";
 
-    while (my $rec = <PKGLST>) {
+    while (my $rec = <$PKGLST>) {
        $rec =~ s/\n\s+/ /g;
        chomp $rec;
        $rec .= "\n";
 
        my $res = {};
 
-       while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
+       while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
            $res->{lc $1} = $2;
        }
 
@@ -1058,7 +1137,7 @@ sub __parse_packages {
        }
     }
 
-    close (PKGLST);    
+    close ($PKGLST);
 }
 
 sub pkginfo {
@@ -1280,6 +1359,7 @@ sub install_init_script {
     my ($self, $script, $runlevel, $prio) = @_;
 
     my $suite = $self->{config}->{suite};
+    my $suiteinfo = get_suite_info($suite);
     my $rootdir = $self->{rootfs};
 
     my $base = basename ($script);
@@ -1288,12 +1368,7 @@ sub install_init_script {
     $self->run_command ("install -m 0755 '$script' '$target'");
     if ($suite eq 'etch' || $suite eq 'lenny') {
        $self->ve_command ("update-rc.d $base start $prio $runlevel .");
-    } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
-            $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
-            $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
-            $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
-            || $suite eq 'hirsute'
-    ) {
+    } elsif ($suiteinfo->{flags}->{systemd}) {
        die "unable to install init script (system uses systemd)\n";
     } elsif ($suite eq 'trusty' || $suite eq 'precise') {
        die "unable to install init script (system uses upstart)\n";
@@ -1310,17 +1385,26 @@ sub bootstrap {
     my $pkginfo = $self->pkginfo();
     my $veid = $self->{veid};
     my $suite = $self->{config}->{suite};
+    my $suiteinfo = get_suite_info($suite);
 
     my $important = [ @{$self->{incl}} ];
     my $required;
     my $standard;
 
     my $mta = $opts->{exim} ? 'exim' : 'postfix';
-
     if ($mta eq 'postfix') {
        push @$important, "postfix";
     }
 
+    if ($opts->{include}) {
+       push @$important, split(',', $opts->{include});
+    }
+
+    my $exclude = {};
+    if ($opts->{exclude}) {
+       $exclude->{$_} = 1 for split(',', $opts->{exclude});
+    }
+
     foreach my $p (sort keys %$pkginfo) {
        next if grep { $p eq $_ } @{$self->{excl}};
        my $pri = $pkginfo->{$p}->{priority};
@@ -1329,17 +1413,17 @@ sub bootstrap {
        next if $p =~ m/(selinux|semanage|policycoreutils)/;
 
        push @$required, $p  if $pri eq 'required';
+       next if $exclude->{$p};
        push @$important, $p if $pri eq 'important';
        push @$standard, $p if $pri eq 'standard' && !$opts->{minimal};
     }
 
     my $closure = {};
-    $required = $self->closure ($closure, $required);
-    $important = $self->closure ($closure, $important);
+    $required = $self->closure($closure, $required);
+    $important = $self->closure($closure, $important);
 
     if (!$opts->{minimal}) {
-       push @$standard, 'xbase-clients';
-       $standard = $self->closure ($closure, $standard);
+       $standard = $self->closure($closure, $standard);
     }
 
     # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
@@ -1376,13 +1460,29 @@ sub bootstrap {
 
     # extract required packages first
     $self->logmsg ("create basic environment\n");
+
+    if ($self->can_usr_merge()) {
+       $self->setup_usr_merge();
+    }
+
+    my $compressor2opt = {
+       'zst' => '--zstd',
+       'gz' => '--gzip',
+       'xz' => '--xz',
+    };
+    my $compressor_re = join('|', keys $compressor2opt->%*);
+
+    $self->logmsg ("extract required packages to rootfs\n");
     foreach my $p (@$required) {
        my $filename = $self->getpkgfile ($p);
        my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
-       if ($content =~ m/^data.tar.xz$/m) {
-           $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
+       if ($content =~ m/^(data.tar.($compressor_re))$/m) {
+           my $archive = $1;
+           my $tar_opts = "--keep-directory-symlink $compressor2opt->{$2}";
+
+           $self->run_command("ar -p '$self->{cachedir}/$filename' '$archive' | tar -C '$rootdir' -xf - $tar_opts");
        } else {
-           $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
+           die "unexpected error for $p: no data.tar.{xz,gz,zst} found...";
        }
     }
 
@@ -1412,13 +1512,9 @@ sub bootstrap {
     # avoid warnings about non-existent resolv.conf
     write_file ("", "$rootdir/etc/resolv.conf", 0644);
 
-    if (
-       $suite eq 'hirsute' || $suite eq 'groovy' || $suite eq 'focal' ||
-       $suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
-       $suite eq 'bionic' || $suite eq 'artful' ||
-       $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
-       $suite eq 'wily') {
+    if (lc($suiteinfo->{origin}) eq 'ubuntu' && $suiteinfo->{flags}->{systemd}) {
        # no need to configure loopback device
+       # FIXME: Debian (systemd based?) too?
     } else {
        $data = "auto lo\niface lo inet loopback\n";
        mkdir "$rootdir/etc/network";
@@ -1488,8 +1584,7 @@ EOD
     $self->ve_divert_add ("/sbin/udevd");
 
     if ($suite eq 'etch') {
-       # disable apache2 startup
-       write_file ("NO_START=1\n", "$rootdir/etc/default/apache2");
+       write_file ("NO_START=1\n", "$rootdir/etc/default/apache2"); # disable apache2 startup
     }
 
     $self->logmsg ("configure required packages\n");
@@ -1671,7 +1766,7 @@ sub compute_required {
     my $instpkgs = $self->read_installed ();
 
     my $closure = {};
-    __record_provides ($pkginfo, $closure, [keys %$instpkgs]);
+    __record_provides($pkginfo, $closure, [keys $instpkgs->%*]);
 
     return $self->closure ($closure, $pkglist);
 }
@@ -1680,7 +1775,7 @@ sub task_postgres {
     my ($self, $opts) = @_;
 
     my @supp = ('7.4', '8.1');
-    my $pgversion = '8.1';
+    my $pgversion; # NOTE: not setting that defaults to the distro default, normally the best choice
 
     my $suite = $self->{config}->{suite};
 
@@ -1691,31 +1786,33 @@ sub task_postgres {
        @supp = ('8.4');
        $pgversion = '8.4';
     } elsif ($suite eq 'wheezy') {
-        @supp = ('9.1');
-        $pgversion = '9.1';
+       @supp = ('9.1');
+       $pgversion = '9.1';
     } elsif ($suite eq 'jessie') {
-        @supp = ('9.4');
-        $pgversion = '9.4';
+       @supp = ('9.4');
+       $pgversion = '9.4';
     } elsif ($suite eq 'stretch') {
-        @supp = ('9.6');
-        $pgversion = '9.6';
+       @supp = ('9.6');
+       $pgversion = '9.6';
     } elsif ($suite eq 'buster') {
-        @supp = ('11');
-        $pgversion = '11';
+       @supp = ('11');
+       $pgversion = '11';
     } elsif ($suite eq 'bullseye') {
-       # FIXME update on freeze!
-       @supp = ('12');
-       $pgversion = '12';
+       @supp = ('13');
+    } elsif ($suite eq 'bookworm') {
+       # FIXME: update once froozen
+       @supp = ('13', '14');
     }
-
     $pgversion = $opts->{version} if $opts->{version};
 
-    die "unsupported postgres version '$pgversion'\n" 
-       if !grep { $pgversion eq $_; } @supp;
-
-    my $rootdir = $self->{rootfs};
+    my $required;
+    if (defined($pgversion)) {
+       die "unsupported postgres version '$pgversion'\n" if !grep { $pgversion eq $_; } @supp;
 
-    my $required = $self->compute_required (["postgresql-$pgversion"]);
+       $required = $self->compute_required (["postgresql-$pgversion"]);
+    } else {
+       $required = $self->compute_required (["postgresql"]);
+    }
 
     $self->cache_packages ($required);
  
@@ -1737,7 +1834,7 @@ sub task_mysql {
     my $rootdir = $self->{rootfs};
 
     my $suite = $self->{config}->{suite};
-    
+
     my $ver = '5.0';
     if ($suite eq 'squeeze') {
       $ver = '5.1';
@@ -1782,15 +1879,35 @@ sub task_php {
 
     my $memlimit = $opts->{memlimit};
     my $rootdir = $self->{rootfs};
+    my $suite = $self->{config}->{suite};
 
-    my $required = $self->compute_required ([qw (php5 php5-cli libapache2-mod-php5 php5-gd)]);
+    my $base_set = [qw(php-cli libapache2-mod-php php-gd)];
+    if ($suite =~ /(?:squeeze|wheezy|jessie)$/) {
+       $self->logmsg("WARN: using EOL php release on EOL suite");
+       $base_set = [qw(php5 php5-cli libapache2-mod-php5 php5-gd)];
+    }
+    my $required = $self->compute_required($base_set);
 
     $self->cache_packages ($required);
 
     $self->ve_dpkg ('install', @$required);
 
     if ($memlimit) {
-       $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
+       my $sed_cmd = ['sed', '-e', "s/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/", '-i'];
+       if ($suite =~ /(?:squeeze|wheezy|jessie)$/) {
+           push @$sed_cmd, "$rootdir/etc/php5/apache2/php.ini";
+       } else {
+           my $found = 0;
+           for my $fn (glob("'${rootdir}/etc/php/*/apache2/php.ini'")) {
+               push @$sed_cmd, "$rootdir/$fn";
+               $found = 1;
+           }
+           if (!$found) {
+               warn "WARN: did not found any php.ini to set the memlimit!\n";
+               return;
+           }
+       }
+       $self->run_command($sed_cmd);
     }
 }
 
@@ -1798,7 +1915,7 @@ sub install {
     my ($self, $pkglist, $unpack) = @_;
 
     my $required = $self->compute_required ($pkglist);
-    
+
     $self->cache_packages ($required);
 
     $self->ve_dpkg ($unpack ? 'unpack' : 'install', @$required);