#!/bin/sh
# PlayOn!X: auto-mounting script
# Author: mikka [mika.hellmann@gmail.com]

TMP="/tmp/hdd/root"
HOM="/home"
 
# Waiting for HDD mount
n=1
while [ -z "`mount | grep ext`" ]; do
  sleep 3
  [ $n -gt 30 ] && break
  let n+=1
done

sleep 3
mount -o remount,rw /

# Mounting /tmp/hdd/root
if [ -z "`mount | grep "$TMP"`" ]; 
then
  PART=`mount | grep ext | cut -d" " -f3 | sed q`
  echo "Mounting $PART at $TMP"
  mount $PART $TMP
else
  echo "$TMP already exists"
fi

# Linking /home
if [ -n "`mount | grep ufsd`" ]; 
then
  rm -f /home
  PART=`mount | grep ufsd | cut -d" " -f3 | sed q`
  echo "Linking NTFS partition $PART to $HOM"
  ln -sf $PART $HOM
elif [ -n "`mount | grep ext`" ];
then 
  rm -f /home
  PART=`mount | grep ext | cut -d" " -f3 | sed q`
  echo "Linking ext partition $PART to $HOM"
  ln -sf $PART $HOM
else
  echo "No NTFS/ext partitions found"
fi