forked from betaflight/unified-targets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_targets.sh
executable file
·59 lines (46 loc) · 2.02 KB
/
check_targets.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
#!/bin/bash
error () {
echo -e "\nERROR: $1"
exit 1
}
check_naming () {
echo -n "Checking target naming..."
for target_config in configs/default/*.config; do
BOARD_NAME=$(sed -n 's/^ *board_name \([^#]\+\).*$/\1/p' ${target_config} | sed -e 's/[[:space:]]*$//')
MANUFACTURER_ID=$(sed -n 's/^ *manufacturer_id \+\([^#]\{1,4\}\).*$/\1/p' ${target_config} | sed -e 's/[[:space:]]*$//')
FILE_NAME=$(basename ${target_config})
if [ $(printf %s "${BOARD_NAME}" | grep -c .) -gt 1 ]; then
error "More than one board_name found in Unified Target configuration ${target_config}."
exit 1
fi
if [ $(printf %s "${MANUFACTURER_ID}" | grep -c .) -gt 1 ]; then
error "More than one manufacturer_id found in Unified Target configuration ${target_config}."
exit 1
fi
if [ $(echo "${BOARD_NAME}" | grep -c '[^[:upper:][:digit:]_]') -ne 0 ]; then
error "Invalid characters found in board_name (${BOARD_NAME}, allowed 'A'-'Z', '0'-'9', '_') in Unified Target configuration ${target_config}."
exit 1
fi
if [ $(echo "${MANUFACTURER_ID}" | grep -c '[^[:upper:][:digit:]_]') -ne 0 ]; then
error "Invalid characters found in manufacturer_id (${MANUFACTURER_ID}, allowed 'A'-'Z', '0'-'9', '_') in Unified Target configuration ${target_config}."
exit 1
fi
if [ "${FILE_NAME}" != "${MANUFACTURER_ID}-${BOARD_NAME}.config" ]; then
error "File name does not match board name (${BOARD_NAME}) / manufacturer id (${MANUFACTURER_ID}) in Unified Target configuration ${target_config}."
exit 1
fi
done
echo "done."
}
check_encoding () {
echo -n "Checking file encoding..."
for target_config in configs/default/*; do
if $(grep -U $'\x0D' -q ${target_config}); then
error "File ${target_config} has got invalid (DOS) line endings."
exit 1
fi
done
echo "done."
}
check_naming
check_encoding