Automatically create symbolic link to Bluray when inserted

My MythTV 0.25 box does support Bluray playback straight from the disc but as Blurays need to be mounted in Linux it needs to know where the disc is mounted. At the moment I couldn't get MythTV to automatically detect this location so I hacked a script together. I guess you can probably do all this natively in a UDEV rule but I dont know much about UDEV.

This script will automatically create a symbolic link that you can configure into MythTV so it will always find your Bluray :)

Same this script somewhere. I chose /usr/bin/MakeLink and make sure its executable.

#!/bin/bash
######################################################
##
## Script to create symbolic link to mounted Bluray Disc
## By m00nie @ http://wp.me/p25Sys-bR
## 
#######################################################
#
# Where do you want the symlink to be made 
LINK=/home/m00nie/Bluray
# This is the "base dir" where your discs will be mounted by
# the OS. So for Fedora 17 this is /run/media/USERNAME/
MOUNTDIR=/run/media/m00nie
#
##### No changes should be needed beyond here##########
MOUNTPT="a"
{
if [ -h $LINK ]
then
    echo "$LINK found deleting!"
    rm -f $LINK
    echo "Link deleted"
fi
}
# Check where disc is mounted
for dir in `ls -l $MOUNTDIR | awk '; /^d/ {print $9}';`;
do
    for subdir in `ls -l $MOUNTDIR/$dir | awk '; /^d/ {print $9}';`;
    do
        # Check its a Bluray
        if [ $subdir=AACS ]
        then
                MOUNTPT=$MOUNTDIR/$dir
        fi
    done
done
if [ $MOUNTPT = a ]
then
        echo "No mounted disk found in $MOUNTDIR"
        exit 0
fi
echo "Disc found at $MOUNTPT :D"
echo "Creating link at $LINK"
ln -s $MOUNTPT $LINK
echo "Link created"

Now follow this post to create the UDEV rule that fill fire this script automatically when a Bluray is inserted.

m00nie :D