#!/bin/bash

udevdir=$2/etc/udev
rulesdir=$udevdir/rules.d

if [ -f $1 ] ; then
    if [ ! -d $udevdir ] ; then
	echo "+++ $udevdir does not exist or is not a directory."
	echo "+++ Did you run the configure script with an incorrect value for \'-sysroot\' ?"
        echo "+++ Not installing udev rules \'$1\'."
	exit 0
    fi

    if [ ! -d $rulesdir ] ; then
	echo "*** $rulesdir does not exist or is not a directory."
	echo "*** Did you run the configure script with an incorrect value for \'-sysroot\' ?"
        echo "*** Aborting install of udev rules \'$1\'."
	exit 1
    fi

    install -m 755 $1 $rulesdir
    if [ $? != 0 ] ; then
	echo "*** Failed to install $1 in $rulesdir"
	exit 1
    else
	echo "Installed $1 in $rulesdir"
    fi
else
    echo "*** $1 does not exist - did you accidentally delete it?"
    echo "*** Aborting install of $1."
    exit 1
fi
