removed a lot of unneeded code, polish, new features

This commit is contained in:
Slawomir Wojciech Wojtczak (vermaden) 2012-02-20 20:11:45 +01:00
parent 9a84763b97
commit 13504fcc86
3 changed files with 70 additions and 53 deletions

39
README
View File

@ -31,3 +31,42 @@ Now plugin Your USB thumb drive ;)
Have Fun ;) Have Fun ;)
vermaden vermaden
----------
Latest changes ...
I removed the state_lock and stat_unlock mechanisms as they appeared to be not
needed, I have shufled with 3 drives all the time and the 'integrity' has not
been lost, at it was a lot faster, because the lock always had to wait for the
'slowest' drive (in term of initializing the device, like USB hard drive).
I simplified the 'attach' section a lot, now each filesystem contains only
check/fsck (if possible), mount and log info.
I also simplified and improved the 'detach' section a little.
I added an option to automatically launch the set-up in config file manager.
These are options that I currently successfully use for NAUTILUS file manager,
You need to set-up all three of them to make it work.
| POPUP=YES
| FM="nautilus --browser --no-desktop"
| USER=vermaden
My whole config looks like that now:
| USERUMOUNT=YES
| POPUP=YES
| FM="nautilus --browser --no-desktop"
| USER=vermaden
| ENCODING=pl_PL.ISO8859-2
| CODEPAGE=cp852
All latest updates are available at GITHUB repository:
https://github.com/vermaden/automount
Regards,
vermaden

View File

@ -1,2 +1,6 @@
USERUMOUNT=YES USERUMOUNT=YES
POPUP=YES
FM="nautilus --browser --no-desktop"
USER=vermaden
ENCODING=pl_PL.ISO8859-2
CODEPAGE=cp852

View File

@ -33,12 +33,15 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
: ${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 */
: ${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 */
MNT="${MNTPREFIX}/$( basename ${1} )"
mkdir -p ${MNT} mkdir -p ${MNT}
[ "${USER}" != 0 ] && chown ${USER} ${MNT}
} }
__check_already_mounted() { # /* 1=MNT */ __check_already_mounted() { # /* 1=MNT */
@ -48,30 +51,12 @@ __check_already_mounted() { # /* 1=MNT */
} }
} }
__state_lock() {
TIMEOUT=60
COUNT=0
while [ -f ${STATE}.lock ]
do
sleep 0.5
[ ${COUNT} -gt ${TIMEOUT} ] && break
COUNT=$(( ${COUNT} + 1 ))
done
:> ${STATE}.lock
}
__state_unlock() {
rm ${STATE}.lock
}
__state_add() { # /* 1=DEV 2=PROVIDER 3=MNT */ __state_add() { # /* 1=DEV 2=PROVIDER 3=MNT */
__state_lock 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
} }
echo "${1} ${2} ${3}" >> ${STATE} echo "${1} ${2} ${3}" >> ${STATE}
__state_unlock
} }
__state_remove() { # /* 1=MNT 2=STATE */ __state_remove() { # /* 1=MNT 2=STATE */
@ -84,68 +69,57 @@ __log() { # /* @=MESSAGE */
} }
DEV=/dev/${1} DEV=/dev/${1}
ADD=0
case ${2} in case ${2} in
(attach) (attach)
ADD=0
MNT="${MNTPREFIX}/$( basename ${1} )"
__check_already_mounted ${MNT}
__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*) (*NTFS*)
dd < ${DEV} count=1 2> /dev/null | strings | head -1 | grep -q "NTFS" && { dd < ${DEV} count=1 2> /dev/null | strings | head -1 | grep -q "NTFS" && {
__create_mount_point ${DEV} which ntfsfix 1> /dev/null 2> /dev/null && {
which ntfsfix 1> /dev/null 2> /dev/null && { ntfsfix ${DEV} # /* sysutils/ntfsprogs */
ntfsfix ${DEV} # /* sysutils/ntfsprogs */ }
} which ntfs-3g 1> /dev/null 2> /dev/null && {
__check_already_mounted ${MNT} ntfs-3g -o noatime ${DEV} ${MNT} && ADD=1 # /* sysutils/fusefs-ntfs */
which ntfs-3g 1> /dev/null 2> /dev/null && { } || {
ntfs-3g -o noatime ${DEV} ${MNT} && ADD=1 # /* sysutils/fusefs-ntfs */ mount_ntfs -o noatime ${DEV} ${MNT} && ADD=1
} || { }
mount_ntfs -o noatime ${DEV} ${MNT} && ADD=1 __log "${DEV}:mount (ntfs)"
}
__log "${DEV}:mount (ntfs)"
} }
;; ;;
(*FAT*) (*FAT*)
dd < ${DEV} count=1 2> /dev/null | strings | grep -q "FAT32" && { dd < ${DEV} count=1 2> /dev/null | strings | grep -q "FAT32" && {
__create_mount_point ${DEV} fsck_msdosfs -y ${DEV}
fsck_msdosfs -y ${DEV} mount_msdosfs -o large -L ${ENCODING} -D ${CODEPAGE} ${DEV} ${MNT} && ADD=1
__check_already_mounted ${MNT} __log "${DEV}:mount (fat)"
mount_msdosfs -o large -L ${ENCODING} -D ${CODEPAGE} ${DEV} ${MNT} && ADD=1
__log "${DEV}:mount (fat)"
} }
;; ;;
(*ext2*) (*ext2*)
__create_mount_point ${DEV}
fsck.ext2 -y ${DEV} fsck.ext2 -y ${DEV}
mount -t ext2fs -o noatime ${DEV} ${MNT} && ADD=1 mount -t ext2fs -o noatime ${DEV} ${MNT} && ADD=1
__check_already_mounted ${MNT}
__log "${DEV}:mount (ext2)" __log "${DEV}:mount (ext2)"
;; ;;
(*ext3*) (*ext3*)
__create_mount_point ${DEV}
fsck.ext3 -y ${DEV} fsck.ext3 -y ${DEV}
__check_already_mounted ${MNT}
mount -t ext2fs -o noatime ${DEV} ${MNT} && ADD=1 mount -t ext2fs -o noatime ${DEV} ${MNT} && ADD=1
__log "${DEV}:mount (ext3)" __log "${DEV}:mount (ext3)"
;; ;;
(*ext4*) (*ext4*)
__create_mount_point ${DEV}
fsck.ext4 -y ${DEV} fsck.ext4 -y ${DEV}
__check_already_mounted ${MNT}
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*)
__create_mount_point ${DEV}
fsck_ufs -y ${DEV} fsck_ufs -y ${DEV}
__check_already_mounted ${MNT}
mount -o noatime ${DEV} ${MNT} && ADD=1 mount -o noatime ${DEV} ${MNT} && ADD=1
__log "${DEV}:mount (ufs)" __log "${DEV}:mount (ufs)"
;; ;;
(*) (*)
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)
__create_mount_point ${DEV}
__check_already_mounted ${MNT}
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)"
;; ;;
@ -155,27 +129,27 @@ case ${2} in
[ ${ADD} -eq 1 ] && { [ ${ADD} -eq 1 ] && {
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 ] \
&& su - ${USER} -c "env DISPLAY=:0 ${FM} ${MNT} &"
ADD=0 ADD=0
} }
;; ;;
(detach) (detach)
__state_lock 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=$( mount | grep -E "^${PROVIDER} " | awk '{print $3}' ) TARGET=$( echo "$M" | grep -E "^${PROVIDER} " | awk '{print $3}' )
__state_remove ${MNT} ${STATE} __state_remove ${MNT} ${STATE}
[ -z ${TARGET} ] && continue [ -z ${TARGET} ] && continue
umount -f ${TARGET} & umount -f ${TARGET} &
unset TARGET unset TARGET
__log "${DEV}:umount" __log "${DEV}:umount"
done done
__state_unlock
__log "${DEV}:detach" __log "${DEV}:detach"
find ${MNTPREFIX} -type d -empty -delete
;; ;;
esac esac
find ${MNTPREFIX} -type d -empty -delete