The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::LXC::Container::Setup - setup meta-configuration

SYNOPSIS

    lxc-app-setup <container>

ABSTRACT

This is the module used to maintain the meta-configuration of an LXC application container. It is called from lxc-app-setup via the main module App::LXC::Container.

DESCRIPTION

The module provides the user interface used to setup (create or update) the meta-configuration of an application container (which is later used by App::LXC::Container::Update to create the configuration for LXC itself). It can read, modify and write the meta-configuration of one container. On the first run it also initialises the whole system.

MAIN METHODS

The module defines the following main methods which are used by App::LXC::Container:

new - create configuration object for application container

    $configuration = App::LXC::Container::Setup->new($container);

parameters:

    $container          name of the container to be configured

description:

This is the constructor for the object used to create or update the configuration of an application container. If it is used for the very first time it creates a symbolic link to the configuration directory in the user's HOME directory. It also initialises the configuration directory if necessary. If a configuration with the given name already exist it is read, otherwise the object is initialised with the default values needed for a minimal container.

returns:

the configuration object for the application container

main - create and run main configuration window

    $configuration->main();

description:

This method creates and runs the actual application window used to create or modify the configuration of an application container.

HELPER METHODS / FUNCTIONS

The following methods and functions should not be used outside of this module itself:

_add_dialog - run file-selection dialog

    $self->_add_dialog($title, $directory, $code);

parameters:

    $title              string with title of the file-selection dialog
    $directory          starting directory of file-selection dialog
    $code               reference to subroutine invoked by OK button

description:

This method opens a file-selection dialog and runs the passed code reference when the dialog is finished with the OK button. It contains the common parts for _add_file and _add_package below.

_add_file - add item(s) to listbox via file-selection dialog

    $self->_add_file($title, $prefix, $listbox);

parameters:

    $title              string with title of the file-selection dialog
    $prefix             default marker as prefix
    $listbox            reference to UI element of the listbox

description:

This method opens a file-selection dialog and add the selected files and/or directories to the given listbox placing the given prefix in front of them.

_add_library_packages - add library item(s) to package listbox via FSD

    $self->_add_library_packages($listbox);

parameters:

    $listbox            reference to UI element of the listbox

description:

This method opens a file-selection dialog and add all package(s) containing a library used by the selected executable(s) to the package listbox.

_add_package - add item(s) to package listbox via file-selection dialog

    $self->_add_package($listbox);

parameters:

    $listbox            reference to UI element of the listbox

description:

This method opens a file-selection dialog and add the package(s) containing the selected files and/or directories to the package listbox.

_add_user - add one or more users

    $self->_add_user($listbox);

parameters:

    $listbox            reference to UI element of the listbox

description:

This method dialog to select one or more users from a list of regular users and adds them to the users listbox.

_create_main_window - create main configuration window

    $self->_create_main_window();

description:

This method creates the main configuration window.

_create_mw_listbox - create listbox area for main window

    my $box =
        _create_mw_listbox($title, $ra_list, $h, $w, $add, $modify [, $indirect]);

parameters:

    $title              string with title of the listbox area
    $ra_list            reference to array with content of the listbox
    $h                  height of listbox
    $w                  width of listbox
    $add                reference to function called to add entry
    $modify             optional reference to function called to modify entry
    $indirect           optional reference to function called to add dependencies

description:

This method creates each of the four listbox areas of the main configuration window. Note that the called functions get a reference to the listbox object as 1st parameter.

returns:

UI::Various::Box object containing listbox, title and controls

_create_or_compare - create or compare file from/to array

    _create_or_compare($path, @lines);

parameters:

    $path               absolute path to file
    @lines              array of output lines

description:

This function either creates the non-existing file at the give path and writes the array of output lines into it (using _write_to), or it compares the existing one against the array and reports differences as warning.

returns:

-1 if the file does not exist, 0 if it is equal and 1 otherwise

_help_dialog - display and run help dialog

    $self->_help_dialog();

description:

This method creates and runs the dialog with the help text.

_init_config_dir - initialise configuration directory

    $self->_init_config_dir();

description:

This method opens two file selection dialogues to choose the location of the toolbox's configuration directory and creates the symbolic link to it in the user's HOME directory. It also initialises the directory, if it is empty.

_init_fs_dialog - run file-selection dialog

    $self->_init_fs_dialog($title, $directory);

parameters:

    $title              string with title of the file-selection dialog
    $directory          starting directory of file-selection dialog

description:

This method opens a file-selection dialog and runs the passed code reference when the dialog is finished with the OK button. It contains the common parts for _add_file and _add_package below.

_mark2filter - translate UI file string into configuration line

    $output = _mark2filter($conf_str);

parameters:

    $conf_str           filter configuration string from UI

description:

This function translates an entry of the filter listbox in the UI into the output for the corresponding meta-configuration file.

returns:

configuration line for passed string

_mark2mount - translate UI file string into configuration line

    $output = _mark2mount($conf_str);

parameters:

    $conf_str           files configuration string from UI

description:

This function translates an entry of the files listbox in the UI into the output for the corresponding meta-configuration file.

returns:

configuration line for passed string

_modify_entry - modify an entry of a listbox

    $self->_modify_entry($title, $listbox, @alternatives);

example:

    $self->_modify_entry($title, $listbox,
                         '   ' => txt('__'),
                         'OV ' => txt('OV'),
                         'RW ' => txt('RW'));

parameters:

    $title              string with title of the file-selection dialog
    $listbox            reference to UI element of the listbox
    @alternatives       list of alternatives for the radio buttons

description:

This method opens a dialog with some radio buttons to modify the mode of the selected file or directory in the given listbox.

_modify_value - modify a (text) value of an entry of a listbox

    $self->_modify_value($listbox);

parameters:

    $listbox            reference to UI element of the listbox

description:

This method opens a minimal dialog to allow changing an entry of the given listbox.

_parse_filter - parse existing filter configuration file

    $self->_parse_filter();

description:

This method checks if the current container already has a filter meta-configuration file and parses its content into the object representing the container.

_parse_master - parse existing master configuration file

    $self->_parse_master();

description:

This method checks if the current container already has a master meta-configuration file and parses its content into the object representing the container.

_parse_mounts - parse existing mounts configuration file

    $self->_parse_mounts();

description:

This method checks if the current container already has a mounts meta-configuration file and parses its content into the object representing the container.

_parse_packages - parse existing packages configuration file

    $self->_parse_packages();

description:

This method checks if the current container already has a packages meta-configuration file and parses its content into the object representing the container.

_save_configuration - save currnent meta-configuration

    $self->_save_configuration();

description:

This method saves the current meta-configuration.

_write_to - write array to file

    _write_to($path, @lines);

parameters:

    $path               absolute path to file
    @lines              array of output lines

description:

This function opens the file at the give path and writes the array of output lines into it. If the file already exists and is not writable, the function returns without changing anything. If anything else goes wrong, the function aborts the whole script.

SEE ALSO

man pages lxc.container.conf, lxc and lxcfs

LXC documentation on https://linuxcontainers.org

LICENSE

Copyright (C) Thomas Dorner.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See LICENSE file for more details.

AUTHOR

Thomas Dorner <dorner (at) cpan (dot) org>

Contributors

none so far