#!/bin/sh
FOUND_EXTERNAL_USB_STORAGE=
for f in `df | awk '{print $6}'`; do
  if [ $f = "/media/usb0" ]; then
    FOUND_EXTERNAL_USB_STORAGE=$f
    break
  fi
done
if [ "$FOUND_EXTERNAL_USB_STORAGE" = "/media/usb0" ]; then
  mkdir -p /media/usb0/output
else
  echo "cannot found /media/usb0"
  echo "please insert usb storage."
  exit
fi

DATE_SUFFIX=`date +%F-%H%M%S`
mkdir -p /media/usb0/output/$DATE_SUFFIX
echo "sox -t raw -r 16k -e signed -b 24 -c 8 input.raw input.wav" > /media/usb0/output/$DATE_SUFFIX/convert.sh
cat /hark/hark-ody_recording_template.conf | sed -E "s/<EXPORT>/media\/usb0\/output\/$DATE_SUFFIX/g" > /hark/hark-ody_recording.conf
./vsserver -d /dev/obd -f /media/usb0/output/$DATE_SUFFIX/logged.can &
/hark/hark --config /hark/hark-ody_recording.conf

