[pacman-dev] [PATCH] makepkg: ensure PKGBUILD does not contain CRLF characters

Allan McRae allan at archlinux.org
Sun Dec 7 05:33:29 EST 2008


Dan McGee wrote:
> Do a simple check before sourcing the file to ensure we are a valid bash
> script.
>
> Signed-off-by: Dan McGee <dan at archlinux.org>
> ---
>  scripts/makepkg.sh.in |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
> index b889625..179746d 100644
> --- a/scripts/makepkg.sh.in
> +++ b/scripts/makepkg.sh.in
> @@ -1354,6 +1354,12 @@ if [ ! -f "$BUILDSCRIPT" ]; then
>  		# PKGBUILD passed through a pipe
>  		BUILDSCRIPT=/dev/stdin
>  	fi
> +else
> +	crlftest=$(file $BUILDSCRIPT | grep -F 'CRLF' || true)
> +	if [ "$crlftest" != "" ]; then
> +		error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDSCRIPT"
> +		exit 1
> +	fi
>  fi
>  
>  source "$BUILDSCRIPT"
>   

Do you want to attempt a dos2unix there (with the error message 
downgraded to a warning) before failing?

Allan





More information about the pacman-dev mailing list