From 589871214efbfc57f574db8af6dc7916828575f9 Mon Sep 17 00:00:00 2001 From: mfrasca <> Date: Tue, 6 Sep 2005 17:16:40 +0000 Subject: [PATCH] small bash utility for use with mountable media. tmount as ToggleMOUNT. it mounts or unmounts a user-mountable filesystem. --- pywmhdmon/tmount | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pywmhdmon/tmount diff --git a/pywmhdmon/tmount b/pywmhdmon/tmount new file mode 100644 index 0000000..943ffac --- /dev/null +++ b/pywmhdmon/tmount @@ -0,0 +1,35 @@ +#!/bin/sh + +# tmount - toggle mount / eject +# +# usage: tmount mountpoint ejectable +# +# parameter mountpoint: the mount point, without trailing '/' +# ejectable: not empty indicates that the media is software ejectable +# action: if the indicated file system is not mounted, mounts it +# otherwise unmounts it +# if mounting fails or when unmounting, ejects software ejectable +# media. + +if [ "$2" == "" ]; then eject=echo +else eject=eject +fi + +mountpointIndicated=$1 +mountpointFound=`df $1 | tail -1 | cut -d% -f2` + +if [ $mountpointIndicated = $mountpointFound ] + then + + umount $mountpointIndicated + $eject $mountpointIndicated + +else + + # my smartmedia does not mount correctly after a media change + # second try always succeeds. ask me why! if neither mount + # attempt succeeds, then attempt ejecting ejectable media + + mount $mountpointIndicated || mount $mountpointIndicated || $eject $mountpointIndicated + +fi