From fc825f465bb815e4927ce10a8fd44442ea7d23ca Mon Sep 17 00:00:00 2001 From: stdweird Date: Sun, 10 Nov 2024 10:56:04 +0100 Subject: [PATCH] aii-core: add AII::commands_hook hook module --- aii-core/src/main/perl/commands_hook.pm | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 aii-core/src/main/perl/commands_hook.pm diff --git a/aii-core/src/main/perl/commands_hook.pm b/aii-core/src/main/perl/commands_hook.pm new file mode 100644 index 00000000..c698601b --- /dev/null +++ b/aii-core/src/main/perl/commands_hook.pm @@ -0,0 +1,65 @@ +#${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) = @_; + if ($self->{log}) { + return $self->{log}->$i(@args); + } else { + return; + } + } +} +use strict 'refs';