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