|
|
878a2b |
#!/bin/bash
|
|
|
878a2b |
#
|
|
|
878a2b |
# cli_checkFiles.sh -- This function standardizes the way file
|
|
|
878a2b |
# conditional expressions are applied inside centos-art.sh script.
|
|
|
878a2b |
# Here is where we answer questions like: is the file a regular file
|
|
|
878a2b |
# or a directory? or, is it a symbolic link? or even, does it have
|
|
|
878a2b |
# execution rights, etc. If the verification fails somehow at any
|
|
|
80c9e6 |
# point, an error message is output and centos-art.sh script finishes
|
|
|
80c9e6 |
# its execution.
|
|
|
878a2b |
#
|
|
|
03486a |
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
|
|
|
878a2b |
#
|
|
|
878a2b |
# This program is free software; you can redistribute it and/or modify
|
|
|
878a2b |
# it under the terms of the GNU General Public License as published by
|
|
|
878a2b |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
|
878a2b |
# your option) any later version.
|
|
|
878a2b |
#
|
|
|
878a2b |
# This program is distributed in the hope that it will be useful, but
|
|
|
878a2b |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
878a2b |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
878a2b |
# General Public License for more details.
|
|
|
878a2b |
#
|
|
|
878a2b |
# You should have received a copy of the GNU General Public License
|
|
|
878a2b |
# along with this program; if not, write to the Free Software
|
|
|
878a2b |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
878a2b |
#
|
|
|
878a2b |
# ----------------------------------------------------------------------
|
|
|
878a2b |
# $Id$
|
|
|
878a2b |
# ----------------------------------------------------------------------
|
|
|
878a2b |
|
|
|
878a2b |
function cli_checkFiles {
|
|
|
878a2b |
|
|
|
878a2b |
# Define short options.
|
|
|
aa68b3 |
local ARGSS='d,e,f,h,x'
|
|
|
878a2b |
|
|
|
878a2b |
# Define long options.
|
|
|
aa68b3 |
local ARGSL=''
|
|
|
3b0a5c |
|
|
|
3b0a5c |
# Initialize array variables.
|
|
|
3b0a5c |
local -a CONDITION_PATTERN
|
|
|
3b0a5c |
local -a CONDITION_MESSAGE
|
|
|
3b0a5c |
|
|
|
3b0a5c |
# Initialize array variable counter.
|
|
|
3b0a5c |
local COUNTER=0
|
|
|
878a2b |
|
|
|
878a2b |
# Initialize arguments with an empty value and set it as local
|
|
|
3b0a5c |
# variable to this function scope. Doing this is very important to
|
|
|
3b0a5c |
# avoid any clash with higher execution environments.
|
|
|
878a2b |
local ARGUMENTS=''
|
|
|
878a2b |
|
|
|
3b0a5c |
# Prepare ARGUMENTS for getopt.
|
|
|
878a2b |
cli_parseArgumentsReDef "$@"
|
|
|
878a2b |
|
|
|
3b0a5c |
# Redefine ARGUMENTS using getopt(1) command parser.
|
|
|
878a2b |
cli_parseArguments
|
|
|
878a2b |
|
|
|
878a2b |
# Redefine positional parameters using ARGUMENTS variable.
|
|
|
878a2b |
eval set -- "$ARGUMENTS"
|
|
|
878a2b |
|
|
|
878a2b |
# Look for options passed through positional parameters.
|
|
|
878a2b |
while true; do
|
|
|
878a2b |
|
|
|
878a2b |
case "$1" in
|
|
|
878a2b |
|
|
|
aa68b3 |
-d )
|
|
|
3b0a5c |
CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]='-d'
|
|
|
3b0a5c |
CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "isn't a directory."`"
|
|
|
878a2b |
shift 1
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
aa68b3 |
-e )
|
|
|
aa68b3 |
CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]='-e'
|
|
|
aa68b3 |
CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "doesn't exist."`"
|
|
|
aa68b3 |
;;
|
|
|
aa68b3 |
|
|
|
aa68b3 |
-f )
|
|
|
3b0a5c |
CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]='-f'
|
|
|
3b0a5c |
CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "isn't a regular file."`"
|
|
|
878a2b |
shift 1
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
aa68b3 |
-h )
|
|
|
3b0a5c |
CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]='-h'
|
|
|
3b0a5c |
CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "isn't a symbolic link."`"
|
|
|
878a2b |
shift 1
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
aa68b3 |
-x )
|
|
|
3b0a5c |
CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]='-x'
|
|
|
3b0a5c |
CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "isn't an executable file."`"
|
|
|
878a2b |
shift 1
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
878a2b |
-- )
|
|
|
878a2b |
shift 1
|
|
|
878a2b |
break
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
878a2b |
esac
|
|
|
878a2b |
done
|
|
|
878a2b |
|
|
|
3b0a5c |
# FIXME: Find a way to be sure that file is inside the working
|
|
|
3b0a5c |
# copy and under version control too. All the files we use to
|
|
|
3b0a5c |
# produce content (i.e., svg, docbook, texinfo, etc.) must be
|
|
|
3b0a5c |
# under version control and inside the working copy. Note also
|
|
|
3b0a5c |
# that we uso temporal files which aren't inside the working copy
|
|
|
3b0a5c |
# nor under version control. So a way to verify different types of
|
|
|
3b0a5c |
# files based on context must be available.
|
|
|
3b0a5c |
#
|
|
|
3b0a5c |
# For example: It would be useful to have an option to standardize
|
|
|
3b0a5c |
# questions like "Is this file under version control?" or "Is this
|
|
|
3b0a5c |
# file under the working copy directory structure?".
|
|
|
3b0a5c |
|
|
|
3b0a5c |
# Define list of files we want to apply verifications to, now that
|
|
|
3b0a5c |
# all option-like arguments have been removed from positional
|
|
|
3b0a5c |
# paramters list.
|
|
|
3b0a5c |
local FILE=''
|
|
|
3b0a5c |
local FILES=$@
|
|
|
3b0a5c |
|
|
|
3b0a5c |
for FILE in $FILES;do
|
|
|
3b0a5c |
|
|
|
3b0a5c |
while [[ ${COUNTER} -lt ${#CONDITION_PATTERN[*]} ]];do
|
|
|
3b0a5c |
|
|
|
d0b720 |
[ ! ${CONDITION_PATTERN[$COUNTER]} ${FILE} ] \
|
|
|
3b0a5c |
&& cli_printMessage "${FILE} ${CONDITION_MESSAGE[$COUNTER]}" --as-error-line
|
|
|
3b0a5c |
|
|
|
3b0a5c |
COUNTER=$(($COUNTER + 1))
|
|
|
3b0a5c |
|
|
|
3b0a5c |
done
|
|
|
3b0a5c |
|
|
|
3b0a5c |
done
|
|
|
3b0a5c |
|
|
|
878a2b |
}
|