op_power: make sure powersave is off when turning on display
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_storage.sh
1 #!/bin/bash
2 while selection=$(grep "/dev/mmcblk" /proc/mounts | cut -f 2 -d " " | sed 's/\\040/ /g' | zenity --title="SD Card Mass Storage" --width="380" --height="200" --list --text="Enable mass storage" --column="Select card"); do
3 selection2=$(echo "$selection" | sed 's/ /\\\\040/g')
4 options=$(grep "${selection2}" /proc/mounts | awk '{print $4}' | sed "s/,codepage=[A-Za-z0-9]*,/,/g" | sed 's/\\040/\\ /g' )
5 device=$(grep "${selection2}" /proc/mounts | awk '{print substr($1,1,12)}')
6 device2=$(grep "${selection2}" /proc/mounts | awk '{print $1}')
7
8 if umount $device2; then
9         delay=0
10
11         # remove other gadget modules
12         modules="$(lsmod | awk '{print $1}' | xargs echo)"
13         blacklist="g_zero g_audio g_ether g_serial g_midi gadgetfs g_file_storage
14                 g_mass_storage g_printer g_cdc g_multi g_hid g_dbgp g_nokia g_webcam g_ncm g_acm_ms"
15         restore_list=""
16         for mod in $modules; do
17                 if echo $blacklist | grep -q "\<$mod\>"; then
18                         restore_list="$restore_list $mod"
19                         rmmod $mod
20                         delay=1 # enough?
21                 fi
22         done
23
24         # driver race condition workaround (some kernels crash without wait)
25         sleep $delay
26
27         # switch to mass storage
28         modprobe g_file_storage file=$device stall=0
29
30         zenity --title="Mass Storage Mode" --info --text="SD Card $selection 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."
31
32         rmmod g_file_storage
33
34         if [ ! -d "$selection" ]; then
35                 mkdir "$selection"
36         fi 
37         mount $device2 "$selection" -o $options
38
39         if [ -n "$restore_list" ]; then
40                 sleep $delay
41                 modprobe $restore_list
42         fi
43 else
44         zenity --title="Error" --error --text="Error.\nThe card could not be unmounted.\n\nPlease make sure to close any programs that currently access the SD Card." --timeout 10
45 fi
46
47 done