[PATCH modular 14/14] build.sh: verify PREFIX is a directory and is writable

Peter Hutterer peter.hutterer at who-t.net
Mon Jan 3 15:42:19 PST 2011


On Wed, 29 Dec 2010 11:30:03 -0500, Gaetan Nadon <memsize at videotron.ca> wrote:
> This will catch the case where user forgets to set PREFIX
> and does not have write permission in the /usr/local default location
> 
> Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
> ---
>  build.sh |   23 ++++++++++++++++++++++-
>  1 files changed, 22 insertions(+), 1 deletions(-)
> 
> diff --git a/build.sh b/build.sh
> index 1a29758..afcb158 100755
> --- a/build.sh
> +++ b/build.sh
> @@ -68,6 +68,10 @@ setup_buildenv() {
>      check_full_path $LIBDIR LIBDIR
>      check_full_path $LOCALSTATEDIR LOCALSTATEDIR
>  
> +    # This will catch the case where user forgets to set PREFIX
> +    # and does not have write permission in the /usr/local default location
> +    check_writable_dir $PREFIX PREFIX
> +
>      # Must create local aclocal dir or aclocal fails
>      ACLOCAL_LOCALDIR="${DESTDIR}${DATADIR}/aclocal"
>      $SUDO mkdir -p ${ACLOCAL_LOCALDIR}
> @@ -986,7 +990,7 @@ usage() {
>  
>  # Ensure the named variable value contains a full path name
>  # arguments:
> -#   $1 - the variable value (the path to examin)
> +#   $1 - the variable value (the path to examine)
>  #   $2 - the name of the variable
>  # returns:
>  #   returns nothing or exit on error with message
> @@ -999,6 +1003,23 @@ check_full_path () {
>      fi
>  }
>  
> +# Ensure the named variable value contains a writable directory
> +# arguments:
> +#   $1 - the variable value (the path to examine)
> +#   $2 - the name of the variable
> +# returns:
> +#   returns nothing or exit on error with message
> +check_writable_dir () {
> +    if [ X"$SUDO" = X ]; then

skip this check, just because it's sudo doesn't mean you can write to
the directory.

also, for readability, you may want to add a line of 
dir="$1"

and then use $dir instead of $1 in the remainder.

Cheers,
  Peter

> +	if [ ! -d "$1" ] || [ ! -w "$1" ]; then
> +	    echo "The path \"$1\" supplied by \"$2\" must be a writable directory"
> +	    echo ""
> +	    usage
> +	    exit 1
> +	fi
> +    fi
> +}
> +
>  # perform sanity checks on cmdline args which require arguments
>  # arguments:
>  #   $1 - the option being examined
> -- 
> 1.6.0.4



More information about the xorg-devel mailing list