Skip to content

Commit

Permalink
aii-core: add AII::commands_hook hook module
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird committed Nov 12, 2024
1 parent 834b9ed commit 03f54be
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions aii-core/src/main/perl/commands_hook.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#${PMpre} AII::commands_hook${PMpost}

=pod
=head1 Hooks for customizing kickstart by inserting verbatim (bash) commands
type aii_commands_hook = {
"module" : string = 'commands_hooks'
"commands" : string[]
};
bind "/system/aii/hooks/post_reboot/0" = aii_commands_hook;
"/system/aii/hooks/post_reboot/0/commands" = list(
"dmesg | tail 100",
"lspci | grep -i vendor",
);
Will generate additional text in the post_reboot section of the kickstart script.
# Start hook commands
dmesg | tail 100
lspci | grep -i vendor
# End hook commands
Be aware that certain hooks are used in e.g. bash heredoc constructions, so they might need
extra treatment like escaping bash variables.
=cut

use strict;
use warnings;

sub new {
my $class = shift;
return bless {}, $class;
}


sub _print {
my ($self, $config, $path) = @_;

my $hook_tree = $config->getTree($path);
my $commands = $hook_tree->{commands} || [];

if (@$commands) {
print "# Start hook commands\n";
print join("\n", @$commands);
print "\n# End hook commands\n";
}
}


no strict 'refs';
foreach my $i (qw(pre_install pre_install_end post_reboot post_reboot_end
post_install_nochroot post_install anaconda pre_reboot)) {
*{$i} = sub {
my ($self, @args) = @_;
return $self->_print(@args);
}
}
use strict 'refs';

0 comments on commit 03f54be

Please sign in to comment.