Pandora-Scripts: Added check for g_cdc in op_storage.sh
[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     if lsmod | grep g_cdc &>/dev/null
10         then
11         echo Found g_cdc - removing...
12         rmmod g_cdc
13         ethernet=1
14     fi
15     modprobe g_file_storage file=/dev/mmcblk0p1 stall=0
16     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."
17     rmmod g_file_storage
18     if [ $ethernet=1 ]; then
19       echo Reloading g_cdc...
20       modprobe g_cdc
21     fi
22     $remount
23   else
24      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
25   fi
26   ;;
27   "sd2")
28   remount=$(cat /proc/mounts | grep /dev/mmcblk0p1 | awk '{print "mount " $1 " " $2 " -o " $4}' | sed "s/,codepage=[A-Za-z0-9]*,/,/g")
29   if umount /dev/mmcblk1p1
30   then
31     # switch to mass storage
32      if lsmod | grep g_cdc &>/dev/null
33         then
34         echo Found g_cdc - removing...
35         rmmod g_cdc
36         ethernet=1
37     fi
38     modprobe g_file_storage file=/dev/mmcblk1p1 stall=0
39     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."
40     rmmod g_file_storage
41     if [ $ethernet=1 ]; then
42       echo Reloading g_cdc...
43       modprobe g_cdc
44     fi
45     $remount
46   else
47      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
48   fi
49   ;;
50   esac
51 done