]> git.proxmox.com Git - aab.git/blame - aab
actually use the pacman config
[aab.git] / aab
CommitLineData
7b25f331
WB
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use Getopt::Long;
6
7use PVE::AAB;
8
9$ENV{'LC_ALL'} = 'C';
10
11sub print_usage {
12 my ($msg) = @_;
13
14 if ($msg) {
15 print STDERR "ERROR: $msg\n";
16 }
17 print STDERR "aab <command> [parameters]\n";
18}
19
20$SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = sub {
21 die "interrupted by signal\n";
22};
23
24my $aab = PVE::AAB->new();
25
26$aab->writelog("aab: " . join(' ', @ARGV) . "\n");
27
28my $cmd = shift @ARGV;
29if (!$cmd) {
30 print_usage('missing command');
31 exit -1;
32}
33
34eval {
35 if ($cmd eq 'init') {
36
37 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
38 $aab->initialize();
39
40 } elsif ($cmd eq 'bootstrap') {
41
42 my ($datadir, $keep);
43 if (!GetOptions('datadir=s' => \$datadir,
44 'keep' => \$keep)) {
45 print_usage();
46 exit -1;
47 }
48
49 my $here = "$aab->{working_dir}/scripts/init.bash";
50 if (!$datadir && -f $here) {
51 print "Using current working directory as data directory\n";
52 $datadir = $aab->{working_dir};
53 }
54
55 PVE::AAB::setup_defaults($datadir) if $datadir;
56 $aab->ve_init() if !$keep;
57 $aab->bootstrap();
58
59 } elsif ($cmd eq 'basedir') {
60
61 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
62 print $aab->{rootfs} . "\n";
63
64 } elsif ($cmd eq 'veid') {
65
66 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
67 print $aab->{veid} . "\n";
68
69 } elsif ($cmd eq 'packagefile') {
70
71 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
72
73 print "$aab->{targetname}.tar.gz\n";
74
75 } elsif ($cmd eq 'finalize') {
76
77 $aab->finalize();
78
79 } elsif ($cmd eq 'install') {
80
81 my $required;
82 foreach my $arg (@ARGV) {
83 if ($arg =~ m/\.pkglist$/) {
84 open my $fh, $arg or
85 die "cant open package list '$arg' - $!";
86 while (defined (my $line = <$fh>)) {
87 chomp $line;
88 next if $line =~ m/^\s*$/;
89 next if $line =~ m/\#/;
90 if ($line =~ m/^\s*(\S+)\s*$/) {
91 push @$required, $1;
92 } else {
93 die "invalid package name in '$arg' - $line\n";
94 }
95 }
96 close ($fh);
97 } else {
98 push @$required, $arg;
99 }
100 }
101
102 $aab->install ($required);
103
104 } elsif ($cmd eq 'exec') {
105
106 $aab->ve_exec (@ARGV);
107
108 } elsif ($cmd eq 'enter') {
109
110 $aab->enter();
111
112 } elsif ($cmd eq 'clean') {
113
114 $aab->clean();
115
116 } elsif ($cmd eq 'dist-clean') {
117
118 $aab->clean(1);
119
120 } elsif ($cmd eq 'list') {
121
122 my $verbose;
123
124 if (!GetOptions ('verbose' =>\$verbose)) {
125 print_usage ();
126 exit (-1);
127 }
128
129 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
130
131 my $query = '-Q';
132 $query .= 'q' if !$verbose;
133 print $aab->run_command(['chroot', $aab->{rootfs}, 'pacman', $query], undef, 1);
134
135 } else {
136
137 print_usage("invalid command '$cmd'");
138 exit (-1);
139
140 }
141};
142
143if (my $err = $@) {
144 $aab->logmsg($err);
145 die $err;
146}
147
148exit 0;