View Single Post
int_ua's Avatar
Posts: 676 | Thanked: 1,067 times | Joined on Jul 2010 @ Kyiv, Ukraine
#19
just wrote this script while travelling by the subway:
Code:
#!/bin/sh
# mmc-mounter 0.1
# Licence: GPLv3
# The script was written for Maemo 5 on Nokia N900
# to ease mounting multiple microSD partitions
# since the system wasn't able to recognise them.
# I hope it can help on other devices or OSes too.
# (c) 2010 Serhiy Zagoriya (int_ua)
# *please* mail bugs and feature requests to xintx.ua@gmail.com

if [ "$1" == "mount" ]; then
for partition in `ls /dev/mmcblk1p* | grep -o "[0-9]$"`; do
 echo "Partition "$partition
 mkdir -p /home/user/mmc/$partition
 sudo mount /dev/mmcblk1p$partition /home/user/mmc/$partition
 mountresponse=$?
 if [[ $mountresponse != 0 ]]; then
  if [[ $mountresponse == 255 ]]; then 
   echo "Already mounted"
   continue
  fi
  echo "Failed to mount /dev/mmcblk1p$partition automatically."
  read -p "If you know it's filesystem type, type it, ortherwise just press Enter: " fstype
  if [ "$fstype" != "" ]; then
   echo "mounting /dev/mmcblk1p$partition with '-t $fstype' option"
   sudo mount -t $fstype /dev/mmcblk1p$partition /home/user/mmc/$partition
  fi
 fi
done
#read -p "press Enter to close" None
exit 0
fi

if [ "$1" == "unmount" ]; then
for mountpoint in `cat /etc/mtab | grep -o "/dev/mmcblk1p[0-9]*"`; do 
 echo "Unmounting $mountpoint"
 sudo umount $mountpoint -f
 if [[ $? != 0 ]]; then
  lsof | grep /home/user/mmc/`echo $mountpoint | grep -o "[0-9]*"`
  echo -e "---\nCannot unmount partition $mountpoint. If it was mounted using mmc-mount script and there was opened files on it they are listed above (with lsof command)."
 fi
done
#read -p "press Enter to close" None
exit 0
fi

echo "usage: mmc-mounter.sh {mount|unmount}"
exit 1
Tomorrow I will try to enhance it with all your advices, especially Patola's one
I hope it will become alternative for those who don't want to mess with system files