Blame Documentation/Manpages/tcar_checkFiles.sh.asciidoc

Alain Reguera Delgado e54180
tcar_checkFiles(1)
Alain Reguera Delgado e54180
==================
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== Name
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
tcar_checkFiles - Standardize constructions for file verifications.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== Synopsis
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
*cli_checkFiles [-d|-e|-f|-h|-x] LOCATION*
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== Description
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
The *cli_checkFiles* exists to answer basic questions like ``Is
Alain Reguera Delgado e54180
+LOCATION+ is a regular file?'' and ``Is +LOCATION+ a directory?''.
Alain Reguera Delgado e54180
The answer to such questions affects the script execution flow in the
Alain Reguera Delgado e54180
following way: when the answer positive (e.g., +LOCATION+ is a regular
Alain Reguera Delgado e54180
file), the script passes the test silently and continues its
Alain Reguera Delgado e54180
execution.  When the answer is negative(e.g., +LOCATION+ is not a
Alain Reguera Delgado e54180
regular file), the script finishes its execution immediately with an
Alain Reguera Delgado e54180
error message.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
The *cli_checkFiles* function is exported to *centos-art.sh* script
Alain Reguera Delgado e54180
environment in the very beginning of its execution and will be
Alain Reguera Delgado e54180
available all along its execution lifetime. You can use this function
Alain Reguera Delgado e54180
inside common and specific functions whenever you need to verify files
Alain Reguera Delgado e54180
inside the The CentOS Artwork Repository.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
The *cli_checkFiles* function is available inside the *centos-art.sh*
Alain Reguera Delgado e54180
script only as part of its execution environment. This function is
Alain Reguera Delgado e54180
exported to *centos-art.sh* script just after executing the script
Alain Reguera Delgado e54180
from the command-line and will be available all along the script
Alain Reguera Delgado e54180
lifetime. So, you can use this function both in common and specific
Alain Reguera Delgado e54180
functionalities of centos-art.sh script.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
The *cli_checkFiles* function doesn't create
Alain Reguera Delgado e54180
subsequent execution environments.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== Usage
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
Use the *cli_checkFiles* function inside *centos-art.sh* script
Alain Reguera Delgado e54180
whenever you need to control the script execution flow based on file
Alain Reguera Delgado e54180
type (e.g., regular files, directories, links, etc.) verifications.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== Options
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
The *cli_checkFiles* function accepts the following options:
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
-d::
Alain Reguera Delgado e54180
    Verifies whether +LOCATION+ exists and is a directory. If it
Alain Reguera Delgado e54180
    doesn't exists or isn't a directory, an error message is printed
Alain Reguera Delgado e54180
    and the script finishes its execution.  Otherwise, if it exists
Alain Reguera Delgado e54180
    and is a directory, the script continues its execution normally.
Alain Reguera Delgado e54180
-e::
Alain Reguera Delgado e54180
    Verifies whether +LOCATION+ exists or not. If it doesn't exist, an
Alain Reguera Delgado e54180
    error message is printed and the script finishes its execution.
Alain Reguera Delgado e54180
    Otherwise, if it does exists, the script continues its execution
Alain Reguera Delgado e54180
    normally.
Alain Reguera Delgado e54180
-f::
Alain Reguera Delgado e54180
    Verifies whether +LOCATION+ exists and is a regular file. If it
Alain Reguera Delgado e54180
    doesn't exists or isn't a regular file, an error message is
Alain Reguera Delgado e54180
    printed and the script finishes its execution.  Otherwise, if it
Alain Reguera Delgado e54180
    exists and is a regular file, the script continues its execution
Alain Reguera Delgado e54180
    normally.
Alain Reguera Delgado e54180
-h::
Alain Reguera Delgado e54180
    Verifies whether +LOCATION+ exists and is a symbolic link. If it
Alain Reguera Delgado e54180
    doesn't exists or isn't a symbolic link, an error message is
Alain Reguera Delgado e54180
    printed and the script finishes its execution immediately.
Alain Reguera Delgado e54180
    Otherwise, if it does exist and is a symbolic link, the script
Alain Reguera Delgado e54180
    continue its execution normally.
Alain Reguera Delgado e54180
-x::
Alain Reguera Delgado e54180
    Verifies whether +LOCATION+ exists and execution permission is
Alain Reguera Delgado e54180
    granted. If it doesn't exist or hasn't execution permission, the
Alain Reguera Delgado e54180
    script finishes its execution immediately. Otherwise, if it exists
Alain Reguera Delgado e54180
    and has execution permissions, the script continues its execution
Alain Reguera Delgado e54180
    normally.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
The value of the +LOCATION+ argument must be an absolute path to the
Alain Reguera Delgado e54180
file you want to verify. If such file doesn't exists in any supported
Alain Reguera Delgado e54180
form, the script finishes its execution with an error message.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== Examples
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
The following example was taken from *centos-art.sh* script
Alain Reguera Delgado e54180
initialization phase.  Notice the position of *cli_checkFiles*
Alain Reguera Delgado e54180
function inside the loop. If some of the function files we need to
Alain Reguera Delgado e54180
export doesn't have execution rights, *cli_checkFiles* will finish the
Alain Reguera Delgado e54180
script execution immediately with an error message.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
----------------------------------------------------------------------
Alain Reguera Delgado e54180
for FUNCFILE in ${FUNCFILES};do
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
    # Verify the execution rights for function file.
Alain Reguera Delgado e54180
    cli_checkFiles -x ${FUNCFILE}
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
    # Initialize the function file.
Alain Reguera Delgado e54180
    . ${FUNCFILE}
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
    # Export the function names inside the file to current shell
Alain Reguera Delgado e54180
    # script environment.
Alain Reguera Delgado e54180
    export -f $(egrep "${PATTERN}" ${FUNCFILE} | gawk '{ print $2 }')
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
done
Alain Reguera Delgado e54180
----------------------------------------------------------------------
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== Bugs
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
See https://centos.org.cu/bugs/
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== Authors
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
The *tcar_checkFiles* function has received contributions from the
Alain Reguera Delgado e54180
following people:
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
- Alain Reguera Delgado <al@centos.org.cu>, =COPYRIGHT_YEAR_LIST=
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
== License
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
Copyright (C) =COPYRIGHT_YEAR_LIST= =COPYRIGHT_HOLDER=
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado e54180
it under the terms of the GNU General Public License as published by
Alain Reguera Delgado e54180
the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado e54180
your option) any later version.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado e54180
WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado e54180
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado e54180
General Public License for more details.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
You should have received a copy of the GNU General Public License
Alain Reguera Delgado e54180
along with this program; if not, write to the Free Software
Alain Reguera Delgado e54180
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado e54180
Alain Reguera Delgado e54180
// vim: set syntax=asciidoc: