Blame Documentation/Models/Docbook/Tcar-ug/Scripts/Bash/cli_checkFiles.docbook

e0e02e
<refentry id="scripts-bash-cli_checkFiles">
e0e02e
e0e02e
    <refmeta>
e0e02e
        <refentrytitle>cli_checkFiles</refentrytitle>
e0e02e
        <manvolnum>1</manvolnum>
e0e02e
        <indexterm type="common-function">
e0e02e
            <primary>Standardize constructions for file verifications</primary>
e0e02e
        </indexterm>
e0e02e
    </refmeta>
e0e02e
e0e02e
    <refnamediv>
e0e02e
        <refname>cli_checkFiles</refname>
e0e02e
        <refpurpose>Standardize constructions for file verifications.</refpurpose>
e0e02e
    </refnamediv>
e0e02e
e0e02e
    <refsynopsisdiv>
e0e02e
    <cmdsynopsis>
e0e02e
        <command>cli_checkFiles</command> 
e0e02e
        <arg choice="req">
e0e02e
            <arg>-d</arg>
e0e02e
            <arg>-e</arg>
e0e02e
            <arg>-f</arg>
e0e02e
            <arg>-h</arg>
e0e02e
            <arg>-x</arg>
e0e02e
        </arg>
e0e02e
        <arg choice="req" rep="repeat"><replaceable>LOCATION</replaceable></arg>
e0e02e
    </cmdsynopsis>
e0e02e
    </refsynopsisdiv>
9fb7a6
e0e02e
    <refsection id="scripts-bash-cli_checkFiles-description">
e0e02e
    <title>Description</title>
e0e02e
    <para>
e0e02e
        The <function>cli_checkFiles</function> exists to answer basic
e0e02e
        questions like <quote>Is <replaceable>LOCATION</replaceable>
e0e02e
        is a regular file?</quote> and <quote>Is
e0e02e
        <replaceable>LOCATION</replaceable> a directory?</quote>. The
e0e02e
        answer to such questions affects the script execution flow in
e0e02e
        the following way: when the answer positive (e.g.,
e0e02e
        <replaceable>LOCATION</replaceable> is a regular file), the
e0e02e
        script passes the test silently and continues its execution.
e0e02e
        When the answer is negative(e.g.,
e0e02e
        <replaceable>LOCATION</replaceable> is not a regular file),
e0e02e
        the script finishes its execution immediately with an error
e0e02e
        message.
e0e02e
    </para>
9fb7a6
9fb7a6
    <para>
e0e02e
        The <function>cli_checkFiles</function> function is exported
e0e02e
        to <command>centos-art.sh</command> script environment in the
40baf3
        very beginning of its execution and will be available all
40baf3
        along its execution lifetime. You can use this function inside
40baf3
        common and specific functions whenever you need to verify
40baf3
        files inside the &TCAR;.
9fb7a6
    </para>
9fb7a6
9fb7a6
    <para>
e0e02e
        The <function>cli_checkFiles</function> function is available
e0e02e
        inside the <command>centos-art.sh</command> script only as
e0e02e
        part of its execution environment. This function is exported
e0e02e
        to <command>centos-art.sh</command> script just after
e0e02e
        executing the script from the command-line and will be
e0e02e
        available all along the script lifetime. So, you can use this
e0e02e
        function both in common and specific functionalities of
e0e02e
        centos-art.sh script.
9fb7a6
    </para>
9fb7a6
9fb7a6
    <para>
e0e02e
        The <function>cli_checkFiles</function> function doesn't
e0e02e
        create subsequent execution environments.
9fb7a6
    </para>
e0e02e
    </refsection>
9fb7a6
e0e02e
    <refsection id="scripts-bash-cli_checkFiles-usage">
e0e02e
    <title>Usage</title>
e0e02e
    <para>
e0e02e
        Use the <function>cli_checkFiles</function> function inside
e0e02e
        <command>centos-art.sh</command> script whenever you need to
e0e02e
        control the script execution flow based on file type (e.g.,
e0e02e
        regular files, directories, links, etc.) verifications.
e0e02e
    </para>
e0e02e
    </refsection>
9fb7a6
e0e02e
    <refsection id="scripts-bash-cli_checkFiles-options">
9fb7a6
    <title>Options</title>
9fb7a6
    <para>
9fb7a6
        The <function>cli_checkFiles</function> function accepts the
9fb7a6
        following options:
9fb7a6
    </para>
9fb7a6
    <variablelist>
9fb7a6
    <varlistentry>
9fb7a6
    <term><option>-d</option></term>
9fb7a6
    <listitem>
9fb7a6
    <para>
9fb7a6
        Verifies whether <replaceable>LOCATION</replaceable> exists
9fb7a6
        and is a directory. If it doesn't exists or isn't a directory,
9fb7a6
        an error message is printed and the script finishes its
9fb7a6
        execution.  Otherwise, if it exists and is a directory, the
9fb7a6
        script continues its execution normally.
9fb7a6
    </para>
9fb7a6
    </listitem>
9fb7a6
    </varlistentry>
9fb7a6
9fb7a6
    <varlistentry>
9fb7a6
    <term><option>-e</option></term>
9fb7a6
    <listitem>
9fb7a6
    <para>
9fb7a6
        Verifies whether <replaceable>LOCATION</replaceable> exists or
9fb7a6
        not. If it doesn't exist, an error message is printed and the
9fb7a6
        script finishes its execution.  Otherwise, if it does exists,
9fb7a6
        the script continues its execution normally.
9fb7a6
    </para>
9fb7a6
    </listitem>
9fb7a6
    </varlistentry>
9fb7a6
9fb7a6
    <varlistentry>
9fb7a6
    <term><option>-f</option></term>
9fb7a6
    <listitem>
9fb7a6
    <para>
9fb7a6
        Verifies whether <replaceable>LOCATION</replaceable> exists
9fb7a6
        and is a regular file. If it doesn't exists or isn't a regular
9fb7a6
        file, an error message is printed and the script finishes its
9fb7a6
        execution. Otherwise, if it exists and is a regular file, the
9fb7a6
        script continues its execution normally.
9fb7a6
    </para>
9fb7a6
    </listitem>
9fb7a6
    </varlistentry>
9fb7a6
9fb7a6
    <varlistentry>
9fb7a6
    <term><option>-h</option></term>
9fb7a6
    <listitem>
9fb7a6
    <para>
9fb7a6
        Verifies whether <replaceable>LOCATION</replaceable> exists
9fb7a6
        and is a symbolic link. If it doesn't exists or isn't a
9fb7a6
        symbolic link, an error message is printed and the script
9fb7a6
        finishes its execution immediately.  Otherwise, if it does
9fb7a6
        exist and is a symbolic link, the script continue its
9fb7a6
        execution normally.
9fb7a6
    </para>
9fb7a6
    </listitem>
9fb7a6
    </varlistentry>
9fb7a6
9fb7a6
    <varlistentry>
9fb7a6
    <term><option>-x</option></term>
9fb7a6
    <listitem>
9fb7a6
    <para>
9fb7a6
        Verifies whether <replaceable>LOCATION</replaceable> exists
9fb7a6
        and execution permission is granted. If it doesn't exist or
9fb7a6
        hasn't execution permission, the script finishes its execution
9fb7a6
        immediately. Otherwise, if it exists and has execution
9fb7a6
        permissions, the script continues its execution normally.
9fb7a6
    </para>
9fb7a6
    </listitem>
9fb7a6
    </varlistentry>
9fb7a6
    </variablelist>
9fb7a6
9fb7a6
    <para>
9fb7a6
        The value of the <replaceable>LOCATION</replaceable> argument
9fb7a6
        must be an absolute path to the file you want to verify. If
e0e02e
        such file doesn't exists in any supported form, the script
9fb7a6
        finishes its execution with an error message.
9fb7a6
    </para>
e0e02e
    </refsection>
e0e02e
e0e02e
    <refsection id="scripts-bash-cli_checkFiles-example">
e0e02e
    <title>Examples</title>
e0e02e
    <para>
e0e02e
        The following example was taken from
e0e02e
        <command>centos-art.sh</command> script initialization phase.
e0e02e
        Notice the position of <function>cli_checkFiles</function>
e0e02e
        function inside the loop. If some of the function files we
e0e02e
        need to export doesn't have execution rights,
e0e02e
        <function>cli_checkFiles</function> will
e0e02e
        finish the script execution immediately with an error message.
e0e02e
    </para>
e0e02e
<programlisting language="bash">
e0e02e
# Process the list of files.
e0e02e
for FUNCFILE in $FUNCFILES;do
e0e02e
e0e02e
    # Verify the execution rights for function file.
e0e02e
    cli_checkFiles -x ${FUNCFILE}
e0e02e
  
e0e02e
    # Initialize the function file.
e0e02e
    . ${FUNCFILE}
e0e02e
  
e0e02e
    # Export the function names inside the file to current shell
e0e02e
    # script environment.
e0e02e
    export -f $(egrep "${PATTERN}" ${FUNCFILE} | gawk '{ print $2 }')
e0e02e
  
e0e02e
done
e0e02e
</programlisting>
e0e02e
    </refsection>
e0e02e
e0e02e
    <refsection>
e0e02e
    <title>Bugs</title>
e0e02e
    <para>
e0e02e
        To report bugs related to this function, please create a new
e0e02e
        ticket at 
e0e02e
        url="https://projects.centos.org/trac/artwork" /> refering the
e0e02e
        name of this function clearly and the specific problems you
e0e02e
        found in it.
e0e02e
    </para>
e0e02e
    </refsection>
e0e02e
e0e02e
    <refsection id="scripts-bash-cli_checkFiles-authors">
9fb7a6
    <title>Authors</title>
9fb7a6
    <itemizedlist>
9fb7a6
    <listitem>
9fb7a6
    <para>
9fb7a6
        Alain Reguera Delgado <email>alain.reguera@gmail.com</email>, =COPYRIGHT_YEAR_LIST=
9fb7a6
    </para>
9fb7a6
    </listitem>
9fb7a6
    </itemizedlist>
e0e02e
    </refsection>
9fb7a6
e0e02e
    <refsection id="scripts-bash-cli_checkFiles-licence">
9fb7a6
    <title>License</title>
9fb7a6
9fb7a6
    <para>
9fb7a6
        Copyright © =COPYRIGHT_YEAR_LIST= The CentOS Project
9fb7a6
    </para>
9fb7a6
 
9fb7a6
    <para>
9fb7a6
        This program is free software; you can redistribute it and/or
9fb7a6
        modify it under the terms of the GNU General Public License as
9fb7a6
        published by the Free Software Foundation; either version 2 of
9fb7a6
        the License, or (at your option) any later version.
9fb7a6
    </para>
9fb7a6
 
9fb7a6
    <para>
9fb7a6
        This program is distributed in the hope that it will be
9fb7a6
        useful, but WITHOUT ANY WARRANTY; without even the implied
9fb7a6
        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9fb7a6
        PURPOSE.  See the GNU General Public License for more details.
9fb7a6
    </para>
9fb7a6
 
9fb7a6
    <para>
9fb7a6
        You should have received a copy of the GNU General Public
9fb7a6
        License along with this program; if not, write to the Free
9fb7a6
        Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
9fb7a6
        USA.
9fb7a6
    </para>
e0e02e
    </refsection>
e0e02e
e0e02e
</refentry>
9fb7a6