forked from KonstantinderZweite/Sebennar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckEncoding.sh
169 lines (150 loc) · 4.61 KB
/
checkEncoding.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
set -o noclobber
has_bom() { head -c3 "$1" | grep -q $'\xef\xbb\xbf'; }
function validate_localization(){
echo "--------------------------------------------------------------------------------------------------------------------------------"
declare -i TOTAL=0
declare -i GOOD=0
declare -i BAD=0
for f in ./localisation/*.yml
do
if [[ "$( has_bom "$f" && file -b --mime-encoding "$f")" = utf-8 ]];then
# echo -e "${GREEN}{$f} encoding is good.${NC}"
GOOD+=1
else
echo -e "${RED}{$f} encoding is wrong!${NC}"
file -i $f
BAD+=1
fi
TOTAL+=1
done
echo -e "\n ${GREEN}${GOOD}${NC}/${TOTAL} ${GREEN}localization files encoding validated.${NC}\n"
if [[ $BAD > 0 ]]; then
echo -e "\n ${RED}${BAD}${NC}/${TOTAL} ${RED}decicion files have a wrong or unknown encoding!${NC}\n"
exit 1
fi
}
function validate_events(){
echo "--------------------------------------------------------------------------------------------------------------------------------"
declare -i TOTAL=0
declare -i GOOD=0
declare -i NEUTRAL=0
declare -i BAD=0
for f in ./events/*.txt
do
if [ "$(file -b --mime-encoding "$f")" = us-ascii ];then
# echo -e "${GREEN}{$f} encoding is good.${NC}"
GOOD+=1
elif [ "$(file -b --mime-encoding "$f")" = iso-8859-1 ]; then
# echo -e "${YELLOW}{$f} encoding is in european ascii!${NC}"
GOOD+=1
NEUTRAL+=1
elif [ "$(file -b --mime-encoding "$f")" = unknown-8bit ]; then
echo -e "${YELLOW}{$f} encoding is unknown!${NC}"
file -i $f
GOOD+=1
NEUTRAL+=1
else
echo -e "${RED}{$f} encoding is wrong!${NC}"
file -i $f
BAD+=1
fi
TOTAL+=1
done
echo -e "\n ${GREEN}${GOOD}${NC}/${TOTAL} ${GREEN}event files encoding validated.${NC}\n"
if [[ $NEUTRAL > 0 ]]; then
echo -e "\n ${YELLOW}${NEUTRAL}${NC}/${TOTAL} ${YELLOW}event files encoding are in european ascii or unknown.${NC}\n"
fi
if [[ $BAD > 0 ]]; then
echo -e "\n ${RED}${BAD}${NC}/${TOTAL} ${RED}event files have a wrong encoding!${NC}\n"
exit 1
fi
}
function validate_decisions(){
echo "--------------------------------------------------------------------------------------------------------------------------------"
declare -i TOTAL=0
declare -i GOOD=0
declare -i NEUTRAL=0
declare -i BAD=0
for f in ./decisions/*.txt
do
if [ "$(file -b --mime-encoding "$f")" = us-ascii ];then
# echo -e "${GREEN}{$f} encoding is good.${NC}"
GOOD+=1
elif [ "$(file -b --mime-encoding "$f")" = iso-8859-1 ]; then
# echo -e "${YELLOW}{$f} encoding is in european ascii!${NC}"
# file -i $f
GOOD+=1
NEUTRAL+=1
elif [ "$(file -b --mime-encoding "$f")" = unknown-8bit ]; then
echo -e "${YELLOW}{$f} encoding is unknown!${NC}"
file -i $f
GOOD+=1
NEUTRAL+=1
else
echo -e "${RED}{$f} encoding is wrong!${NC}"
file -i $f
BAD+=1
fi
TOTAL+=1
done
echo -e "\n ${GREEN}${GOOD}${NC}/${TOTAL} ${GREEN}decision files encoding validated.${NC}\n"
if [[ $NEUTRAL > 0 ]]; then
echo -e "\n ${YELLOW}${NEUTRAL}${NC}/${TOTAL} ${YELLOW}decision files encoding are in european ascii or unknown.${NC}\n"
fi
if [[ $BAD > 0 ]]; then
echo -e "\n ${RED}${BAD}${NC}/${TOTAL} ${RED}decision files have a wrong encoding!${NC}\n"
exit 1
fi
}
function validate_indentation(){
echo "--------------------------------------------------------------------------------------------------------------------------------"
declare -i GOOD=0
declare -i BAD=0
declare -i TOTAL=0
for f in ./*/*.txt ./common/*/*.txt
do
LEFT=$(LC_ALL=windows-1252 grep -o '^[^#]*' "$f" | grep -o '{' | wc -l)
RIGHT=$(LC_ALL=windows-1252 grep -o '^[^#]*' "$f" | grep -o '}' | wc -l)
TOTAL+=1
if [ $LEFT != $RIGHT ]; then
echo "${f}"
echo -e "${BLUE}${LEFT}${NC}/${CYAN}${RIGHT}${NC} ${RED}Broken syntax, inequal number of brackets.${NC}\n"
BAD+=1
else
GOOD+=1
fi
done
echo -e "\n ${GREEN}${GOOD}${NC}/${TOTAL} ${GREEN} files syntax validated.${NC}\n"
if [[ $BAD > 0 ]]; then
echo -e "\n ${RED}${BAD}${NC}/${TOTAL} ${RED} files syntax are wrong!${NC}\n"
exit 1
fi
}
function help_function()
{
echo ""
echo "Usage: $0 -e -l -d -u"
echo -e "\t-e Check events folder files encoding"
echo -e "\t-l Check localization folder files encoding"
echo -e "\t-d Check decisions folder files encoding"
echo -e "\t-i Check text file for broken indentation(bracket counting)"
exit 1
}
while getopts "eldi" opt
do
case "$opt" in
e ) validate_events ;;
l ) validate_localization ;;
d ) validate_decisions ;;
i ) validate_indentation ;;
: ) help_function ;;
\? ) help_function ;;
esac
done