]> git.proxmox.com Git - aab.git/blobdiff - PVE/AAB.pm
change `pacman -Sy` to `-Syy`, cleanup whitespace
[aab.git] / PVE / AAB.pm
index a25de94a57b3f08c0e03b86e87341faf959cbbd1..77410adf6bd2b4d59fc6e97d39b64ca8fa1f66ab 100644 (file)
@@ -7,6 +7,7 @@ use File::Path;
 use File::Copy;
 use IO::File;
 use IO::Select;
+use IPC::Open2;
 use IPC::Open3;
 use UUID;
 use Cwd;
@@ -100,7 +101,7 @@ sub read_config {
            my $long = $2;
            $long =~ s/^\s+/ /;
            $res->{description} = $long;
-           chomp $res->{description};      
+           chomp $res->{description};
        } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
            my ($key, $value) = (lc ($1), $2);
            if ($key eq 'source' || $key eq 'mirror') {
@@ -116,6 +117,8 @@ sub read_config {
 
     die "unable to parse config file" if $rec;
 
+    $res->{architecture} = 'amd64' if $res->{architecture} eq 'x86_64';
+
     return $res;
 }
 
@@ -130,7 +133,7 @@ sub new {
     die "no 'maintainer' specified\n" if !$config->{maintainer};
 
     my $name = $config->{name} || die "no 'name' specified\n";
-    $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ || 
+    $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
        die "illegal characters in name '$name'\n";
 
     my $targetname;
@@ -165,8 +168,8 @@ sub __sample_config {
     return <<"CFG";
 lxc.arch = $arch
 lxc.include = /usr/share/lxc/config/archlinux.common.conf
-lxc.utsname = localhost
-lxc.rootfs = $self->{rootfs}
+lxc.uts.name = localhost
+lxc.rootfs.path = $self->{rootfs}
 lxc.mount.entry = $self->{pkgcache} $self->{pkgdir} none bind 0 0
 CFG
 }
@@ -235,10 +238,12 @@ sub initialize {
 
     $fh = IO::File->new($self->{'pacman.conf'}, O_WRONLY|O_CREAT|O_EXCL) ||
        die "unable to write pacman config file $self->{'pacman.conf'} - $!";
+    my $arch = $config->{architecture};
+    $arch = 'x86_64' if $arch eq 'amd64';
     print $fh <<"EOF";
 [options]
 HoldPkg = pacman glibc
-Architecture = $config->{architecture}
+Architecture = $arch
 CheckSpace
 SigLevel = Never
 
@@ -283,7 +288,7 @@ sub ve_status {
        }
     }
     close($fh);
-    
+
     return $res;
 }
 
@@ -306,13 +311,14 @@ sub ve_init {
 
 
     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};
     mkpath $self->{rootfs};
@@ -322,12 +328,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', '--';
+       unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile,'--clear-env', '--';
        $self->run_command ($cmd, $input);
     } else {
-       $self->run_command ("lxc-attach -n $veid --clear-env -- $cmd", $input);
+       $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- $cmd", $input);
     }
 }
 
@@ -335,9 +342,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,  '--', @cmd)
+    my $pid = open2($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--', @cmd)
        or die "unable to exec command";
 
     while (defined (my $line = <$reader>)) {
@@ -375,8 +383,8 @@ sub run_command {
     # catch exec errors
     if ($orig_pid != $$) {
        $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
-       POSIX::_exit (1); 
-       kill ('KILL', $$); 
+       POSIX::_exit (1);
+       kill ('KILL', $$);
     }
 
     die $err if $err;
@@ -426,7 +434,8 @@ sub start_container {
 sub stop_container {
     my ($self) = @_;
     my $veid = $self->{veid};
-    $self->run_command ("lxc-stop -n $veid --kill");
+    my $conffile = $self->{veconffile};
+    $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
 }
 
 sub pacman_command {
@@ -457,7 +466,7 @@ sub bootstrap {
     mkpath $self->{pkgcache};
     mkpath $self->{pkgdir};
     mkpath "$root/var/lib/pacman";
-    $self->run_command([@pacman, '-Sy']);
+    $self->run_command([@pacman, '-Syy']);
 
     print "Figuring out what to install...\n";
     my $incl = { map { $_ => 1 } @{$self->{incl}} };
@@ -644,6 +653,7 @@ sub finalize {
 sub enter {
     my ($self) = @_;
     my $veid = $self->{veid};
+    my $conffile = $self->{veconffile};
 
     my $vestat = $self->ve_status();
     if (!$vestat->{exist}) {
@@ -655,7 +665,7 @@ sub enter {
        $self->start_container();
     }
 
-    system ("lxc-attach -n $veid --clear-env");
+    system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
 }
 
 sub clean {