On Sun, Dec 7, 2008 at 4:33 AM, Allan McRae <allan@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@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