-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
47 lines (34 loc) · 1.53 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
ERROR=0
PATHS=$(printf ${MODIFIED_FILES} | tr \\n '\n')
echo "******************************** MODIFIED FILES ********************************"
printf ${MODIFIED_FILES}
printf "\n********************************* ERRORS FOUND *******************************************************************"
echo "$PATHS" | while read FILE ; do
if [[ ! -f $FILE ]]; then
continue # skip deleted files
fi
IS_FILE_BINARY=$(find $FILE -type f | perl -lne 'print if -B' | wc -l)
if [[ $IS_FILE_BINARY == 1 ]]; then
continue # skip binary files
fi
CR_FOUND=$(find $FILE -not -type d -exec file "{}" ";" | grep " CR\(LF\)\? line terminators" | cut -d " " -f 1 | cut -d ":" -f 1 | wc -l)
CR_LINE_DETECTOR=$(find $FILE -not -type d -exec file "{}" ";" | grep ", with CR\(LF\)\?," | cut -d " " -f 1 | cut -d ":" -f 1 | wc -l)
BREAKLINE_TYPE=$(find $FILE -not -type d -exec file "{}" ";" | grep -o "CR\(LF\)\?")
if [[ $CR_FOUND == 1 ]]; then
echo "\n* Whole file( $FILE ) breakline format is $BREAKLINE_TYPE , it should be LF"
ERROR=1
fi
if [[ $CR_LINE_DETECTOR == 1 ]]; then
echo "\n* $BREAKLINE_TYPE line breaker found in $FILE:"
cat -en $FILE | grep "\^M" | sed 's/\^M\$//g'
ERROR=1
fi
done
if [[ $ERROR == 0 ]]; then
printf "\n* No files with wrong breakline format found in changed files"
fi
printf "\n******************************************************************************************************************\n"
if [[ $ERROR == 1 ]]; then
exit 101
fi