]> git.proxmox.com Git - dab.git/blobdiff - DAB.pm
close #1668: add support for devuan jessie and ascii
[dab.git] / DAB.pm
diff --git a/DAB.pm b/DAB.pm
index e02cf10fb528e3fc3993d7cb9897d9fc674c2da1..dafae9fd11823d50cd90ab1a8832dccf1108ad6e 100644 (file)
--- a/DAB.pm
+++ b/DAB.pm
@@ -237,7 +237,7 @@ sub __sample_config {
 
     my $ostype = $self->{config}->{ostype};
 
-    if ($ostype =~ m/^debian-/) {
+    if ($ostype =~ m/^de(bi|vu)an-/) {
        $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
     } elsif ($ostype =~ m/^ubuntu-/) {
        $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
@@ -319,7 +319,9 @@ sub new {
        if $arch !~ m/^(i386|amd64)$/;
 
     my $suite = $config->{suite} || die "no 'suite' specified\n";
-    if ($suite eq 'jessie') {
+    if ($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";
@@ -329,6 +331,12 @@ sub new {
        $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' || 'ascii') {
+       $suite = 'ascii';
+       $config->{ostype} = "devuan-2.0";
     } elsif ($suite eq 'hardy') { 
        $config->{ostype} = "ubuntu-8.04";
     } elsif ($suite eq 'intrepid') { 
@@ -343,6 +351,14 @@ sub new {
        $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";
     } else {
        die "unsupported debian suite '$suite'\n";
     }
@@ -366,14 +382,18 @@ sub new {
     }
 
     if (!$config->{source}) {
-       if ($suite eq 'etch' || $suite eq 'lenny' || $suite eq 'squeeze' || 
-           $suite eq 'wheezy' || $suite eq 'jessie' ) {
+       if ($suite eq 'etch' || $suite eq 'lenny') {
            push @{$config->{source}}, "http://ftp.debian.org/debian SUITE main contrib";
-           push @{$config->{source}}, "http://ftp.debian.org/debian SUITE-updates main contrib"
-               if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie');
+           push @{$config->{source}}, "http://security.debian.org SUITE/updates main contrib";
+       } elsif ($suite eq 'squeeze' || $suite eq 'wheezy' ||
+                $suite eq 'jessie' || $suite eq 'stretch' ) {
+           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 'wily' || $suite eq 'vivid' || $suite eq 'trusty' || $suite eq 'precise') {
+                $suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
+                $suite eq 'trusty' || $suite eq 'precise' || $suite eq 'yakkety' ||
+                $suite eq 'zesty' || $suite eq 'artful' ) {
            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"; 
@@ -440,8 +460,10 @@ sub new {
     # ubuntu has too many dependencies on udev, so
     # we cannot exclude it (instead we disable udevd)
 
-    if ($suite eq 'vivid' || $suite eq 'wily') {
+    if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
+       $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful') {
        push @$incl, 'isc-dhcp-client';
+       push @$excl, qw(libmodule-build-perl);
     } elsif ($suite eq 'trusty') {
        push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
    } elsif ($suite eq 'precise') {
@@ -458,6 +480,9 @@ sub new {
        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') {
+       push @$excl, qw(module-init-tools pciutils hdparm
+                       memtest86+ parted);
      } else {
        push @$excl, qw(udev module-init-tools pciutils hdparm 
                        memtest86+ parted);
@@ -544,6 +569,7 @@ sub finalize {
     my $instpkgs = $self->read_installed ();
     my $pkginfo = $self->pkginfo();
     my $veid = $self->{veid};
+    my $conffile = $self->{veconffile};
     my $rootdir = $self->{rootfs};
 
     my $vestat = $self->ve_status();
@@ -609,7 +635,7 @@ sub finalize {
     $self->ve_divert_remove ("/sbin/init"); 
 
     # finally stop the VE
-    $self->run_command ("lxc-stop -n $veid --kill");
+    $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
 
     unlink "$rootdir/sbin/defenv";
 
@@ -716,12 +742,13 @@ sub ve_command {
     my ($self, $cmd, $input) = @_;
 
     my $veid = $self->{veid};
+    my $conffile = $self->{veconffile};
 
     if (ref ($cmd) eq 'ARRAY') {
-       unshift @$cmd, 'lxc-attach', '-n', $veid, '--clear-env', '--', 'defenv';
+       unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
        $self->run_command ($cmd, $input);      
     } else {
-       $self->run_command ("lxc-attach -n $veid --clear-env -- defenv $cmd", $input);
+       $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
     }
 }
 
@@ -730,9 +757,10 @@ sub ve_exec {
     my ($self, @cmd) = @_;
 
     my $veid = $self->{veid};
+    my $conffile = $self->{veconffile};
 
     my $reader;
-    my $pid = open2($reader, "<&STDIN", 'lxc-attach', '-n', $veid,  '--',
+    my $pid = open2($reader, "<&STDIN", 'lxc-attach', '-n', $veid,  '--rcfile', $conffile, '--',
                    'defenv', @cmd) || die "unable to exec command";
     
     while (defined (my $line = <$reader>)) {
@@ -812,10 +840,11 @@ sub ve_destroy {
     my ($self) = @_;
 
     my $veid = $self->{veid}; # fixme
+    my $conffile = $self->{veconffile};
 
     my $vestat = $self->ve_status();
     if ($vestat->{running}) {
-       $self->run_command ("lxc-stop -n $veid --kill");
+       $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
     }
 
     rmtree $self->{rootfs};
@@ -826,12 +855,13 @@ sub ve_init {
     my ($self) = @_;
 
     my $veid = $self->{veid};
+    my $conffile = $self->{veconffile};
 
     $self->logmsg ("initialize VE $veid\n");
 
     my $vestat = $self->ve_status();
     if ($vestat->{running}) {
-       $self->run_command ("lxc-stop -n $veid --kill");
+       $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
     } 
 
     rmtree $self->{rootfs};
@@ -996,18 +1026,19 @@ sub closure {
     # first, record provided packages
     __record_provides ($pkginfo, $closure, $list, 1);
 
-    my $pkgs = {};
+    my $pkghash = {};
+    my $pkglist = [];
 
     # then resolve dependencies
     foreach my $pname (@$list) {
-       __closure_single ($pkginfo, $closure, $pkgs, $pname, $self->{excl});
+       __closure_single ($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl});
     }
 
-    return [ keys %$pkgs ];
+    return $pkglist;
 }
 
 sub __closure_single {
-    my ($pkginfo, $closure, $pkgs, $pname, $excl) = @_;
+    my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
 
     $pname =~ s/^\s+//;
     $pname =~ s/\s+$//;
@@ -1024,8 +1055,11 @@ sub __closure_single {
     my $url = $info->{url};
 
     $url || die "$pname: no url for package '$pname'";
-    
-    $pkgs->{$pname} = 1;
+
+    if (!$pkghash->{$pname}) {
+       unshift @$pkglist, $pname;
+       $pkghash->{$pname} = 1;
+    }
 
     __record_provides ($pkginfo, $closure, [$pname]) if $info->{provides};
 
@@ -1061,7 +1095,7 @@ sub __closure_single {
 
       #printf (STDERR "$pname: $p --> $found\n");
          
-      __closure_single ($pkginfo, $closure, $pkgs, $found, $excl);
+      __closure_single ($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
   }
 }
 
@@ -1110,7 +1144,8 @@ 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 'wily' || $suite eq 'vivid') {
+    } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
+            $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful') {
        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";
@@ -1138,7 +1173,7 @@ sub bootstrap {
        push @$important, "postfix";
     }
 
-    foreach my $p (keys %$pkginfo) {
+    foreach my $p (sort keys %$pkginfo) {
        next if grep { $p eq $_ } @{$self->{excl}};
        my $pri = $pkginfo->{$p}->{priority};
        next if !$pri;
@@ -1229,8 +1264,14 @@ sub bootstrap {
     # avoid warnings about non-existent resolv.conf
     write_file ("", "$rootdir/etc/resolv.conf", 0644);
 
-    $data = "auto lo\niface lo inet loopback\n";
-    write_file ($data, "$rootdir/etc/network/interfaces", 0644);
+    if ($suite eq 'artful' || $suite eq 'zesty' || $suite eq 'yakkety' ||
+       $suite eq 'xenial' || $suite eq 'wily') {
+       # no need to configure loopback device
+    } else {
+       $data = "auto lo\niface lo inet loopback\n";
+       mkdir "$rootdir/etc/network";
+       write_file ($data, "$rootdir/etc/network/interfaces", 0644);
+    }
 
     # setup devices
     $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
@@ -1267,7 +1308,7 @@ sub bootstrap {
 
     $self->ve_dpkg ('install', 'mawk');
     $self->ve_dpkg ('install', 'debconf');
-    
+
     # unpack required packages
     foreach my $p (@$required) {
        $self->ve_dpkg ('unpack', $p);
@@ -1325,7 +1366,11 @@ EOD
     }
 
     # start loopback
-    $self->ve_command ("ifconfig lo up");
+    if (-x "$rootdir/sbin/ifconfig") {
+       $self->ve_command ("ifconfig lo up");
+    } else {
+       $self->ve_command ("ip link set lo up");
+    }
 
     $self->logmsg ("configure important packages\n");
     $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
@@ -1421,6 +1466,7 @@ sub enter {
     my ($self) = @_;
 
     my $veid = $self->{veid};
+    my $conffile = $self->{veconffile};
 
     my $vestat = $self->ve_status();
 
@@ -1430,10 +1476,10 @@ sub enter {
     }
 
     if (!$vestat->{running}) {
-       $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
+       $self->run_command ("lxc-start -n $veid -f $conffile");
     }
 
-    system ("lxc-attach -n $veid --clear-env");
+    system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
 }
 
 sub ve_mysql_command {
@@ -1500,6 +1546,9 @@ sub task_postgres {
     } elsif ($suite eq 'jessie') {
         @supp = ('9.4');
         $pgversion = '9.4';
+    } elsif ($suite eq 'stretch') {
+        @supp = ('9.6');
+        $pgversion = '9.6';
     }
 
     $pgversion = $opts->{version} if $opts->{version};
@@ -1516,8 +1565,9 @@ sub task_postgres {
     $self->ve_dpkg ('install', @$required);
 
     my $iscript = "postgresql-$pgversion";
-    if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
-      $iscript = 'postgresql';
+    if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
+       $suite eq 'stretch') {
+       $iscript = 'postgresql';
     }
 
     $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start};
@@ -1536,6 +1586,8 @@ sub task_mysql {
       $ver = '5.1';
     } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
       $ver = '5.5';
+    } else {
+       die "task_mysql: unsupported suite '$suite'";
     }
 
     my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);