#!/bin/bash

set -e

#DEBHELPER#

check_4_fdi_files () {
ls /etc/hal/fdi/policy/ | grep sixa_ > /dev/null
}

check_4_old_profiles-list () {
cat /usr/share/qtsixa/profiles.list | grep "2h4u;" > /dev/null
}

if [ -f /usr/share/qtsixa/profiles.list ]; then

  if (check_4_old_profiles-list "$1"); then true; else
    cp /usr/share/qtsixa/profiles.list.bu /usr/share/qtsixa/profiles.list
  fi

else
  cp /usr/share/qtsixa/profiles.list.bu /usr/share/qtsixa/profiles.list
fi

if [ -f /etc/hal/fdi/policy/DualShock3.fdi ]; then
rm /etc/hal/fdi/policy/DualShock3.fdi
echo "Note: incompatible DualShock3.fdi file was found and deleted"
fi

if (check_4_fdi_files "$1"); then true; else
cp /usr/share/qtsixa/sixaxis-profiles/sixa_none.fdi /etc/hal/fdi/policy/
fi
