pandora-scripts: First (working) version of mass storage script. Needs more checks :)
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_storage.sh
1 #!/bin/bash
2 while mainsel=$(zenity --title="SD Card Mass Storage" --width="380" --height="200" --list --column "id" --column "Please select" --hide-column=1 --text="What do you want to do?" "sd1" "Switch SD Card 1 to Mass Storage Mode" "sd2" "Switch SD Card 2 to Mass Storage Mode" ); do
3   case $mainsel in
4   "sd1")
5   remount=$(cat /proc/mounts | grep /dev/mmcblk0p1 | awk '{print "mount " $1 " " $2 " -o " $4}' | sed "s/,codepage=[A-Za-z0-9]*,/,/g")
6   if umount /dev/mmcblk0p1
7   then
8     # switch to mass storage
9     rmmod g_cdc
10     modprobe g_file_storage file=/dev/mmcblk0p1 stall=0
11     zenity --title="SD Card 1 Mass Storage Mode" --info --text="SD Card Slot 1 is currently in Mass Storage Mode.\n\nClick on OK when you're finished with your data transfer\nand want to go back to normal mode."
12     rmmod g_file_storage
13     modprobe g_cdc
14     $remount
15   else
16      zenity --title="Error" --error --text="Error.\nEither there is no card in SD Slot 1 or some program\nis currently accessing the card.\n\nPlease make sure to close any programs that currently access te SD Card." --timeout 6
17   fi
18   ;;
19   "sd2")
20   remount=$(cat /proc/mounts | grep /dev/mmcblk0p1 | awk '{print "mount " $1 " " $2 " -o " $4}' | sed "s/,codepage=[A-Za-z0-9]*,/,/g")
21   if umount /dev/mmcblk1p1
22   then
23     # switch to mass storage
24     rmmod g_cdc
25     modprobe g_file_storage file=/dev/mmcblk1p1 stall=0
26     zenity --title="SD Card 2 Mass Storage Mode" --info --text="SD Card Slot 2 is currently in Mass Storage Mode.\n\nClick on OK when you're finished with your data transfer\nand want to go back to normal mode."
27     rmmod g_file_storage
28     insmod g_cdc
29     $remount
30   else
31      zenity --title="Error" --error --text="Error.\nEither there is no card in SD Slot 2 or some program\nis currently accessing the card.\n\nPlease make sure to close any programs that currently access te SD Card." --timeout 6
32   fi
33   ;;
34   esac
35 done