#!/bin/sh
# Netgear Samba Shares path mapping

# Command line arguments
HOST_STORAGE_DEVICES_INFO_GUEST="$1"
GUEST_MOUNT_PREFIX="$2"

# Files and Directories
SHARES_DIR="/tmp/shares"

# Make sure we have some shares
if [ "`ls -A ${SHARES_DIR} 2>/dev/null`" == "" ]; then
    exit 0
fi

# Mapping for /tmp/shares links
for file in ${SHARES_DIR}/*
do
    if [ -L "$file" ]; then
        dlna_path="$file"
        mount_point=`readlink -f -n "$file"`
        if [ "${mount_point}" == "" ]; then
            continue
        fi
        line=`grep "$mount_point" ${HOST_STORAGE_DEVICES_INFO_GUEST}`
        if [ "${line}" == "" ]; then
            continue
        fi
        uuid=`echo "$line" | awk '{ print $2 }'`
        #label=`echo "$line" | awk '{ print $4 }'`
        chroot_path="${GUEST_MOUNT_PREFIX}$uuid"
        if [ -n "$chroot_path" ]; then
            echo "$dlna_path $chroot_path $uuid"
        fi
    fi
done
