#!/usr/bin/perl -wT
# #
# Software subject to following license(s):
#   Apache 2 License (http://www.opensource.org/licenses/apache2.0)
#   Copyright (c) Responsible Organization
#

# #
# Current developer(s):
#   Luis Fernando Muñoz Mejías <Luis.Munoz@UGent.be>
#   Ronald Starink <ronalds@nikhef.nl>
#

# #
# Author(s): Michel Jouvin, Ben Jones, Gabor Gombas, Nick Williams, Stijn De Weirdt
#

# #
# server, 26.2.0, 1, Tue Apr 07 2026
#
################################################################################

# This is aii-shellfe, a aii's file

=encoding utf8

=pod

=head1 NAME

aii-shellfe - AII local management utility.

The aii-shellfe program configures, marks for install or for local
boot the nodes given as arguments. It loads and runs any AII plug-ins
specified in the profile.

=head1 SYNOPSIS

 aii-shellfe --cdburl URL [options]
                       <--boot <hostname|regexp>      |
                        --bootlist <filename>         |
                        --configure <hostname|regexp> |
                        --configurelist <filename>    |
                        --include <directories...>    |
                        --install <hostname|regexp>   |
                        --installlist <filename>      |
                        --remove <hostname|regexp>    |
                        --removelist <filename> >     |
                        --removeall                   |
                        --reinstall <hostname|regexp> |
                        --rescue <hostname|regexp>    |
                        --rescuelist <filename>       |
                        --status <hostname|regexp>    |
                        --statuslist <filename> >     |
                        --firmware <hostname|regexp>  |
                        --firmwarelist <filename>     |
                        --livecd <hostname|regexp>    |
                        --livecdlist <filename>       |
                        --file <filename>

C<--removeall>, is not ready yet.

=head1 DESCRIPTION

aii-shellfe is the user frontend for the quattor Automated
Installation Infrastructure. aii-shellfe is used to automatically
manage DHCP, the Network Bootstrap Program (NBP), and the OS
installer. It instantiates
and configures NCM components for configuring these systems.

aii-shellfe can be used locally, or remotely called with
aii-installfe.

Input data can be specified via the command line (for just one host)
or via a text file (for more than one host). Perl regular expressions
(see EXAMPLES) instead of hostnames are supported (only in case of
command line options). The only limitation is that, if your regular
expression contains a dot (.), you must specify --use_fqdn.

Note that you have to configure (command --configure) the client nodes
before to mark them for the installation or to boot from local disk.

aii-shellfe needs the URL for the location of the CDB. Instead of
CDB, a plain http(s) server may be used to fetch the profiles. It is
recommended to store this parameter in the aii-shellfe.conf
configuration file.

=head1 COMMANDS

=over 4

=item --boot <hostname|regexp>

Select boot from local disk for <hostname> or for all hostnames that
match the Perl regular expression <regexp>

=item --bootlist <filename>

Select boot from local disk for hosts listed on <filename>. Each line
should contain one host name. Lines starting with a # are comment
lines.

=item --install <hostname|regexp>

Select to install <hostname> or all hostnames that match the Perl
regular expression <regexp>

=item --installlist <filename>

Select to install the hosts listed in <filename>. Each line should
contain one host name. Lines starting with a # are comment lines.

=item --configure <hostname|regexp>

Configure <hostname> or all hostnames that match the Perl regular
expression <regexp>

=item --configurelist <filename>

Configure hosts listed in <filename>. Each line should contain one
host name. Lines starting with a # are comment lines.

=item --include <directories...>

A colon-separated list of directories to add to the search path
for perl plugins.

=item --remove <hostname|regexp>

Remove the configuration for <hostname> or all hostnames that match
the Perl regular expression <regexp>

=item --removelist <filename>

Remove configurations for hosts listed in <filename>. Each line should
contain one host name. Lines starting with a # are comment lines.

=item --removeall

Remove configurations for *ALL* hosts configured. Useful only in case
of problems/test (note that DHCP configuration is not affected by this
command).

=item --reinstall

Remove, (re)configure and (re)install the configuration for <hostname>
or all hostnames that match the Perl regular expression <regexp>
(i.e. C<--reinstall host> is equal to
C<--remove host --configure host --install host>).

=item --status <hostname|regexp>

Report the boot status (boot from local disk/install) for <hostname>
or for all hostnames that match the Perl regular expression <regexp>

=item --statuslist <filename>

Report the boot status (boot from local disk/install) for hosts listed
in <filename>. Each line should contain one host name. Lines starting
with a # are comment lines.

=item --firmware

Select the firmware installation target for <hostname>. Perl regular expressions
can be used.

=item --firmwarelist <filename>

Select firmware installation for the hosts listed in <filename>. Hosts have to
be listed one per line. Lines starting with # are comment.

=item --livecd

Select the livecd installation target for <hostname>. Perl regular expressions
can be used.

=item --livecdlist <filename>

Select livecd installation for the hosts listed in <filename>. Hosts have to
be listed one per line. Lines starting with # are comment.

=item --rescue <hostname|regexp>

Use the Rescue image (LOCATION) to boot <hostname> or all hostnames
that match the Perl regular expression <regexp>.

=item --rescuelist <filename>

Use the Rescue image (LOCATION) to boot the hosts listed in
<filename>.  Each line should contain one host name. Lines starting
with a # are comment lines.

=item --file <filename>

Read the actions and hosts from the specified file. This file
allows you to specify both the action and the hostname at
the same time.
Each line should
be of the form:
   hostname,action[,argument]
The action is one of the
defined actions such as 'configure', 'install', etc. The
optional argument is for the use of the specified action.
The value of the filename may be '-' in which case stdin
is used (this feature is not available on any of the other
file-based options).

=back

=head1 OPTIONS

=over 4

=item --nodiscovery

Do not update DHCP configuration. Valid only with --configure command.

=item --nonbp

Do not update NBP configuration. Valid only with --configure command.

=item --noosinstall

Do not update OS installer configuration. Valid only with --configure
command.

=item --cdburl <url>

URL for CDB location

Known profiles are determined via the C<profiles-info.xml> file.

In case the C<dir:///path/profile/directory> is used,
all profiles in that directory are considered usable via C<file://>
url.

=back

=head2 Other Options

=over

=item --help

Displays a help message with all options and default settings.

=item --version

Displays program version information.

=item --debug <1..5>

Set the debugging level to <1..5>.

=item --cfgfile <path>

Use as configuration file <path> instead of the default configuration
file /etc/aii/aii-shellfe.conf.

=item --logfile <file>

Store and append log messages in <file>.

=item --noaction

Compute and show the operations, but do not execute them. The
components must accept $NoAction.

=item --use_fqdn

When retrieving profiles, keep the fully qualified domain name in the
name of the profile (if specified). Otherwise, the domain name will be
stripped. Use this also if your regular expressions contain a dot.

=item --profile_prefix <prefix>

Set the prefix for the profile names that AII will fetch from the CDB.
The default is 'profile_'. To disable the usage of a prefix, set
profile_prefix to an empty string in the configuration file
/etc/aii/aii-shellfe.conf.

=item --cachedir <dir>

The location to cache foreign profiles. This defaults to /tmp/aii.

=item --lockdir <dir>

The location where node lock files are stored. This defaults to /var/lock/quattor.

=back

=head1 CONFIGURATION FILE

Default values of command lines options can be specified in the file
/etc/aii/aii-shellfe.conf using syntax:

 <option> = <value>

Also, for fetching the profiles, /etc/ccm.conf must exist and be
correct.

=head1 EXAMPLES

E.g. to get the status of all nodes:

 aii-shellfe --status .+ --use_fqdn

To prepare configuration files for grid001, grid002, grid005:

 aii-shellfe --configure grid00[125]

To set as "to be installed" grid001 and grid002:

 aii-shellfe --install grid00[12]


=head1 RETURN

On success, aii-shellfe returns 0. Fatal errors are indicated by
return value 1.  When non-fatal errors occur, aii-shellfe returns
16.

=head1 SEE ALSO

L<aii-components(8)>, L<aii-hooks(8)>,
L<aii(8)>

=cut

package main;

BEGIN {
        push (@INC, '/usr/lib/perl');
}

use strict;
use warnings;

use CAF::Object;
use AII::Shellfe;

$ENV{PATH} = join (":", qw (/bin /usr/bin /usr/sbin /sbin));

use LC::Exception qw (SUCCESS throw_error);

our $this_app = AII::Shellfe->new ($0, @ARGV) or exit 1;
our %SIG;
our $ec = LC::Exception::Context->new->will_store_errors;
$CAF::Object::NoAction = 1 if $this_app->option('noaction');


$this_app->cmds;
$this_app->finish;

exit ($this_app->{status});
