1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#!/bin/bash
if [ $# -gt 1 ] || [ "${1%elp}" = "-h" ] || [ "${1%elp}" = "--h" ] ; then
echo "\
Using karma_helper, logically connect and mount (or unmount and disconnect)
the RK from the USB interface. Assumes the mountpoint is /mnt/karma2.
Without options toggles \"${0##*/} -c\" / \"${0##*/} -u\"
Option -u previously umounts lkarmafs, if mounted.
Usage: ${0##*/} [-h[elp]] [[-]c[onnect]] [[-]u[nconnect]]"
exit 0
fi
#
KH=`which karma_helper`
MNTPOINT=/mnt/karma2 ; OPT=u
#
if [ $# -eq 0 ] ; then
if mount | grep -q "$MNTPOINT.*omfs" ; then OPT=u ; else OPT=c ; fi
else
if [ -z "${1%-c*}" ] || [ -z "${1%c*}" ] ; then OPT=c
elif [ -z "${1%-u*}" ] || [ -z "${1%u*}" ] ; then OPT=u
else echo Unknown option $1 ; $0 -h ; exit 1
fi
fi
#
if [ "$OPT" == "c" ] ; then
echo -n Binding the RK ..." "
sudo $KH -b
echo "done!"
echo -n Mounting the RK on $MNTPOINT" "
if mount | grep -q "$MNTPOINT.*omfs" ; then echo ... was already mounted.
else while ! mount $MNTPOINT 2>/dev/null ; do sleep 1 ; echo -n \. ; done
echo " "mounted!
fi
elif [ "$OPT" == "u" ] ; then
LKARMAMNT=`mount | awk '/lkarmafs/{print $3}'`
if [ ! -z $LKARMAMNT ] ; then
echo -n Unmounting lkarmafs from $LKARMAMNT ..." "
if ! fusermount -u $LKARMAMNT
then echo "*** failed" ; else echo "done!" ; fi
sleep 1
fi
echo -n Unmounting the RK from $MNTPOINT ..." "
if RES=`LANG=C umount $MNTPOINT 2>&1`
then echo "done!" ;
else if echo $RES | grep -q 'is not mounted'
then echo "Not mounted" ; else echo "*** failed!" ; fi
fi
echo -n Unbinding and disconnecting the RK ..." "
for o in u l r ; do sudo $KH -$o ; done
echo "done!"
fi
|