[pacman-dev] [PATCH] makepkg: ensure PKGBUILD does not contain CRLF characters
Xavier
shiningxc at gmail.com
Tue Dec 16 13:16:51 EST 2008
from http://linuxreviews.org/beginner/abs-guide/en/x7610.html
#!/bin/bash
# Du.sh: DOS to UNIX text file converter.
E_WRONGARGS=65
if [ -z "$1" ]
then
echo "Usage: `basename $0` filename-to-convert"
exit $E_WRONGARGS
fi
NEWFILENAME=$1.unx
CR='\015' # Carriage return.
# 015 is octal ASCII code for CR.
# Lines in a DOS text file end in CR-LF.
# Lines in a UNIX text file end in LF only.
tr -d $CR < $1 > $NEWFILENAME
# Delete CR's and write to new file.
echo "Original DOS text file is \"$1\"."
echo "Converted UNIX text file is \"$NEWFILENAME\"."
exit 0
based on this, I have two comments :
1) just grepping for \015 seems enough for the detection
2) if we want automatic conversion, tr seems enough. Not sure what
dos2unix adds though. At least simplicity, no need to remember and
type \015. Is there anything else? Otherwise tr looks fine for a
script.
On Sun, Dec 7, 2008 at 3:35 PM, Dan McGee <dpmcgee at gmail.com> wrote:
> On Sun, Dec 7, 2008 at 4:33 AM, Allan McRae <allan at archlinux.org> wrote:
>> 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?
>
> I'm not sure everyone would have dos2unix installed, so that makes me
> shy away from this a bit. In addition, I feel like actually modifying
> the PKGBUILD should be a rare case. We do it in the case of VCS
> PKGBUILDs, but that is it, and I'd rather not destroy someone's work.
>
> -Dan
> _______________________________________________
> pacman-dev mailing list
> pacman-dev at archlinux.org
> http://archlinux.org/mailman/listinfo/pacman-dev
>
More information about the pacman-dev
mailing list