| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function cli_checkFiles { |
| |
| |
| local FILE="$1" |
| |
| |
| local TYPE="$2" |
| |
| |
| local MESSAGE='' |
| |
| |
| |
| if [[ $# -lt 1 ]];then |
| cli_printMessage "cli_checkFiles: `gettext "You need to provide one argument at least."`" 'AsErrorLine' |
| cli_printMessage "$(caller)" "AsToKnowMoreLine" |
| fi |
| |
| |
| |
| if [[ $FILE == '' ]];then |
| cli_printMessage "cli_checkFiles: `gettext "The first argument cannot be empty."`" 'AsErrorLine' |
| cli_printMessage "$(caller)" "AsToKnowMoreLine" |
| fi |
| |
| |
| case $TYPE in |
| |
| d | directory ) |
| |
| if [[ ! -d $FILE ]];then |
| cli_printMessage "`eval_gettext "The directory \\\"\\\$FILE\\\" doesn't exist."`" |
| cli_printMessage "`gettext "Do you want to create it now?"`" 'AsYesOrNoRequestLine' |
| mkdir -p $FILE |
| fi |
| ;; |
| |
| f | regular-file ) |
| # File exists and is a regular file. |
| if [[ ! -f $FILE ]];then |
| MESSAGE="`eval_gettext "The file \\\"\\\$FILE\\\" is not a regular file."`" |
| fi |
| ;; |
| |
| h | symbolic-link ) |
| # File exists and is a symbolic link. |
| if [[ ! -h $FILE ]];then |
| MESSAGE="`eval_gettext "The file \\\"\\\$FILE\\\" is not a symbolic link."`" |
| fi |
| ;; |
| |
| x | execution ) |
| # To exist, file should be executable. |
| if [[ ! -x $FILE ]];then |
| MESSAGE="`eval_gettext "The file \\\"\\\$FILE\\\" is not executable."`" |
| fi |
| ;; |
| |
| fh ) |
| # To exist, file should be a regular file or a symbolic link. |
| if [[ ! -f $FILE ]];then |
| if [[ ! -h $FILE ]];then |
| MESSAGE="`eval_gettext "The path \\\"\\\$FILE\\\" doesn't exist."`" |
| fi |
| fi |
| ;; |
| |
| fd ) |
| # To exist, file should be a regular file or a directory. |
| if [[ ! -f $FILE ]];then |
| if [[ ! -d $FILE ]];then |
| MESSAGE="`eval_gettext "The path \\\"\\\$FILE\\\" doesn't exist."`" |
| fi |
| fi |
| ;; |
| |
| isInWorkingCopy ) |
| # To exist, file should be inside the working copy. |
| if [[ $FILE =~ "^/home/centos/artwork/.+$" ]];then |
| MESSAGE="`eval_gettext "The path \\\"\\\$FILE\\\" doesn't exist inside the working copy."`" |
| fi |
| ;; |
| |
| * ) |
| # File exists. |
| if [[ ! -a $FILE ]];then |
| MESSAGE="`eval_gettext "The path \\\"\\\$FILE\\\" doesn't exist."`" |
| fi |
| |
| esac |
| |
| # If file verification fails in anyway, output message information |
| # and end up script execution. Otherwise, continue with script |
| # normal flow. |
| if [[ "$MESSAGE" != '' ]];then |
| cli_printMessage "$MESSAGE" "AsErrorLine" |
| cli_printMessage "$(caller)" "AsToKnowMoreLine" |
| fi |
| |
| } |
| |