Blame Artworks/Documentation/Repository/UserGuide/Docbook/Tcar-ug/Scripts/Bash/cli_checkFiles.docbook

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