#!/bin/bash
set -x

command="$1"
device="$2"

# echo "command= $command" >> /etc/udev.log
# echo "device= $device" >> /etc/udev.log

if [ "$device" = "" ]; then
    echo "No device specified"
    exit
fi

# If the type is the fastec file system, then we're done.
type=$(blkid -o export "$device" | grep "^TYPE=" | sed 's/^TYPE=//')
if [ "$type" = "" ]; then
    exit
fi

if [ "$command" = "add" ]; then
    # Adjust this command to fit your needs.
    if [ "$type" = "vfat" ] || [ "$type" = "exfat" ] || [ "$type" = "ntfs" ]; then
        udisksctl mount -o noexec,nodev,noatime,gid=995,umask=0002 -b "$device"
    else
        udisksctl mount -o noatime -b "$device"
    fi
elif [ "$command" = "remove" ]; then
    udisksctl unmount -b "$device"
fi

