#!/bin/sh

#
# Mountpoint mapper for automounter
#

#
#smbfs ignores all options when it sees 'noatime'
#
STD="" #STD=",noatime"

OPT=""
# Replace @ by / in mount
MOUNT=`echo $1 | sed 's/@/\//g'`

# Separate mount and options: mount%options
if test "${MOUNT/*%*/exists}" = "exists"; then # there is a '%'
    OPT=,`echo ${MOUNT/*%/}`
    SZ=$(( ${#MOUNT} - ${#OPT} ))
    MOUNT=`echo ${MOUNT:0:$SZ}`
fi

OPT="$OPT$STD"

while true; do
    case "$MOUNT" in
    ro.*)
        OPT=",ro$OPT"
        MOUNT="${MOUNT:3:9999}"
        ;;
    dev.*) # format is: dev.name[%options]
        OPT=",fstype=auto$OPT"
        echo "-${OPT:1:9999} :/dev/${MOUNT:4:9999}"
        exit 0
        ;;
    vfat.*) # format is: vfat.name[%options]
        OPT=",fstype=vfat,umask=000,quiet,nocase,nosuid,noexec,uni_xlate=1,codepage=866,iocharset=koi8-r$OPT"
        echo "-${OPT:1:9999} :/dev/${MOUNT:5:9999}"
        exit 0
        ;;
    ntfs.*) # format is: ntfs.name[%options]
        OPT=",fstype=ntfs,iocharset=koi8-r,ro$OPT"
        echo "-${OPT:1:9999} :/dev/${MOUNT:5:9999}"
        exit 0
        ;;
    smb.*) # format is: smb.host@share[%options]
        OPT=",fstype=smbfs,fmask=644,dmask=755,codepage=cp866,iocharset=koi8-r,$OPT"
        echo "-${OPT:1:9999} ://${MOUNT:4:9999}"
        exit 0
        ;;
    nfs.*) # format is: nfs.host:@dir[@dir]...[%options]
        OPT=",fstype=nfs$OPT"
        echo "-${OPT:1:9999} ${MOUNT:4:9999}"
        exit 0
        ;;
    *) # format is: name[%options]
        OPT=",fstype=auto$OPT"
        echo "-${OPT:1:9999} :/dev/$MOUNT"
        exit 0
        ;;
    esac
done
