|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
b76c02 |
# cli_checkFiles.sh -- This function standardizes file verifications
|
|
|
b76c02 |
# inside centos-art.sh script. If file verification fails in anyway,
|
|
|
b76c02 |
# centos-art.sh script complains about it and ends up script
|
|
|
b76c02 |
# execution.
|
|
|
b76c02 |
#
|
|
|
7cd8e9 |
# Usage:
|
|
|
b76c02 |
#
|
|
|
7cd8e9 |
# cli_checkFiles FILE [TYPE]
|
|
|
4c79b5 |
#
|
|
|
2d3646 |
# Copyright (C) 2009, 2010, 2011 The CentOS Project
|
|
|
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
|
|
|
dcd347 |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
|
dcd347 |
# your option) any later version.
|
|
|
fa95b1 |
#
|
|
|
74a058 |
# This program is distributed in the hope that it will be useful, but
|
|
|
74a058 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
4c79b5 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
4c79b5 |
# General Public License for more details.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# You should have received a copy of the GNU General Public License
|
|
|
4c79b5 |
# along with this program; if not, write to the Free Software
|
|
|
dcd347 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
7ac5a5 |
#
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
418249 |
# $Id$
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function cli_checkFiles {
|
|
|
4c79b5 |
|
|
|
288be2 |
local FILE=''
|
|
|
288be2 |
local FILES="$1"
|
|
|
4c79b5 |
local TYPE="$2"
|
|
|
4c79b5 |
local MESSAGE=''
|
|
|
4c79b5 |
|
|
|
b76c02 |
# Check number of paramaters passed to cli_checkFiles function. At
|
|
|
b76c02 |
# least one argument should be passed.
|
|
|
4c79b5 |
if [[ $# -lt 1 ]];then
|
|
|
a014c6 |
cli_printMessage "`gettext "You need to provide one argument at least."`" --as-error-line
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
288be2 |
for FILE in $FILES;do
|
|
|
288be2 |
|
|
|
288be2 |
# Check value passed as file to cli_checkFiles function. The
|
|
|
288be2 |
# file value cannot be empty nor have extrange values.
|
|
|
288be2 |
cli_checkPathComponent "$FILE" '--default'
|
|
|
288be2 |
|
|
|
288be2 |
# Perform file verification using FILE and TYPE variables.
|
|
|
288be2 |
case $TYPE in
|
|
|
288be2 |
|
|
|
288be2 |
d | directory )
|
|
|
288be2 |
# File exists and is a directory
|
|
|
288be2 |
if [[ ! -d $FILE ]];then
|
|
|
a014c6 |
MESSAGE="`eval_gettext "The directory \\\"\\\$FILE\\\" does not exist."`"
|
|
|
288be2 |
fi
|
|
|
288be2 |
;;
|
|
|
288be2 |
|
|
|
288be2 |
f | regular-file )
|
|
|
288be2 |
# File exists and is a regular file.
|
|
|
288be2 |
if [[ ! -f $FILE ]];then
|
|
|
288be2 |
MESSAGE="`eval_gettext "The file \\\"\\\$FILE\\\" is not a regular file."`"
|
|
|
288be2 |
fi
|
|
|
288be2 |
;;
|
|
|
288be2 |
|
|
|
288be2 |
h | symbolic-link )
|
|
|
288be2 |
# File exists and is a symbolic link.
|
|
|
b76c02 |
if [[ ! -h $FILE ]];then
|
|
|
288be2 |
MESSAGE="`eval_gettext "The file \\\"\\\$FILE\\\" is not a symbolic link."`"
|
|
|
4c79b5 |
fi
|
|
|
288be2 |
;;
|
|
|
4c79b5 |
|
|
|
288be2 |
x | execution )
|
|
|
288be2 |
# To exist, file should be executable.
|
|
|
288be2 |
if [[ ! -x $FILE ]];then
|
|
|
288be2 |
MESSAGE="`eval_gettext "The file \\\"\\\$FILE\\\" is not executable."`"
|
|
|
288be2 |
fi
|
|
|
288be2 |
;;
|
|
|
288be2 |
|
|
|
288be2 |
fh )
|
|
|
288be2 |
# To exist, file should be a regular file or a symbolic link.
|
|
|
288be2 |
if [[ ! -f $FILE ]];then
|
|
|
288be2 |
if [[ ! -h $FILE ]];then
|
|
|
a014c6 |
MESSAGE="`eval_gettext "The path \\\"\\\$FILE\\\" does not exist."`"
|
|
|
288be2 |
fi
|
|
|
288be2 |
fi
|
|
|
288be2 |
;;
|
|
|
288be2 |
|
|
|
288be2 |
fd )
|
|
|
288be2 |
# To exist, file should be a regular file or a directory.
|
|
|
288be2 |
if [[ ! -f $FILE ]];then
|
|
|
288be2 |
if [[ ! -d $FILE ]];then
|
|
|
a014c6 |
MESSAGE="`eval_gettext "The path \\\"\\\$FILE\\\" does not exist."`"
|
|
|
288be2 |
fi
|
|
|
288be2 |
fi
|
|
|
288be2 |
;;
|
|
|
288be2 |
|
|
|
288be2 |
isInWorkingCopy )
|
|
|
288be2 |
# To exist, file should be inside the working copy.
|
|
|
288be2 |
if [[ ! $FILE =~ "^/home/centos/artwork/.+$" ]];then
|
|
|
a014c6 |
MESSAGE="`eval_gettext "The path \\\"\\\$FILE\\\" does not exist inside the working copy."`"
|
|
|
288be2 |
fi
|
|
|
288be2 |
;;
|
|
|
288be2 |
|
|
|
288be2 |
* )
|
|
|
288be2 |
# File exists.
|
|
|
288be2 |
if [[ ! -a $FILE ]];then
|
|
|
a014c6 |
MESSAGE="`eval_gettext "The path \\\"\\\$FILE\\\" does not exist."`"
|
|
|
0f02c4 |
fi
|
|
|
288be2 |
|
|
|
288be2 |
esac
|
|
|
288be2 |
|
|
|
288be2 |
done
|
|
|
4c79b5 |
|
|
|
b76c02 |
# If file verification fails in anyway, output message information
|
|
|
b76c02 |
# and end up script execution. Otherwise, continue with script
|
|
|
b76c02 |
# normal flow.
|
|
|
b76c02 |
if [[ "$MESSAGE" != '' ]];then
|
|
|
a014c6 |
cli_printMessage "$MESSAGE" --as-error-line
|
|
|
6253fc |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|