]> git.proxmox.com Git - dab.git/blobdiff - DAB.pm
bootstrap: tar extract: pass "keep-directory-symlink" flag
[dab.git] / DAB.pm
diff --git a/DAB.pm b/DAB.pm
index 3d51c1e168fa5f300494aa7e34bd1cdd4ca29da6..590fd629517eff48d57a78bf2ba55fd9ea207784 100644 (file)
--- a/DAB.pm
+++ b/DAB.pm
@@ -42,6 +42,8 @@ mynetworks = 127.0.0.0/8
 inet_interfaces = loopback-only
 recipient_delimiter = +
 
+compatibility_level = 2
+
 EOD
 
 # produce apt compatible filenames (/var/lib/apt/lists)
@@ -55,6 +57,147 @@ sub __url_to_filename {
     return $url;
 }
 
+# defaults:
+#  origin: debian
+my $supported_suites = {
+    'bookworm' => {
+       ostype => "debian-12",
+    },
+    'bullseye' => {
+       ostype => "debian-11",
+    },
+    'buster' => {
+       ostype => "debian-10",
+    },
+    'stretch' => {
+       ostype => "debian-9.0",
+    },
+    'jessie' => {
+       ostype => "debian-8.0",
+    },
+    'wheezy' => {
+       ostype => "debian-7.0",
+    },
+    'squeeze' => {
+       ostype => "debian-6.0",
+    },
+    'lenny' => {
+       ostype => "debian-5.0",
+    },
+    'etch' => {
+       ostype => "debian-4.0",
+    },
+
+# DEVUAN
+    'devuan-jessie' => {
+       suite => 'jessie',
+       ostype => "devuan-1.0",
+    },
+    'devuan-ascii' => {
+       suite => 'ascii',
+       ostype => "devuan-2.0",
+    },
+    'ascii' => {
+       ostype => "devuan-2.0",
+    },
+    'beowulf' => {
+       ostype => "devuan-3.0",
+    },
+    'chimaera' => {
+       ostype => "devuan-4.0",
+    },
+
+# UBUNTU
+    'hardy' => {
+       ostype => "ubuntu-8.04",
+       origin => 'ubuntu',
+    },
+    'intrepid' => {
+       ostype => "ubuntu-8.10",
+       origin => 'ubuntu',
+    },
+    'jaunty' => {
+       ostype => "ubuntu-9.04",
+       origin => 'ubuntu',
+    },
+    'precise' => {
+       ostype => "ubuntu-12.04",
+       origin => 'ubuntu',
+    },
+    'trusty' => {
+       ostype => "ubuntu-14.04",
+       origin => 'ubuntu',
+    },
+    'vivid' => {
+       ostype => "ubuntu-15.04",
+       origin => 'ubuntu',
+    },
+    'wily' => {
+       ostype => "ubuntu-15.10",
+       origin => 'ubuntu',
+    },
+    'xenial' => {
+       ostype => "ubuntu-16.04",
+       origin => 'ubuntu',
+    },
+    'yakkety' => {
+       ostype => "ubuntu-16.10",
+       origin => 'ubuntu',
+    },
+    'zesty' => {
+       ostype => "ubuntu-17.04",
+       origin => 'ubuntu',
+    },
+    'artful' => {
+       ostype => "ubuntu-17.10",
+       origin => 'ubuntu',
+    },
+    'bionic' => {
+       ostype => "ubuntu-18.04",
+       origin => 'ubuntu',
+    },
+    'cosmic' => {
+       ostype => "ubuntu-18.10",
+       origin => 'ubuntu',
+    },
+    'disco' => {
+       ostype => "ubuntu-19.04",
+       origin => 'ubuntu',
+    },
+    'eoan' => {
+       ostype => "ubuntu-19.10",
+       origin => 'ubuntu',
+    },
+    'focal' => {
+       ostype => "ubuntu-20.04",
+       origin => 'ubuntu',
+    },
+    'groovy' => {
+       ostype => "ubuntu-20.10",
+       origin => 'ubuntu',
+    },
+    'hirsute' => {
+       ostype => "ubuntu-21.04",
+       origin => 'ubuntu',
+    },
+    'impish' => {
+       ostype => "ubuntu-21.10",
+       origin => 'ubuntu',
+    },
+};
+
+sub get_suite_info {
+    my ($suite) = @_;
+
+    my $suiteinfo = $supported_suites->{$suite} || die "unsupported suite '$suite'!\n";
+
+    # set defaults
+    $suiteinfo->{origin} //= 'debian';
+    $suiteinfo->{suite} //= $suite;
+
+    return $suiteinfo;
+}
+
 sub download {
     my ($self, $url, $path) = @_;
 
@@ -319,59 +462,10 @@ sub new {
        if $arch !~ m/^(i386|amd64)$/;
 
     my $suite = $config->{suite} || die "no 'suite' specified\n";
-    if ($suite eq 'buster') {
-       $config->{ostype} = "debian-10.0";
-    } elsif ($suite eq 'stretch') {
-       $config->{ostype} = "debian-9.0";
-    } elsif ($suite eq 'jessie') {
-         $config->{ostype} = "debian-8.0";
-    } elsif ($suite eq 'wheezy') {
-         $config->{ostype} = "debian-7.0";
-    } elsif ($suite eq 'squeeze') {
-       $config->{ostype} = "debian-6.0";
-    } elsif ($suite eq 'lenny') { 
-       $config->{ostype} = "debian-5.0";
-    } elsif ($suite eq 'etch') { 
-       $config->{ostype} = "debian-4.0";
-    } elsif ($suite eq 'devuan-jessie') {
-       $suite = 'jessie';
-       $config->{ostype} = "devuan-1.0";
-    } elsif ($suite eq 'devuan-ascii' || $suite eq 'ascii') {
-       $suite = 'ascii';
-       $config->{ostype} = "devuan-2.0";
-    } elsif ($suite eq 'hardy') { 
-       $config->{ostype} = "ubuntu-8.04";
-    } elsif ($suite eq 'intrepid') { 
-       $config->{ostype} = "ubuntu-8.10";
-    } elsif ($suite eq 'jaunty') { 
-       $config->{ostype} = "ubuntu-9.04";
-    } elsif ($suite eq 'precise') { 
-       $config->{ostype} = "ubuntu-12.04";
-    } elsif ($suite eq 'trusty') { 
-       $config->{ostype} = "ubuntu-14.04";
-    } elsif ($suite eq 'vivid') { 
-       $config->{ostype} = "ubuntu-15.04";
-    } elsif ($suite eq 'wily') {
-       $config->{ostype} = "ubuntu-15.10";
-    } elsif ($suite eq 'xenial') {
-       $config->{ostype} = "ubuntu-16.04";
-    } elsif ($suite eq 'yakkety') {
-       $config->{ostype} = "ubuntu-16.10";
-    } elsif ($suite eq 'zesty') {
-       $config->{ostype} = "ubuntu-17.04";
-    } elsif ($suite eq 'artful') {
-       $config->{ostype} = "ubuntu-17.10";
-    } elsif ($suite eq 'bionic') {
-       $config->{ostype} = "ubuntu-18.04";
-    } elsif ($suite eq 'cosmic') {
-       $config->{ostype} = "ubuntu-18.10";
-    } elsif ($suite eq 'disco') {
-       $config->{ostype} = "ubuntu-19.04";
-    } elsif ($suite eq 'eoan') {
-       $config->{ostype} = "ubuntu-19.10";
-    } else {
-       die "unsupported debian suite '$suite'\n";
-    }
+
+    my $suiteinfo = get_suite_info($suite);
+    $suite = $suiteinfo->{suite};
+    $config->{ostype} = $suiteinfo->{ostype};
 
     my $name = $config->{name} || die "no 'name' specified\n";
 
@@ -392,23 +486,32 @@ sub new {
     }
 
     if (!$config->{source}) {
-       if ($suite eq 'etch' || $suite eq 'lenny') {
-           push @{$config->{source}}, "http://ftp.debian.org/debian SUITE main contrib";
-           push @{$config->{source}}, "http://security.debian.org SUITE/updates main contrib";
-       } elsif ($suite eq 'squeeze' || $suite eq 'stretch' ||
-                $suite eq 'jessie' || $suite eq 'buster' ) {
-           push @{$config->{source}}, "http://ftp.debian.org/debian SUITE main contrib";
-           push @{$config->{source}}, "http://ftp.debian.org/debian SUITE-updates main contrib";
-           push @{$config->{source}}, "http://security.debian.org SUITE/updates main contrib";
-       } elsif ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty' ||
-                $suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
-                $suite eq 'trusty' || $suite eq 'precise' || $suite eq 'yakkety' ||
-                $suite eq 'zesty' || $suite eq 'artful' || $suite eq 'bionic' ||
-                $suite eq 'cosmic' || $suite eq 'disco' || $suite eq 'eoan' ) {
+       if (lc($suiteinfo->{origin}) eq 'debian') {
+           if ($suite eq 'etch' || $suite eq 'lenny') {
+               push @{$config->{source}}, (
+                   'http://ftp.debian.org/debian SUITE main contrib',
+                   'http://security.debian.org SUITE/updates main contrib',
+               );
+           } 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",
+                   "http://security.debian.org SUITE-security main contrib",
+               );
+           } else {
+               push @{$config->{source}}, (
+                   "http://ftp.debian.org/debian SUITE main contrib",
+                   "http://ftp.debian.org/debian SUITE-updates main contrib",
+                   "http://security.debian.org SUITE/updates main contrib",
+               );
+           }
+       } elsif (lc($suiteinfo->{origin}) eq 'ubuntu') {
            my $comp = "main restricted universe multiverse";
-           push @{$config->{source}}, "http://archive.ubuntu.com/ubuntu SUITE $comp"; 
-           push @{$config->{source}}, "http://archive.ubuntu.com/ubuntu SUITE-updates $comp"; 
-           push @{$config->{source}}, "http://archive.ubuntu.com/ubuntu SUITE-security $comp";
+           push @{$config->{source}}, (
+               "http://archive.ubuntu.com/ubuntu SUITE $comp",
+               "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
+               "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
+           );
        } else {
            die "implement me";
        }
@@ -474,7 +577,9 @@ sub new {
     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 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
+       || $suite eq 'hirsute' || $suite eq 'impish'
+    ) {
        push @$incl, 'isc-dhcp-client';
        push @$excl, qw(libmodule-build-perl);
     } elsif ($suite eq 'trusty') {
@@ -491,14 +596,11 @@ sub new {
     } 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') {
-       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;
@@ -520,6 +622,17 @@ sub initialize {
     my $logfd = $self->{logfd} = IO::File->new (">$self->{logfile}") ||
        die "unable to open log file";
 
+    my $COMPRESSORS = [
+       {
+           ext => 'xz',
+           decomp => 'xz -d',
+       },
+       {
+           ext => 'gz',
+           decomp => 'gzip -d',
+       },
+    ];
+
     foreach my $ss (@{$self->{sources}}) {
        my $src = $ss->{mirror} || $ss->{source};
        my $path = "dists/$ss->{suite}/Release";
@@ -534,12 +647,22 @@ sub initialize {
            print $logfd $@; 
            warn "Release info ignored\n";
        };
+
        foreach my $comp (@{$ss->{comp}}) {
-           $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.gz";
-           $target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
-           my $pkgsrc = "$src/$path";
-           $self->download ($pkgsrc, $target);
-           $self->run_command ("gzip -d '$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;
+               }
+           }
        }
     }
 }
@@ -662,15 +785,18 @@ sub finalize {
 
     write_file ("", "$rootdir/var/log/syslog");
 
-    $self->logmsg ("detecting final size: ");
+    my $get_path_size = sub {
+       my ($path) = @_;
+       my $sizestr = $self->run_command ("du -sm $path", undef, 1);
+       if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
+           return int($1);
+       } else {
+           die "unable to detect size for '$path'\n";
+       }
+    };
 
-    my $sizestr = $self->run_command ("du -sm $rootdir", undef, 1);
-    my $size;
-    if ($sizestr =~ m/^(\d+)\s+\Q$rootdir\E$/) {
-       $size = $1;
-    } else {
-       die "unable to detect size\n";
-    }
+    $self->logmsg ("detecting final appliance size: ");
+    my $size = $get_path_size->($rootdir);
     $self->logmsg ("$size MB\n");
 
     $self->write_config ("$rootdir/etc/appliance.info", $size);
@@ -678,12 +804,38 @@ sub finalize {
     $self->logmsg ("creating final appliance archive\n");
 
     my $target = "$self->{targetname}.tar";
+
+    my $compressor = $opts->{compressor} // 'gz';
+    my $compressor2cmd_map = {
+       gz => 'gzip',
+       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 $ending = $compressor2ending->{$compressor} // $compressor;
+    my $final_archive = "${target}.${ending}";
     unlink $target;
-    unlink "$target.gz";
+    unlink $final_archive;
 
     $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
     $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
-    $self->run_command ("gzip $target");
+    $self->run_command ("$compressor_cmd $target");
+
+    $self->logmsg ("detecting final commpressed appliance size: ");
+    $size = $get_path_size->($final_archive);
+    $self->logmsg ("$size MB\n");
+
+    $self->logmsg ("appliance archive: $final_archive\n");
 }
 
 sub read_installed {
@@ -1160,7 +1312,9 @@ sub install_init_script {
     } 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 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
+            || $suite eq 'hirsute' || $suite eq 'impish'
+    ) {
        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";
@@ -1247,9 +1401,9 @@ sub bootstrap {
        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 -");
+           $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf - --keep-directory-symlink");
        } else {
-           $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
+           $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf - --keep-directory-symlink");
        }
     }
 
@@ -1279,10 +1433,14 @@ sub bootstrap {
     # avoid warnings about non-existent resolv.conf
     write_file ("", "$rootdir/etc/resolv.conf", 0644);
 
-    if ($suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
+    if (
+       $suite eq 'impish' ||
+       $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') {
+       $suite eq 'wily'
+    ) {
        # no need to configure loopback device
     } else {
        $data = "auto lo\niface lo inet loopback\n";
@@ -1464,18 +1622,16 @@ EOD
        $self->run_command ($cmd);
     }
 
-    if ($suite eq 'intrepid') {
+    if ($suite eq 'intrepid' || $suite eq 'jaunty') {
        # remove sysctl setup (avoid warnings at startup)
        my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
-       $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf";
+       $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
        $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
        $self->run_command ("rm $filelist");
     }
-    if ($suite eq 'jaunty') {
-       # remove sysctl setup (avoid warnings at startup)
-       my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
-       $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
-       $self->run_command ("rm $filelist");
+
+    if (-e "$rootdir/lib/systemd/system/sys-kernel-config.mount") {
+       $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
     }
 }
 
@@ -1569,6 +1725,13 @@ sub task_postgres {
     } elsif ($suite eq 'buster') {
         @supp = ('11');
         $pgversion = '11';
+    } elsif ($suite eq 'bullseye') {
+       @supp = ('13');
+       $pgversion = '13';
+    } elsif ($suite eq 'bookworm') {
+       # FIXME: update once froozen
+       @supp = ('13');
+       $pgversion = '13';
     }
 
     $pgversion = $opts->{version} if $opts->{version};