#!/bin/sh

#
# This script is needed for the Dockerfile since running gpsd with a RUN command doesn't seem to work
#
RED='\033[0;31m'
NC='\033[0m' # No Color
echo "Log Level: $RUST_LOG"
echo "Rocket Config: $ROCKET_CONFIG"
echo "GNSS ENABLED: $GNSS_ENABLED"
if [ "$GNSS_ENABLED" = true ]; then
	echo "GNSS Device Path: $GNSS_DEV"
	gpsd -n -G -S 2947 -F /var/run/gpsd.sock $GNSS_DEV
else
	echo "${RED}GNSS is DISABLED${NC}"
fi

mkdir /pcap/
touch /pcap/receiver.pcap
tcpdump -i eth0 -w /pcap/receiver.pcap &

sleep 5
mkdir /output/
if [ "$GNSS_ENABLED" = true ]; then
	videoprobe -p "/pcap/receiver.pcap" -o "/output/videoprobe_$(date '+%s').log"
else
	videoprobe -p "/pcap/receiver.pcap" -o "/output/videoprobe_$(date '+%s').log" -d
fi
