|
|
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
|
|
|
fa95b1 |
#
|
|
|
fa95b1 |
# This program is free software; you can redistribute it and/or modify
|
|
|
fa95b1 |
# it under the terms of the GNU General Public License as published by
|
|
|
fa95b1 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
fa95b1 |
# (at your option) any later version.
|
|
|
fa95b1 |
#
|
|
|
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 |
# $Id$
|
|
|
b7b189 |
# ----------------------------------------------------------------------
|
|
|
b7b189 |
|
|
|
b7b189 |
function cli_getFilesList {
|
|
|
b7b189 |
|
|
|
8eeb3a |
local LOCATION=''
|
|
|
f5c4be |
local FILTER=''
|
|
|
f5c4be |
local FILES=''
|
|
|
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 |
|
|
|
f5c4be |
# If second argument is provided to cli_getFilesList, use it as
|
|
|
f5c4be |
# default extension to look for files. Otherwise, if second
|
|
|
f5c4be |
# argument is not provided, use flag filter instead.
|
|
|
f5c4be |
if [[ "$2" != '' ]];then
|
|
|
f5c4be |
FILTER="$2"
|
|
|
f5c4be |
else
|
|
|
f5c4be |
FILTER="$FLAG_FILTER"
|
|
|
f5c4be |
fi
|
|
|
f5c4be |
|
|
|
f5c4be |
# Define filter as regular expression pattern. When we use regular
|
|
|
f5c4be |
# expressions with find, regular expressions are evaluated against
|
|
|
f5c4be |
# the whole file path. This way, when the regular expression is
|
|
|
4a9a32 |
# specified, we need to build it in a way that matches the whole
|
|
|
f5c4be |
# path. Doing so, everytime we pass the `--filter' option in the
|
|
|
385cc4 |
# command-line could be a tedious task. Instead, in the sake of
|
|
|
f5c4be |
# reducing some typing, we prepare the regular expression here to
|
|
|
f5c4be |
# match the whole path using the regular expression provided by
|
|
|
385cc4 |
# the user as pattern. Do not use LOCATION variable as part of
|
|
|
385cc4 |
# regular expresion so it could be possible to use path expansion.
|
|
|
385cc4 |
# Using path expansion reduce the amount of places to find out
|
|
|
385cc4 |
# things and so the time required to finish the task.
|
|
|
385cc4 |
FILTER="^.+/${FILTER}$"
|
|
|
8eeb3a |
|
|
|
385cc4 |
# Define list of files to process. At this point we cannot verify
|
|
|
385cc4 |
# whether the LOCATION is a directory or a file since path
|
|
|
385cc4 |
# expansion coul be introduced to it. The best we can do is
|
|
|
385cc4 |
# verifying exit status and go on.
|
|
|
385cc4 |
FILES=$(find ${LOCATION} -regextype posix-egrep -regex "${FILTER}" | sort | uniq)
|
|
|
8eeb3a |
|
|
|
d1225f |
# Output list of files to process.
|
|
|
385cc4 |
if [[ $? -eq 0 ]];then
|
|
|
385cc4 |
echo "$FILES"
|
|
|
385cc4 |
fi
|
|
|
b7b189 |
|
|
|
b7b189 |
}
|