]> git.proxmox.com Git - aab.git/blob - aab
mask systemd-journald-audit.socket
[aab.git] / aab
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Getopt::Long;
6
7 use PVE::AAB;
8
9 $ENV{'LC_ALL'} = 'C';
10
11 sub 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
24 my $aab = PVE::AAB->new();
25
26 $aab->writelog("aab: " . join(' ', @ARGV) . "\n");
27
28 my $cmd = shift @ARGV;
29 if (!$cmd) {
30 print_usage('missing command');
31 exit -1;
32 }
33
34 eval {
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 'keyring') {
60 # for debugging:
61
62 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
63 $aab->populate_keyring();
64
65 } elsif ($cmd eq 'basedir') {
66
67 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
68 print $aab->{rootfs} . "\n";
69
70 } elsif ($cmd eq 'veid') {
71
72 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
73 print $aab->{veid} . "\n";
74
75 } elsif ($cmd eq 'packagefile') {
76
77 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
78
79 print "$aab->{targetname}.tar.gz\n";
80
81 } elsif ($cmd eq 'finalize') {
82
83 $aab->finalize();
84
85 } elsif ($cmd eq 'install') {
86
87 my $required;
88 foreach my $arg (@ARGV) {
89 if ($arg =~ m/\.pkglist$/) {
90 open my $fh, $arg or
91 die "cant open package list '$arg' - $!";
92 while (defined (my $line = <$fh>)) {
93 chomp $line;
94 next if $line =~ m/^\s*$/;
95 next if $line =~ m/\#/;
96 if ($line =~ m/^\s*(\S+)\s*$/) {
97 push @$required, $1;
98 } else {
99 die "invalid package name in '$arg' - $line\n";
100 }
101 }
102 close ($fh);
103 } else {
104 push @$required, $arg;
105 }
106 }
107
108 $aab->install ($required);
109
110 } elsif ($cmd eq 'exec') {
111
112 $aab->ve_exec (@ARGV);
113
114 } elsif ($cmd eq 'enter') {
115
116 $aab->enter();
117
118 } elsif ($cmd eq 'clean') {
119
120 $aab->clean();
121
122 } elsif ($cmd eq 'dist-clean') {
123
124 $aab->clean(1);
125
126 } elsif ($cmd eq 'list') {
127
128 my $verbose;
129
130 if (!GetOptions ('verbose' =>\$verbose)) {
131 print_usage ();
132 exit (-1);
133 }
134
135 die "command '$cmd' expects no arguments.\n" if scalar (@ARGV) != 0;
136
137 my $query = '-Q';
138 $query .= 'q' if !$verbose;
139 print $aab->run_command(['chroot', $aab->{rootfs}, 'pacman', $query], undef, 1);
140
141 } else {
142
143 print_usage("invalid command '$cmd'");
144 exit (-1);
145
146 }
147 };
148
149 if (my $err = $@) {
150 $aab->logmsg($err);
151 die $err;
152 }
153
154 exit 0;