meta-agl-bsp: Add reference hardware GPS support
[AGL/meta-agl.git] / meta-agl-bsp / meta-agl-refhw-gen3 / recipes-navigation / gpsd / files / refhw-gpsd-helper.sh
1 #!/bin/sh
2 #
3 # Script to detect AGL Reference Hardware and switch gpsd
4 # configuration as necessary.
5 #
6 # NOTE:
7 # For the most part errors are ignored and the script returns
8 # 0/success so gpsd still be started if the script is somehow
9 # run on a board without the expected hardware.
10
11 COMPAT=/sys/firmware/devicetree/base/compatible
12 GPSTTY=/dev/ttySC3
13
14 #if [ ! \( -f "$COMPAT" -a -c "$GPSTTY" -a -f /etc/default/gpsd.refhw \) ]; then
15 if [ ! \( -f "$COMPAT" -a -f /etc/default/gpsd.refhw \) ]; then
16     exit 0
17 fi
18
19 found=false
20 for c in `cat $COMPAT | tr '\0' ' '`; do
21     if echo $c | grep -q '^agl,refhw-h3$'; then
22         found=true
23         break
24     fi
25 done
26
27 if $found; then
28     if [ ! -c "$GPSTTY" ]; then
29         exit 0
30     fi
31     update-alternatives --install /etc/default/gpsd gpsd-defaults /etc/default/gpsd.refhw 20
32 else
33     update-alternatives --install /etc/default/gpsd gpsd-defaults /etc/default/gpsd.refhw 5
34 fi
35 exit 0