|
|
b7b189 |
#!/bin/bash
|
|
|
b7b189 |
#
|
|
|
b7b189 |
# cli_getFilesList.sh -- This function defines the list of FILES to
|
|
|
b7b189 |
# process.
|
|
|
b7b189 |
#
|
|
|
92e46a |
# Copyright (C) 2009-2011 Alain Reguera Delgado
|
|
|
b7b189 |
#
|
|
|
b7b189 |
# This program is free software; you can redistribute it and/or
|
|
|
b7b189 |
# modify it under the terms of the GNU General Public License as
|
|
|
b7b189 |
# published by the Free Software Foundation; either version 2 of the
|
|
|
b7b189 |
# License, or (at your option) any later version.
|
|
|
b7b189 |
#
|
|
|
b7b189 |
# This program is distributed in the hope that it will be useful, but
|
|
|
b7b189 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
b7b189 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
b7b189 |
# General Public License for more details.
|
|
|
b7b189 |
#
|
|
|
b7b189 |
# You should have received a copy of the GNU General Public License
|
|
|
b7b189 |
# along with this program; if not, write to the Free Software
|
|
|
b7b189 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
b7b189 |
# USA.
|
|
|
b7b189 |
#
|
|
|
b7b189 |
# ----------------------------------------------------------------------
|
|
|
b7b189 |
# $Id$
|
|
|
b7b189 |
# ----------------------------------------------------------------------
|
|
|
b7b189 |
|
|
|
b7b189 |
function cli_getFilesList {
|
|
|
b7b189 |
|
|
|
8eeb3a |
local LOCATION=''
|
|
|
8eeb3a |
|
|
|
8eeb3a |
# If first argument is provided to cli_getFilesList, use it as
|
|
|
8eeb3a |
# default location. Otherwise, if first argument is not provided,
|
|
|
8eeb3a |
# location takes the action value (ACTIONVAL) as default.
|
|
|
8eeb3a |
if [[ "$1" != '' ]];then
|
|
|
8eeb3a |
LOCATION="$1"
|
|
|
8eeb3a |
else
|
|
|
8eeb3a |
LOCATION="$ACTIONVAL"
|
|
|
8eeb3a |
fi
|
|
|
8eeb3a |
|
|
|
4a9a32 |
# Define regular expression (REGEX) local variable, using regular
|
|
|
4a9a32 |
# expression (REGEX) global variable, to reduce the amount of
|
|
|
4a9a32 |
# characters we type in order to match find's output. When using
|
|
|
4a9a32 |
# regular expression with find, in order to reduce the amount
|
|
|
4a9a32 |
# files found, the regular expression is evaluated against the
|
|
|
4a9a32 |
# whole file path. This way, when the regular expression is
|
|
|
4a9a32 |
# specified, we need to build it in a way that matches the whole
|
|
|
4a9a32 |
# path. Doing so each time we pass a `--filter' command-line
|
|
|
4a9a32 |
# argument may be a tedious task, so, in the sake of reducing some
|
|
|
4a9a32 |
# typing, we prepare the regular expression here to match the
|
|
|
4a9a32 |
# whole path using the regular expression provided by the user as
|
|
|
4a9a32 |
# pattern.
|
|
|
4a9a32 |
local REGEX="^${LOCATION}/${REGEX}$"
|
|
|
8eeb3a |
|
|
|
8eeb3a |
# Define list of files to process.
|
|
|
8eeb3a |
if [[ -d $LOCATION ]];then
|
|
|
4a9a32 |
FILES=$(find $LOCATION -regextype posix-egrep -type f -regex "${REGEX}" | sort)
|
|
|
8eeb3a |
elif [[ -f $LOCATION ]];then
|
|
|
8eeb3a |
FILES=$LOCATION
|
|
|
8eeb3a |
fi
|
|
|
8eeb3a |
|
|
|
8eeb3a |
# Check list of files to process. If we have an empty list of
|
|
|
8eeb3a |
# files, inform about it and stop script execution.
|
|
|
8eeb3a |
if [[ $FILES == '' ]];then
|
|
|
4cbc7a |
cli_printMessage "`gettext "There is no file to process."`" 'AsErrorLine'
|
|
|
8eeb3a |
cli_printMessage "$(caller)" 'AsToKnowMoreLine'
|
|
|
b7b189 |
fi
|
|
|
b7b189 |
|
|
|
b7b189 |
}
|