| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function cli_checkFiles { |
| |
| |
| local FILE="$1" |
| local TYPE="$2" |
| local ACTION="$3" |
| local MESSAGE='' |
| |
| |
| |
| if [[ $# -lt 1 ]];then |
| cli_printMessage "cli_checkFiles: `gettext "You need to provide one argument at least."`" |
| cli_printMessages "$(caller)" "AsToKnowMoreLine" |
| fi |
| |
| |
| if [[ ! "$3" ]] || [[ "$3" == '' ]];then |
| ACTION=`gettext "Checking"` |
| fi |
| |
| |
| if [[ $FILE == '' ]];then |
| MESSAGE="`gettext "Unknown"`" |
| cli_printMessage "${ACTION}: $MESSAGE" |
| return 1 |
| fi |
| |
| |
| case $TYPE in |
| |
| d | directory ) |
| |
| if [[ ! -d $FILE ]];then |
| MESSAGE="`eval_gettext "The directory \\\"\\\$FILE\\\" doesn't exist."`" |
| 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 |
| ;; |
| |
| 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 file \\\"\\\$FILE\\\" doesn't exist."`" |
| fi |
| fi |
| ;; |
| |
| * ) |
| # File exists. |
| if [[ ! -a $FILE ]];then |
| MESSAGE="`eval_gettext "The file \\\"\\\$FILE\\\" doesn't exist."`" |
| fi |
| |
| esac |
| |
| # If there is some message print it. |
| if [[ "$MESSAGE" == '' ]];then |
| cli_printMessage "${ACTION}: $FILE" |
| return 0 |
| else |
| cli_printMessage "${ACTION}: $MESSAGE" |
| return 1 |
| fi |
| |
| } |
| |