1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2016 Intel Corporation 4# All rights reserved. 5 6# Make sure file has a trailing newline 7 8f="$1" 9 10if [ -z "$f" ]; then 11 echo "usage: $0 <file>" 12 exit 1 13fi 14 15if [ ! -f "$f" ]; then 16 exit 0 17fi 18 19if [[ $(tail -c1 "$f") ]]; then 20 echo "$f: No newline at end of file" 21 echo '' >> "$f" 22 exit 1 23fi 24 25if [[ ! $(tail -c2 "$f") ]]; then 26 echo "$f: Extra trailing newline" 27 exit 1 28fi 29 30if grep -q $'\r' "$f"; then 31 echo "$f: DOS-style newlines" 32 dos2unix "$f" &> /dev/null 33 exit 1 34fi 35 36if grep -q $'[\t ]$' "$f"; then 37 echo "$f: Trailing whitespace" 38 sed -i $'s/[ \t]*$//' "$f" 39 exit 1 40fi 41 42exit 0 43