#!/bin/sh

module_id() {
    awk 'BEGIN { FS=": " } /Hardware/ { print $2 } ' </proc/cpuinfo
}

if [ ! -f /etc/sysconfig/bluetooth ]; then
  echo -n "Checking for built-in Bluetooth: "
  case `module_id` in
    "HP iPAQ H5400")
	BLUETOOTH=yes
	PORT=/dev/tts/1
	SPEED=921600
        PROTO=any
	;;
    "HP iPAQ H3900")
	BLUETOOTH=yes
	PORT=/dev/tts/1
	SPEED=921600
        PROTO=bcsp
	;;
    "HP iPAQ H3800")
	BLUETOOTH=yes
	PORT=/dev/ttySB0
	SPEED=230400
        PROTO=bcsp
	;;
    *)
	BLUETOOTH=no
        ;;
  esac

  if [ $BLUETOOTH = "yes" ]; then
    if ! blueprobe $PORT $SPEED; then
      BLUETOOTH=no
    fi
  fi

  echo $BLUETOOTH
  echo "BLUETOOTH=$BLUETOOTH" >/etc/sysconfig/bluetooth
  if [ $BLUETOOTH = "yes" ]; then
    echo "BLUETOOTH_PORT=$PORT" >>/etc/sysconfig/bluetooth
    echo "BLUETOOTH_SPEED=$SPEED" >>/etc/sysconfig/bluetooth
    echo "BLUETOOTH_PROTOCOL=$PROTO" >>/etc/sysconfig/bluetooth
  fi
fi
