#!/bin/sh
#
# (c) 2003-2007 Linbox FAS, http://linbox.com
# (c) 2008-2009 Mandriva, http://www.mandriva.com
#
# $Id$
#
# This file is part of Pulse 2, http://pulse2.mandriva.org
#
# Pulse 2 is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Pulse 2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pulse 2; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# NTFS / VFAT / EXT234 Mounting
#

# Time to load fuse kids...
#grep -q '^fuse' /proc/modules || insmod /opt/lib/modules/fuse.ko
# bpo 20151222 : no more necessary

device=${1}

# Is there a parameter ?
if [ ! -z ${device} ]; then
  # Does it looks like being a block device ?
  if [ -b ${device} ]; then
    # Clean mountpoint first
    umount /mnt >/dev/null 2>&1
    # Try to mount as ntfs first (mount.ntfs is a symlink to ntfs-3g binary)
    if mount.lowntfs-3g -o ignore_case -o remove_hiberfile ${device} /mnt; then
      echo "*** INFO: ${device} successfully mounted as /mnt (NTFS-3G)"
    # Use regular mount command (linux stuff)
    elif mount ${device} /mnt; then
      echo "*** INFO: ${device} successfully mounted as /mnt"
    else
      echo "*** ERROR: Unable to mount device ${device}"
      exit 1
    fi
    echo $device >/tmp/partname
  else
    echo "*** ERROR: Paramater isn't a block device (trying to mount ${device})" 
    exit 1
  fi
else
  echo "*** ERROR: No parameter" 
  exit 1
fi
