Various fixes. Add MTP/XFS/HFS support. Remove delays.

This commit is contained in:
vermaden 2018-12-08 05:53:16 +01:00
parent c4921bb118
commit fc951d10bc
2 changed files with 398 additions and 236 deletions

19
README
View File

@ -20,6 +20,11 @@ Now plugin Your USB thumb drive and have fun ;)
* sysutils/automount * sysutils/automount
* sysutils/exfat-utils * sysutils/exfat-utils
* sysutils/fusefs-exfat * sysutils/fusefs-exfat
* sysutils/fusefs-ntfs
* sysutils/fusefs-ext4fuse
* sysutils/fusefs-simple-mtpfs
* sysutils/fusefs-hfsfuse
* sysutils/fusefs-lkl
Regards, Regards,
vermaden vermaden
@ -29,7 +34,19 @@ vermaden
C H A N G E L O G C H A N G E L O G
========================= =========================
VERSION 1.5.8 (CURRENT) -------------------------------------------------------------------------------
VERSION 1.5.9 (CURRENT)
Decreese DELAY for sleep from '1' to '0.1' for faster monting.
Remove __random_wait() at 'attach'.
Implement MTP mounting.
Added XFS and HFS support.
Various fixes and cleanups.
-------------------------------------------------------------------------------
VERSION 1.5.8
Omit GVFS filesystem in the mount(8) listing. Omit GVFS filesystem in the mount(8) listing.
Improve exFAT mount options. Improve exFAT mount options.

213
automount
View File

@ -29,12 +29,15 @@ __usage() {
AUTOMOUNT is a devd(8) based automounter for FreeBSD. AUTOMOUNT is a devd(8) based automounter for FreeBSD.
It supports following file systems: It supports following file systems:
UFS/FAT/exFAT/NTFS/EXT2/EXT3/EXT4 UFS/FAT/exFAT/NTFS/EXT2/EXT3/EXT4/MTP/HFS
It needs these ports to mount NTFS/exFAT/EXT4 respectively: Add these to mount NTFS/exFAT/EXT4/MTP/HFS/XFS respectively:
o sysutils/fusefs-ntfs o sysutils/fusefs-ntfs
o sysutils/fusefs-exfat o sysutils/fusefs-exfat
o sysutils/fusefs-ext4fuse o sysutils/fusefs-ext4fuse
o sysutils/fusefs-simple-mtpfs
o sysutils/fusefs-hfsfuse
o sysutils/fusefs-lkl
By default it mounts/unmounts all removable media but By default it mounts/unmounts all removable media but
it is possible to set some additional options at the it is possible to set some additional options at the
@ -137,7 +140,7 @@ EOF
if [ "${1}" = "--version" -o "${1}" = "-version" -o "${1}" = "version" ] if [ "${1}" = "--version" -o "${1}" = "-version" -o "${1}" = "version" ]
then then
echo "automount 1.5.8 2018/06/13" echo "automount 1.5.9 2018/12/08"
exit 0 exit 0
fi fi
@ -163,7 +166,7 @@ fi
: ${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
: ${TIMEOUT="8"} # stop waiting for device after that time : ${TIMEOUT="8"} # stop waiting for device after that time
: ${DELAY="1"} # check for the device node that often : ${DELAY="0.1"} # check for the device node that often
: ${BOOTDELAY="45"} # wait for boot process to complete : ${BOOTDELAY="45"} # wait for boot process to complete
: ${NOTIFY="NO"} # use 'notify-send' and 'libnotify' : ${NOTIFY="NO"} # use 'notify-send' and 'libnotify'
: ${WALL="NO"} # use 'wall(1)' : ${WALL="NO"} # use 'wall(1)'
@ -176,12 +179,16 @@ then
fi fi
__create_mount_point() { # 1=DEV __create_mount_point() { # 1=DEV
mkdir -p ${MNT} local DEVICE=${1##*/}
mkdir -p ${MNTPREFIX}/${DEVICE}
if [ "${USER}" != 0 ] if [ "${USER}" != 0 ]
then then
chown ${USER}:$( id -g -n ${USER} ) ${MNT} chown ${USER}:$( id -g -n ${USER} ) ${MNTPREFIX}/${DEVICE}
UID=$( id -u ${USER} ) UID=$( id -u ${USER} )
GID=$( id -g ${USER} ) GID=$( id -g ${USER} )
else
UID=0
GID=0
fi fi
} }
@ -291,19 +298,19 @@ __wait_for_boot() {
fi fi
} }
__random_wait() { # __random_wait() {
RANDOM=$( head -c 256 /dev/urandom | env LC_ALL=C tr -c -d '1-9' ) # RANDOM=$( head -c 256 /dev/urandom | env LC_ALL=C tr -c -d '1-9' )
MODULO=$(( ${RANDOM} % 24 )) # MODULO=$(( ${RANDOM} % 24 ))
WAIT=$( echo ${MODULO} / 10 | bc -l ) # WAIT=$( echo ${MODULO} / 10 | bc -l )
WAIT_TEST=$( echo ${WAIT} | awk -F'.' '{print $1}' ) # WAIT_TEST=$( echo ${WAIT} | awk -F'.' '{print $1}' )
if [ "${WAIT_TEST}" = "" ] # if [ "${WAIT_TEST}" = "" ]
then # then
WAIT="0${WAIT}" # WAIT="0${WAIT}"
fi # fi
WAIT=$( printf "%.1f" ${WAIT} ) # WAIT=$( printf "%.1f" ${WAIT} )
sleep ${WAIT} # sleep ${WAIT}
__log "${DEV}: random wait for '${WAIT}' seconds before 'attach' action" # __log "${DEV}: random wait for '${WAIT}' seconds before 'attach' action"
} # }
__fstype() { # 1=DEV __fstype() { # 1=DEV
TYPE=$( dd < ${DEV} count=1 2> /dev/null | strings | head -1 ) TYPE=$( dd < ${DEV} count=1 2> /dev/null | strings | head -1 )
@ -334,6 +341,16 @@ __fstype() { # 1=DEV
TYPE=EXT4 TYPE=EXT4
return return
fi fi
if echo "${TYPE}" | grep -q 'SGI XFS'
then
TYPE=XFS
return
fi
if echo "${TYPE}" | grep -q 'Macintosh HFS'
then
TYPE=HFS
return
fi
if echo "${TYPE}" | grep -q 'boot sector' if echo "${TYPE}" | grep -q 'boot sector'
then then
TYPE=$( file -r -k -b -L -s ${DEV} | sed -E 's/label:\ \".*\"//g' ) TYPE=$( file -r -k -b -L -s ${DEV} | sed -E 's/label:\ \".*\"//g' )
@ -368,12 +385,91 @@ __fstype() { # 1=DEV
} }
DEV=/dev/${1} DEV=/dev/${1}
__wait_for_boot __wait_for_boot
case ${1} in
(ugen*)
case ${2} in
case ${2} in
(attach) (attach)
__random_wait # __random_wait
__log "${DEV}: attach"
if [ "${BLACKLIST}" != "" ]
then
__log "${DEV}: using BLACKLIST='${BLACKLIST}'"
for I in ${BLACKLIST}
do
if [ ${1} = "${I}" ]
then
__log "${DEV}: device blocked by BLACKLIST option"
exit 0
fi
done
fi
ADD=0
MNT="${MNTPREFIX}/${1}"
__check_already_mounted -d ${DEV}
__check_already_mounted -m ${MNT}
__wait_for_device ${DEV}
PHONEDEV=$( simple-mtpfs --list-devices -d ${DEV} 2>&1 )
if [ "${PHONEDEV}" = "No raw devices found." ]
then
__log "${DEV}: no raw devices found"
exit 0
else
PHONEDEV=$( echo "${PHONEDEV}" | awk '{print $1}' | tr -d ':' )
fi
__create_mount_point ${DEV}
simple-mtpfs --device ${PHONEDEV} ${MNT} -o uid=${UID} -o gid=${GID} -o allow_other
if [ ${?} -ne 0 ]
then
su - ${USER} -c "env DISPLAY=:0 zenity --info --text 'Allow on the Phone.\n\nThen click OK.' --no-wrap"
exit 0
else
# simple-mtpfs --device ${PHONEDEV} ${MNT} -o uid=${UID} -o gid=${GID} -o allow_other
PROVIDER=$( mount | grep -m 1 " ${MNT} " | awk '{printf $1}' )
__state_add ${DEV} ${PROVIDER} ${MNT}
if [ "${USER}" != 0 -a "${FM}" != 0 ]
then
su - ${USER} -c "env DISPLAY=:0 ${FM} ${MNT} &"
fi
fi
;;
(detach)
__log "${DEV}: detach"
if [ -f ${STATE} ]
then
grep -E "${MNTPREFIX}/${1}$" ${STATE} \
| while read DEV PROVIDER MNT
do
TARGET=$( mount | grep -v \.gvfs | grep -m 1 -E "^${PROVIDER} " | awk '{print $3}' )
__state_remove ${MNT}
if [ -z ${TARGET} ]
then
continue
fi
( # put entire umount/find/rm block into background
umount -f ${TARGET}
__remove_dir "${TARGET}"
__log "${DEV}: removed '${TARGET}'"
) &
unset TARGET
__log "${DEV}: umount"
done
__remove_dir "${MNTPREFIX}/${1}"
__log "${DEV}: mount point '${MNTPREFIX}/${1}' removed"
fi
;;
esac
;;
(da*|mmcsd*)
case ${2} in
(attach)
# __random_wait
__log "${DEV}: attach" __log "${DEV}: attach"
if [ "${BLACKLIST}" != "" ] if [ "${BLACKLIST}" != "" ]
then then
@ -398,6 +494,7 @@ case ${2} in
__wait_for_device ${DEV} __wait_for_device ${DEV}
__fstype ${DEV} __fstype ${DEV}
case ${TYPE} in case ${TYPE} in
(UFS) (UFS)
__create_mount_point ${DEV} __create_mount_point ${DEV}
__wait_for_device ${DEV} __wait_for_device ${DEV}
@ -414,8 +511,9 @@ case ${2} in
__log "${DEV}: mount failed (ufs) 'mount -t ufs ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (ufs) 'mount -t ufs ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (ufs)" __log "${DEV}: mount (ufs) 'mount -t ufs ${OPTS} ${DEV} ${MNT}'"
;; ;;
(FAT) # must be before NTFS section because: newfs_msdos -O NTFS -L NTFS (FAT) # must be before NTFS section because: newfs_msdos -O NTFS -L NTFS
__create_mount_point ${DEV} __create_mount_point ${DEV}
__wait_for_device ${DEV} __wait_for_device ${DEV}
@ -431,7 +529,7 @@ case ${2} in
else else
USEROPTS="" USEROPTS=""
fi fi
FATCMD=$( mount_msdosfs ${OPTS} -o large -o longnames -m 644 -M 755 -D ${CODEPAGE} -L ${ENCODING} ${USEROPTS} ${DEV} ${MNT} ) FATCMD="mount_msdosfs ${OPTS} -o longnames -m 644 -M 755 -D ${CODEPAGE} -L ${ENCODING} ${USEROPTS} ${DEV} ${MNT}"
if ${FATCMD} if ${FATCMD}
then then
ADD=1 ADD=1
@ -440,13 +538,13 @@ case ${2} in
FATCUR=0 FATCUR=0
while sleep 1 while sleep 1
do do
FATCUR=$(( FATCUR + 1 )) FATCUR=$(( ${FATCUR} + 1 ))
if [ ${FATCUR} -gt ${FATOUT} ] if [ ${FATCUR} -gt ${FATOUT} ]
then then
__log "${DEV}: mount failed (fat) 'mount_msdosfs ${OPTS} -o large -o longnames -D ${CODEPAGE} -L ${ENCODING} -m 644 -M 755 ${USEROPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (fat) '${FATCMD}'"
break break
fi fi
FATCMD ${FATCMD}
if [ ${?} -eq 0 ] if [ ${?} -eq 0 ]
then then
ADD=1 ADD=1
@ -457,8 +555,14 @@ case ${2} in
done done
exit 1 exit 1
fi fi
__log "${DEV}: mount (fat)" if [ ${ADD} -eq 1 ]
then
__log "${DEV}: mount (fat) '${FATCMD}'"
else
__log "${DEV}: mount failed (fat) '${FATCMD}'"
fi
;; ;;
(NTFS) # must be after FAT section: newfs_msdos -O NTFS -L NTFS (NTFS) # must be after FAT section: newfs_msdos -O NTFS -L NTFS
__create_mount_point ${DEV} __create_mount_point ${DEV}
__wait_for_device ${DEV} __wait_for_device ${DEV}
@ -491,8 +595,9 @@ case ${2} in
exit 1 exit 1
fi fi
fi fi
__log "${DEV}: mount (ntfs)" __log "${DEV}: mount (ntfs) 'mount_ntfs ${OPTS} ${DEV} ${MNT}'"
;; ;;
(EXT2) (EXT2)
__create_mount_point ${DEV} __create_mount_point ${DEV}
__wait_for_device ${DEV} __wait_for_device ${DEV}
@ -509,8 +614,9 @@ case ${2} in
__log "${DEV}: mount failed (ext2) 'mount -t ext2fs ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (ext2) 'mount -t ext2fs ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (ext2)" __log "${DEV}: mount (ext2) 'mount -t ext2fs ${OPTS} ${DEV} ${MNT}'"
;; ;;
(EXT3) (EXT3)
__create_mount_point ${DEV} __create_mount_point ${DEV}
__wait_for_device ${DEV} __wait_for_device ${DEV}
@ -527,8 +633,9 @@ case ${2} in
__log "${DEV}: mount failed (ext3) 'mount -t ext2fs ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (ext3) 'mount -t ext2fs ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (ext3)" __log "${DEV}: mount (ext3) 'mount -t ext2fs ${OPTS} ${DEV} ${MNT}'"
;; ;;
(EXT4) (EXT4)
__create_mount_point ${DEV} __create_mount_point ${DEV}
__wait_for_device ${DEV} __wait_for_device ${DEV}
@ -545,8 +652,9 @@ case ${2} in
__log "${DEV}: mount failed (ext4) 'ext4fuse ${DEV} ${MNT}'" __log "${DEV}: mount failed (ext4) 'ext4fuse ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (ext4)" __log "${DEV}: mount (ext4) 'ext4fuse ${DEV} ${MNT}'"
;; ;;
(EXFAT) (EXFAT)
__create_mount_point ${DEV} __create_mount_point ${DEV}
__wait_for_device ${DEV} __wait_for_device ${DEV}
@ -562,15 +670,49 @@ case ${2} in
then then
ADD=1 ADD=1
else else
__log "${DEV}: mount failed (exfat) 'mount.exfat ${OPTS} ${USEROPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (exfat) 'mount.exfat ${OPTS} ${USEROPTS} -o dmask=022 -o fmask=133 -o noatime ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (exfat)" __log "${DEV}: mount (exfat) 'mount.exfat ${OPTS} ${USEROPTS} -o dmask=022 -o fmask=133 -o noatime ${DEV} ${MNT}'"
;; ;;
(XFS)
__create_mount_point ${DEV}
__wait_for_device ${DEV}
xfs_repair -d ${DEV} \
| while read LINE
do
__log "${DEV}: xfs_repair ${LINE}"
done
__wait_for_device ${DEV}
if lklfuse -o type=xfs -o allow_other -o uid=${UID} -o gid=${GID} ${DEV} ${MNT} # sysutils/fusefs-lkl
then
ADD=1
else
__log "${DEV}: mount failed (xfs) 'lklfuse -o type=xfs -o allow_other -o uid=${UID} -o gid=${GID} ${DEV} ${MNT}'"
exit 1
fi
__log "${DEV}: mount (xfs) 'lklfuse -o type=xfs -o allow_other -o uid=${UID} -o gid=${GID} ${DEV} ${MNT}'"
;;
(HFS)
__create_mount_point ${DEV}
__wait_for_device ${DEV}
if hfsfuse --force -o noatime ${DEV} ${MNT} # sysutils/fusefs-hfsfuse
then
ADD=1
else
__log "${DEV}: mount failed (hfs) 'hfsfuse --force -o noatime ${DEV} ${MNT}'"
exit 1
fi
__log "${DEV}: mount (hfs) 'hfsfuse --force -o noatime ${DEV} ${MNT}'"
;;
(*) (*)
__log "${DEV}: filesystem not supported or no filesystem" __log "${DEV}: filesystem not supported or no filesystem"
exit 0 exit 0
;; ;;
esac esac
if [ ${ADD} -eq 1 ] if [ ${ADD} -eq 1 ]
then then
@ -610,4 +752,7 @@ case ${2} in
fi fi
;; ;;
esac
;;
esac esac