NTFS/MSDOS improvements
This commit is contained in:
parent
13504fcc86
commit
b217554d9e
15
README
15
README
|
|
@ -32,7 +32,7 @@ Now plugin Your USB thumb drive ;)
|
||||||
Have Fun ;)
|
Have Fun ;)
|
||||||
vermaden
|
vermaden
|
||||||
|
|
||||||
----------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
Latest changes ...
|
Latest changes ...
|
||||||
|
|
||||||
|
|
@ -70,3 +70,16 @@ https://github.com/vermaden/automount
|
||||||
Regards,
|
Regards,
|
||||||
vermaden
|
vermaden
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Latest changes ...
|
||||||
|
|
||||||
|
FAT/NTFS detection improvements.
|
||||||
|
The 'chown' now uses sets user's group.
|
||||||
|
MSDOS filesystem is now mounted with -m 644 -M 755 options by default.
|
||||||
|
Removed POPUP=YES option, just use USER + FM for simplicity.
|
||||||
|
NTFS filesystem, when mounted by mount_ntfs(8) uses -u and -g options by default.
|
||||||
|
Even more simplified 'detach' section.
|
||||||
|
|
||||||
|
Regards,
|
||||||
|
vermaden
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
USERUMOUNT=YES
|
USERUMOUNT=YES
|
||||||
POPUP=YES
|
|
||||||
FM="nautilus --browser --no-desktop"
|
FM="nautilus --browser --no-desktop"
|
||||||
USER=vermaden
|
USER=vermaden
|
||||||
ENCODING=pl_PL.ISO8859-2
|
ENCODING=pl_PL.ISO8859-2
|
||||||
|
|
|
||||||
90
automount.sh
90
automount.sh
|
|
@ -1,10 +1,10 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
# Copyright (c) 2011 Slawomir Wojciech Wojtczak (vermaden)
|
# Copyright (c) 2012 Slawomir Wojciech Wojtczak (vermaden)
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# modification, are permitted provided that the following conditions are met:
|
# modification, are permitted provided that following conditions are met:
|
||||||
# 1. Redistributions of source code must retain the above copyright
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
# notice, this list of conditions and the following disclaimer.
|
# notice, this list of conditions and the following disclaimer.
|
||||||
# 2. Redistributions in binary form must reproduce the above copyright
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
|
@ -26,32 +26,31 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
||||||
|
|
||||||
[ -f /usr/local/etc/automount.conf ] && . /usr/local/etc/automount.conf
|
[ -f /usr/local/etc/automount.conf ] && . /usr/local/etc/automount.conf
|
||||||
|
|
||||||
: ${MNTPREFIX="/media"}
|
: ${MNTPREFIX="/media"} # mount prefix
|
||||||
: ${LOG="/var/log/automount.log"}
|
: ${LOG="/var/log/automount.log"} # log file
|
||||||
: ${STATE="/var/run/automount.state"}
|
: ${STATE="/var/run/automount.state"} # current state file
|
||||||
: ${ENCODING="en_US.ISO8859-1"} # /* US/Canada */
|
: ${ENCODING="en_US.ISO8859-1"} # US/Canada
|
||||||
: ${CODEPAGE="cp437"} # /* US/Canada */
|
: ${CODEPAGE="cp437"} # US/Canada
|
||||||
: ${DATEFMT="%Y-%m-%d %H:%M:%S"} # /* 2012-02-20 07:49:09 */
|
: ${DATEFMT="%Y-%m-%d %H:%M:%S"} # 2012-02-20 07:49:09
|
||||||
: ${USERUMOUNT="NO"} # /* when YES add suid bit to umount(8) */
|
: ${USERUMOUNT="NO"} # when YES add suid bit to umount(8)
|
||||||
: ${POPUP="NO"} # /* display file manager window */
|
: ${USER="0"} # which user to use for popup
|
||||||
: ${USER="0"} # /* which user to use for popup */
|
: ${FM="0"} # which file manager to use
|
||||||
: ${FM="0"} # /* which file manager to use */
|
|
||||||
|
|
||||||
[ "${USERUMOUNT}" = "YES" ] && chmod u+s /sbin/umount # /* WHEEL group member */
|
[ "${USERUMOUNT}" = YES ] && chmod u+s /sbin/umount # WHEEL group member
|
||||||
|
|
||||||
__create_mount_point() { # /* 1=DEV */
|
__create_mount_point() { # 1=DEV
|
||||||
mkdir -p ${MNT}
|
mkdir -p ${MNT}
|
||||||
[ "${USER}" != 0 ] && chown ${USER} ${MNT}
|
[ "${USER}" = 0 ] || chown ${USER}:$( id -g -n ${USER} ) ${MNT}
|
||||||
}
|
}
|
||||||
|
|
||||||
__check_already_mounted() { # /* 1=MNT */
|
__check_already_mounted() { # 1=MNT
|
||||||
mount | grep " ${1} " 1> /dev/null 2> /dev/null && {
|
mount | grep " ${1} " 1> /dev/null 2> /dev/null && {
|
||||||
__log "${DEV}:already mounted (ntfs)"
|
__log "${DEV}:already mounted (ntfs)"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__state_add() { # /* 1=DEV 2=PROVIDER 3=MNT */
|
__state_add() { # 1=DEV 2=PROVIDER 3=MNT
|
||||||
grep -E "${3}$" ${STATE} 1> /dev/null 2> /dev/null && {
|
grep -E "${3}$" ${STATE} 1> /dev/null 2> /dev/null && {
|
||||||
__log "${1}:duplicated '${STATE}'"
|
__log "${1}:duplicated '${STATE}'"
|
||||||
exit 0
|
exit 0
|
||||||
|
|
@ -59,12 +58,12 @@ __state_add() { # /* 1=DEV 2=PROVIDER 3=MNT */
|
||||||
echo "${1} ${2} ${3}" >> ${STATE}
|
echo "${1} ${2} ${3}" >> ${STATE}
|
||||||
}
|
}
|
||||||
|
|
||||||
__state_remove() { # /* 1=MNT 2=STATE */
|
__state_remove() { # 1=MNT
|
||||||
BSMNT=$( echo ${1} | sed 's/\//\\\//g' ) # /* backslash the slashes ;) */
|
BSMNT=$( echo ${1} | sed 's/\//\\\//g' ) # backslash the slashes ;)
|
||||||
sed -i '' "/${BSMNT}\$/d" ${2}
|
sed -i '' "/${BSMNT}\$/d" ${STATE}
|
||||||
}
|
}
|
||||||
|
|
||||||
__log() { # /* @=MESSAGE */
|
__log() { # @=MESSAGE
|
||||||
echo $( date +"${DATEFMT}" ) ${@} >> ${LOG}
|
echo $( date +"${DATEFMT}" ) ${@} >> ${LOG}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,28 +72,30 @@ DEV=/dev/${1}
|
||||||
case ${2} in
|
case ${2} in
|
||||||
(attach)
|
(attach)
|
||||||
ADD=0
|
ADD=0
|
||||||
MNT="${MNTPREFIX}/$( basename ${1} )"
|
MNT="${MNTPREFIX}/${1}"
|
||||||
__check_already_mounted ${MNT}
|
__check_already_mounted ${MNT}
|
||||||
__create_mount_point ${DEV}
|
__create_mount_point ${DEV}
|
||||||
case $( file -b -L -s ${DEV} | sed -E 's/label:\ \".*\"//g' ) in
|
case $( file -b -L -s ${DEV} | sed -E 's/label:\ \".*\"//g' ) in
|
||||||
(*NTFS*)
|
(*FAT*) # must be before NTFS section: newfs_msdos -O NTFS -L NTFS
|
||||||
dd < ${DEV} count=1 2> /dev/null | strings | head -1 | grep -q "NTFS" && {
|
dd < ${DEV} count=1 2> /dev/null | strings | grep "FAT32" && {
|
||||||
which ntfsfix 1> /dev/null 2> /dev/null && {
|
fsck_msdosfs -y ${DEV}
|
||||||
ntfsfix ${DEV} # /* sysutils/ntfsprogs */
|
mount_msdosfs -o large -D ${CODEPAGE} -L ${ENCODING} \
|
||||||
}
|
-m 644 -M 755 ${DEV} ${MNT} && ADD=1
|
||||||
which ntfs-3g 1> /dev/null 2> /dev/null && {
|
__log "${DEV}:mount (fat)"
|
||||||
ntfs-3g -o noatime ${DEV} ${MNT} && ADD=1 # /* sysutils/fusefs-ntfs */
|
|
||||||
} || {
|
|
||||||
mount_ntfs -o noatime ${DEV} ${MNT} && ADD=1
|
|
||||||
}
|
|
||||||
__log "${DEV}:mount (ntfs)"
|
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
(*FAT*)
|
(*NTFS*) # must be after FAT section: newfs_msdos -O NTFS -L NTFS
|
||||||
dd < ${DEV} count=1 2> /dev/null | strings | grep -q "FAT32" && {
|
dd < ${DEV} count=1 2> /dev/null | strings | head -1 | grep "NTFS" && {
|
||||||
fsck_msdosfs -y ${DEV}
|
which ntfsfix 1> /dev/null 2> /dev/null && {
|
||||||
mount_msdosfs -o large -L ${ENCODING} -D ${CODEPAGE} ${DEV} ${MNT} && ADD=1
|
ntfsfix ${DEV} # sysutils/ntfsprogs
|
||||||
__log "${DEV}:mount (fat)"
|
}
|
||||||
|
which ntfs-3g 1> /dev/null 2> /dev/null && {
|
||||||
|
ntfs-3g -o noatime ${DEV} ${MNT} && ADD=1 # sysutils/fusefs-ntfs
|
||||||
|
} || {
|
||||||
|
[ "${USER}" = 0 ] || OPTS="-u ${USER} -g $( id -g -n ${USER} )"
|
||||||
|
mount_ntfs ${OPTS} -o noatime ${DEV} ${MNT} && ADD=1
|
||||||
|
}
|
||||||
|
__log "${DEV}:mount (ntfs)"
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
(*ext2*)
|
(*ext2*)
|
||||||
|
|
@ -109,7 +110,7 @@ case ${2} in
|
||||||
;;
|
;;
|
||||||
(*ext4*)
|
(*ext4*)
|
||||||
fsck.ext4 -y ${DEV}
|
fsck.ext4 -y ${DEV}
|
||||||
ext4fuse ${DEV} ${MNT} && ADD=1 # /* sysutils/fusefs-ext4fuse */
|
ext4fuse ${DEV} ${MNT} && ADD=1 # sysutils/fusefs-ext4fuse
|
||||||
__log "${DEV}:mount (ext4)"
|
__log "${DEV}:mount (ext4)"
|
||||||
;;
|
;;
|
||||||
(*Unix\ Fast\ File*)
|
(*Unix\ Fast\ File*)
|
||||||
|
|
@ -120,28 +121,27 @@ case ${2} in
|
||||||
(*)
|
(*)
|
||||||
case $( dd < ${DEV} count=1 2> /dev/null | strings | head -1 ) in
|
case $( dd < ${DEV} count=1 2> /dev/null | strings | head -1 ) in
|
||||||
(EXFAT)
|
(EXFAT)
|
||||||
mount.exfat -o noatime ${DEV} ${MNT} && ADD=1 # /* sysutils/fusefs-exfat */
|
mount.exfat -o noatime ${DEV} ${MNT} && ADD=1 # sysutils/fusefs-exfat
|
||||||
__log "${DEV}:mount (ufs)"
|
__log "${DEV}:mount (ufs)"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
[ ${ADD} -eq 1 ] && {
|
[ ${ADD} -eq 1 ] && {
|
||||||
|
ADD=0
|
||||||
PROVIDER=$( mount | grep -m 1 " ${MNT} " | awk '{printf $1}' )
|
PROVIDER=$( mount | grep -m 1 " ${MNT} " | awk '{printf $1}' )
|
||||||
__state_add ${DEV} ${PROVIDER} ${MNT}
|
__state_add ${DEV} ${PROVIDER} ${MNT}
|
||||||
[ "${POPUP}" = YES ] && [ "${USER}" != 0 ] && [ "${FM}" != 0 ] \
|
[ "${USER}" != 0 ] && [ "${FM}" != 0 ] \
|
||||||
&& su - ${USER} -c "env DISPLAY=:0 ${FM} ${MNT} &"
|
&& su - ${USER} -c "env DISPLAY=:0 ${FM} ${MNT} &"
|
||||||
ADD=0
|
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(detach)
|
(detach)
|
||||||
M=$( mount )
|
|
||||||
grep -E "${PREFIX}/${1}$" ${STATE} \
|
grep -E "${PREFIX}/${1}$" ${STATE} \
|
||||||
| while read DEV PROVIDER MNT
|
| while read DEV PROVIDER MNT
|
||||||
do
|
do
|
||||||
TARGET=$( echo "$M" | grep -E "^${PROVIDER} " | awk '{print $3}' )
|
TARGET=$( mount | grep -E "^${PROVIDER} " | awk '{print $3}' )
|
||||||
__state_remove ${MNT} ${STATE}
|
__state_remove ${MNT}
|
||||||
[ -z ${TARGET} ] && continue
|
[ -z ${TARGET} ] && continue
|
||||||
umount -f ${TARGET} &
|
umount -f ${TARGET} &
|
||||||
unset TARGET
|
unset TARGET
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue