From b76c025fdf79b2ddad47141b7b1b989b2a75afe8 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Nov 05 2010 15:20:32 +0000 Subject: Update cli_checkFiles.sh and related files: - Before this commit, cli_checkFiles function used four arguments, and was designed to be used only for two-columns format output. It was also designed to do quiet verifications based on returned value. - In this commit, cli_checkFiles uses two arguments only. One to receive FILE, and other to receive the verification type. Both ACTION and OPTIONS arguments were removed from cli_checkFiles. cli_checkFiles was redesign to no longer be used inside two-columns output only, but in whatever place you need inside centos-art.sh script. As default behaviour, if FILE pass verification, centos-art.sh script continues with its normal flow. Otherwise the centos-art.sh ends script execution with an error and documentation message. - As consecuence of these changes, related files where cli_checkFiles is used needed to be updated to fit new arguments and script flow. - When you verify directories with cli_checkFiles, if directory doesn't exist, centos-art.sh script ask you for confirmation in order to create that directory. If you answer positively, centos-art.sh script creates that directory and continues script flows normally. Otherwise, if you answer negatively, centos-art.sh ends script execution with an error and documentation message. NOTE: File manipulation insdie repository will be covered by centos-art.sh script ``path'' functionality. Once ``path'' functionality be ready. All file/directory creation should be done through ``path'' functionality. - Add file execution (x) verification to cli_checkFiles. --- diff --git a/Scripts/Bash/Functions/Render/render_doIdentityGroupByType.sh b/Scripts/Bash/Functions/Render/render_doIdentityGroupByType.sh index 5c33b4f..c1ee9aa 100755 --- a/Scripts/Bash/Functions/Render/render_doIdentityGroupByType.sh +++ b/Scripts/Bash/Functions/Render/render_doIdentityGroupByType.sh @@ -139,16 +139,10 @@ function render_doIdentityGroupByType { TARGET=$(dirname $FILE)/$(cli_getRepoName "$FORMAT" 'd') # Check existence of source file. - cli_checkFiles $SOURCE 'f' '' '--quiet' - if [[ $? -ne 0 ]];then - continue - fi + cli_checkFiles $SOURCE 'f' # Check existence of target directory. - cli_checkFiles $TARGET 'd' '' '--quiet' - if [[ $? -ne 0 ]];then - mkdir $TARGET - fi + cli_checkFiles $TARGET 'd' # Redifine file path to add file and its type. TARGET=${TARGET}/$(basename $FILE).${FORMAT} diff --git a/Scripts/Bash/Functions/Render/render_doIdentityImageBrands.sh b/Scripts/Bash/Functions/Render/render_doIdentityImageBrands.sh index fc806c4..e3531f5 100644 --- a/Scripts/Bash/Functions/Render/render_doIdentityImageBrands.sh +++ b/Scripts/Bash/Functions/Render/render_doIdentityImageBrands.sh @@ -58,7 +58,7 @@ function render_doIdentityImageBrands { TARGETFILE=$TARGETDIR/$(basename $SOURCEFILE) # --- centos-art path $SOURCEFILE --move-to=$TARGETDIR cli_printMessage "$TARGETFILE" 'AsMovedToLine' - cli_checkFiles $TARGETDIR 'd' '' '--quiet' + cli_checkFiles $TARGETDIR 'd' if [[ $? -ne 0 ]];then mkdir -p $TARGETDIR fi @@ -71,7 +71,7 @@ function render_doIdentityImageBrands { TARGETFILE=$TARGETDIR/$(basename $SOURCEFILE) # --- centos-art path $SOURCEFILE --move-to=$TARGETDIR cli_printMessage "$TARGETFILE" 'AsMovedToLine' - cli_checkFiles $TARGETDIR 'd' '' '--quiet' + cli_checkFiles $TARGETDIR 'd' if [[ $? -ne 0 ]];then mkdir -p $TARGETDIR fi diff --git a/Scripts/Bash/Functions/Render/render_doIdentityImageDm.sh b/Scripts/Bash/Functions/Render/render_doIdentityImageDm.sh index 2a00693..e871c52 100755 --- a/Scripts/Bash/Functions/Render/render_doIdentityImageDm.sh +++ b/Scripts/Bash/Functions/Render/render_doIdentityImageDm.sh @@ -74,10 +74,7 @@ function render_doIdentityImageDm { fi # Check absolute path to display manager design models. - cli_checkFiles $TPL 'd' - if [[ $? -ne 0 ]];then - cli_printMessage "$(caller)" 'AsToKnowMoreLine' - fi + cli_checkFiles "$TPL" 'd' # Get screen resolutions passed from render.conf.sh pre-rendering # configuration script. @@ -116,10 +113,7 @@ function render_doIdentityImageDm { # we are using CentOS symbol at 48x48 pixels. This value seems to # be the middle dimension that fits all situations. SYMBOL=/home/centos/artwork/trunk/Identity/Brands/Img/CentOS/Symbol/5c-a/Png/48.png - cli_checkFiles $SYMBOL 'f' - if [[ $? -ne 0 ]];then - cli_printMessage "$(caller)" "AsToKnowMoreLine" - fi + cli_checkFiles "$SYMBOL" 'f' for VERSION in $VERSIONS;do @@ -129,19 +123,13 @@ function render_doIdentityImageDm { IMG=$OPTIONVAL/$VERSION/Img # Check existence of release-specific image directory. - cli_checkFiles $IMG '-d' '' '--quiet' - if [[ $? -ne 0 ]];then - mkdir -p $IMG - fi + cli_checkFiles "$IMG" 'd' # Define directory to store release-specific tar.gz files. TGZ=$OPTIONVAL/$VERSION/Tgz # Check existence of release-specific tar.gz directory. - cli_checkFiles $TGZ 'd' '' '--quiet' - if [[ $? -ne 0 ]];then - mkdir -p $TGZ - fi + cli_checkFiles "$TGZ" 'd' # Move into working directory. pushd $TGZ > /dev/null @@ -151,11 +139,7 @@ function render_doIdentityImageDm { cli_printMessage "$TGZ/${TMP}-${RESOLUTION}.tar.gz" "AsCreatingLine" # Check background existence for specified resolution. - cli_checkFiles $BGS/$RESOLUTION.png 'f' '' '--quiet' - if [[ $? -ne 0 ]];then - cli_printMessage "`eval_gettext "There is not background for \\\"\\\$RESOLUTION\\\" resolution."`" - cli_printMessage "$(caller)" "AsToKnowMoreLine" - fi + cli_checkFiles "$BGS/${RESOLUTION}.png" 'f' # Create temporal directory. if [[ ! -d $TMP ]]; then diff --git a/Scripts/Bash/Functions/Render/render_doIdentityImages.sh b/Scripts/Bash/Functions/Render/render_doIdentityImages.sh index f50d9dd..f2c1db0 100644 --- a/Scripts/Bash/Functions/Render/render_doIdentityImages.sh +++ b/Scripts/Bash/Functions/Render/render_doIdentityImages.sh @@ -67,12 +67,9 @@ function render_doIdentityImages { EXTERNALFILES=$(egrep '(xlink:href|sodipodi:absref)="/home/centos/artwork/' $INSTANCE \ | sed -r 's!^[[:space:]]+!!' \ | sed -r 's!^(xlink:href|sodipodi:absref)="!!' \ - | sed -r 's!".*$!!' | uniq) + | sed -r 's!".*$!!' | sort | uniq) for EXTERNALFILE in $EXTERNALFILES;do cli_checkFiles $EXTERNALFILE - if [[ $? -ne 0 ]];then - cli_printMessage "$(caller)" 'AsToKnowMoreLine' - fi done # Render template instance and modify the inkscape output to diff --git a/Scripts/Bash/Functions/Render/render_getIdentityDefs.sh b/Scripts/Bash/Functions/Render/render_getIdentityDefs.sh index 66444d2..e364050 100644 --- a/Scripts/Bash/Functions/Render/render_getIdentityDefs.sh +++ b/Scripts/Bash/Functions/Render/render_getIdentityDefs.sh @@ -48,7 +48,8 @@ function render_getIdentityDefs { if [[ "$TRANSLATION" == 'None' ]];then cli_printMessage "`gettext "None"`" "AsTranslationLine" else - cli_checkFiles "$TRANSLATION" 'fh' `gettext "Translation"` + cli_checkFiles "$TRANSLATION" 'fh' + cli_printMessage "`gettext "Translation"`:" "$TRANSLATION" fi # Define the design template absolute path. This definition is @@ -288,10 +289,8 @@ function render_getIdentityDefs { # Check existence of TEMPLATE file. If design template doesn't # exist we cannot render it; in such case, stop working for it and # try the next one in the list. - cli_checkFiles "$TEMPLATE" '' "`gettext "Design"`" - if [[ $? -gt 0 ]];then - continue - fi + cli_checkFiles "$TEMPLATE" 'f' + cli_printMessage "`gettext "Design"`: $TEMPLATE" 'AsRegularLine' # Get relative path to file. The path string (stored in FILE) has # two parts: 1. the variable path and 2. the common path. The diff --git a/Scripts/Bash/Functions/Shell/shell_updateTopComment.sh b/Scripts/Bash/Functions/Shell/shell_updateTopComment.sh index 1b0fdf3..76d34f7 100755 --- a/Scripts/Bash/Functions/Shell/shell_updateTopComment.sh +++ b/Scripts/Bash/Functions/Shell/shell_updateTopComment.sh @@ -55,11 +55,7 @@ function shell_updateTopComment { done # Check template file existence. - cli_checkFiles $TEMPLATE 'f' '' '--quiet' - if [[ $? -ne 0 ]];then - cli_printMessage "`gettext "The template file you provided doesn't exist."`" - cli_printMessage "$(caller)" 'AsToKnowMoreLine' - fi + cli_checkFiles $TEMPLATE 'f' # Define template instance name. INSTANCE=${TMPFILE}-$(basename $TEMPLATE) @@ -80,10 +76,8 @@ function shell_updateTopComment { sed -i -f $INSTANCE $FILE # Remove template instance. - cli_checkFiles $INSTANCE 'f' '' '--quiet' - if [[ $? -eq 0 ]];then - rm $INSTANCE - fi + cli_checkFiles $INSTANCE 'f' + rm $INSTANCE done \ | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk diff --git a/Scripts/Bash/Functions/Svg/svg_updateMetadata.sh b/Scripts/Bash/Functions/Svg/svg_updateMetadata.sh index 7d5e8a2..f2c09ea 100755 --- a/Scripts/Bash/Functions/Svg/svg_updateMetadata.sh +++ b/Scripts/Bash/Functions/Svg/svg_updateMetadata.sh @@ -61,11 +61,7 @@ function svg_updateMetadata { done # Check metadata template file existence. - cli_checkFiles $TEMPLATE 'f' '' '--quiet' - if [[ $? -ne 0 ]];then - cli_printMessage "`gettext "The template file you provided doesn't exist."`" - cli_printMessage "$(caller)" 'AsToKnowMoreLine' - fi + cli_checkFiles $TEMPLATE 'f' # Define metadata template instance. INSTANCE=${TMPFILE}-$(basename $TEMPLATE) @@ -122,10 +118,8 @@ function svg_updateMetadata { sed -i -f $INSTANCE $FILE # Remove metadata template instance. - cli_checkFiles $INSTANCE 'f' '' '--quiet' - if [[ $? -eq 0 ]];then - rm $INSTANCE - fi + cli_checkFiles $INSTANCE 'f' + rm $INSTANCE done \ | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk diff --git a/Scripts/Bash/Functions/Verify/verify_doLinkInstall.sh b/Scripts/Bash/Functions/Verify/verify_doLinkInstall.sh index 2c28bfa..a10e50a 100755 --- a/Scripts/Bash/Functions/Verify/verify_doLinkInstall.sh +++ b/Scripts/Bash/Functions/Verify/verify_doLinkInstall.sh @@ -35,22 +35,18 @@ function verify_doLinkInstall { # Verify parent directory of missing link names that have a # file as target. If the parent directory doesn't exist, # create it first before creating links inside it. Because - # links are not created yet, we use their targets as reference - # to determine what type of link we are creating. + # links are not created yet, we use their related targets as + # reference to determine what type of link we are creating. if [[ -f ${TARGETS[$ID]} ]];then LINKS_PARENT=$(dirname ${LINKS[$ID]}) - cli_checkFiles $LINKS_PARENT 'd' '' '--quiet' - if [[ $? -ne 0 ]];then - mkdir -p $LINKS_PARENT - fi + cli_checkFiles $LINKS_PARENT 'd' fi # Verify missing link that already exists as regular file. If # a regular file exists with the same name of a required link, # warn the user about it and continue with the next file in # the list of missing links that need to be installed. - cli_checkFiles ${LINKS[$ID]} 'f' '' '--quiet' - if [[ $? -eq 0 ]];then + if [[ -f ${LINKS[$ID]} ]];then WARNING=" (`gettext "Already exists as regular file."`)" cli_printMessage "${LINKS[$ID]}${WARNING}" 'AsResponseLine' continue diff --git a/Scripts/Bash/Functions/Verify/verify_doPackageCheck.sh b/Scripts/Bash/Functions/Verify/verify_doPackageCheck.sh index 3d8ebba..a0351f7 100755 --- a/Scripts/Bash/Functions/Verify/verify_doPackageCheck.sh +++ b/Scripts/Bash/Functions/Verify/verify_doPackageCheck.sh @@ -30,11 +30,7 @@ function verify_doPackageCheck { local PACKAGE='' # Check package manager command existance. - cli_checkFiles '/bin/rpm' 'f' '' '--quiet' - if [[ $? -ne 0 ]];then - cli_printMessage "`gettext "The RPM package manager is not installed."`" - cli_printMessage "$(caller)" 'AsToKnowMoreLine' - fi + cli_checkFiles '/bin/rpm' 'x' for PACKAGE in $PACKAGES;do diff --git a/Scripts/Bash/Functions/Verify/verify_doPackageInstall.sh b/Scripts/Bash/Functions/Verify/verify_doPackageInstall.sh index b42f057..d171f1e 100755 --- a/Scripts/Bash/Functions/Verify/verify_doPackageInstall.sh +++ b/Scripts/Bash/Functions/Verify/verify_doPackageInstall.sh @@ -27,11 +27,7 @@ function verify_doPackageInstall { # Verify `yum' command existence. - cli_checkFiles '/usr/bin/yum' 'f' '' '--quiet' - if [[ $? -ne 0 ]];then - cli_printMessage "`gettext "The yum package manager is not installed."`" - cli_printMessage "$(caller)" 'AsToKnowMoreLine' - fi + cli_checkFiles '/usr/bin/yum' 'x' # Use sudo to install packages in your system through yum. sudo yum install ${PACKAGES_MISSING[*]} diff --git a/Scripts/Bash/Functions/cli.sh b/Scripts/Bash/Functions/cli.sh index 9a761e5..ab49423 100644 --- a/Scripts/Bash/Functions/cli.sh +++ b/Scripts/Bash/Functions/cli.sh @@ -106,19 +106,16 @@ function cli { # Define default answer to questions. ANSWER=${N} - # Define a unique string based on script name and process id used - # to create temporal files under /tmp/. - TMPFILE="/tmp/centos-art-$USER-$$" - - # Define text editor used to edit texinfo documentation. Predifine - # possible editors paths here to avoid malevolent values. If we do - # not create this restriction editor can be set to anything other - # than a text editor and in that case be executed when you try to - # edit a documentation entry using the `centos-art help --edit' - # command. + # Define prefix for temporal files. + TMPFILE="/tmp/centos-art-$$" + + # Define default text editors used by centos-art.sh script. if [[ ! "$EDITOR" =~ '/usr/bin/(vim|emacs|nano)' ]];then EDITOR='/usr/bin/vim' fi + + # Check text editor execution rights. + cli_checkFiles $EDITOR 'x' # Go to defined actions. Keep the cli_getActions function calling # after all variables and arguments definitions. Reason? To make diff --git a/Scripts/Bash/Functions/cli_checkFiles.sh b/Scripts/Bash/Functions/cli_checkFiles.sh index fb56a26..fea7eb0 100644 --- a/Scripts/Bash/Functions/cli_checkFiles.sh +++ b/Scripts/Bash/Functions/cli_checkFiles.sh @@ -1,6 +1,13 @@ #!/bin/bash # -# cli_checkFiles.sh -- This function checks file existence. +# cli_checkFiles.sh -- This function standardizes file verifications +# inside centos-art.sh script. If file verification fails in anyway, +# centos-art.sh script complains about it and ends up script +# execution. +# +# Usage: +# +# cli_checkFiles FILE [TYPE] # # Copyright (C) 2009-2010 Alain Reguera Delgado # @@ -25,39 +32,38 @@ function cli_checkFiles { - # Define variables as local to avoid conflicts outside. + # Get absolute path to file/directory. local FILE="$1" + + # Get verification type. local TYPE="$2" - local ACTION="$3" - local OPTIONS="$4" + + # Initialize message output. local MESSAGE='' - # Check amount of paramaters passed. At least one argument should - # be passed. + # Check number of paramaters passed to cli_checkFiles function. At + # least one argument should be passed. if [[ $# -lt 1 ]];then cli_printMessage "cli_checkFiles: `gettext "You need to provide one argument at least."`" cli_printMessages "$(caller)" "AsToKnowMoreLine" fi - # Define default action to take, if it is not specified. - if [[ ! "$3" ]] || [[ "$3" == '' ]];then - ACTION=`gettext "Checking"` - fi - - # Check file provided. + # Check value passed as file to cli_checkFiles function. The file + # value cannot be empty. if [[ $FILE == '' ]];then - MESSAGE="`gettext "Unknown"`" - cli_printMessage "${ACTION}: $MESSAGE" "AsRegularLine" - return 1 + cli_printMessage "cli_checkFiles: `gettext "The first argument cannot be empty."`" + cli_printMessages "$(caller)" "AsToKnowMoreLine" fi - # Check file types. + # Perform file verification using FILE and TYPE variables. case $TYPE in d | directory ) # File exists and is a directory if [[ ! -d $FILE ]];then - MESSAGE="`eval_gettext "The directory \\\"\\\$FILE\\\" doesn't exist."`" + 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 ;; @@ -75,12 +81,17 @@ function cli_checkFiles { 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. - cli_checkFiles $FILE 'f' '' '--quiet' - if [[ $? -ne 0 ]];then - cli_checkFiles $FILE 'h' '' '--quiet' - if [[ $? -ne 0 ]];then + if [[ ! -f $FILE ]];then + if [[ ! -h $FILE ]];then MESSAGE="`eval_gettext "The file \\\"\\\$FILE\\\" doesn't exist."`" fi fi @@ -94,26 +105,12 @@ function cli_checkFiles { esac - # If there is some message print it when there is no `--quiet' - # option passed as fourth argument. - if [[ "$MESSAGE" == '' ]];then - for OPTION in $OPTIONS;do - case $OPTION in - '--quiet' ) - return 0 - esac - done - cli_printMessage "${ACTION}: $FILE" "AsRegularLine" - return 0 - else - for OPTION in $OPTIONS;do - case $OPTION in - '--quiet' ) - return 1 - esac - done - cli_printMessage "${ACTION}: $MESSAGE" "AsRegularLine" - return 1 + # 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" "AsRegularLine" + cli_printMessages "$(caller)" "AsToKnowMoreLine" fi }