op_power: reload modules correctly
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_createsd.sh
1 #!/bin/bash
2 if selection=$(grep "/dev/mmcblk" /proc/mounts | cut -f 2 -d " " | sed 's/\\040/ /g' | zenity --title="Create Pandora SD Card" --width="380" --height="250" --list --text="This utility creates the needed Pandora directories on your SD Card.\nYou can also use it to format your SD Card.\n\nPlease select the SD Card to be used (no data will be changed yet):" --column="Select card"); then
3 selection2=$(echo "$selection" | sed 's/ /\\\\040/g')
4 device=$(grep "${selection2}" /proc/mounts | awk '{print $1}')
5
6                 if zenity --question --title="Format SD Card" --text="Do you also want to format your SD Card?\n\nNote: This will delete ALL existing data on the card!" --ok-label="Yes, format the card!" --cancel-label="Don't format it"; then
7                         if label=$(zenity --title="Enter label" --entry --text "Please enter a Label for your SD Card.") ; then
8                                 name="${label// /_}"
9                                 echo Label: $name
10                         else
11                                 name=PANDORA
12                                 echo Label: $name
13                         fi
14                         if fstype=$(zenity --title="Filesystem" --width="350" --height="320" --list --column "fs" --column "Please select" --hide-column=1 --text="The Pandora supports the following file systems.\n\nIt is strongly recommended to use VFAT (FAT32)\nto ensure a maximum compatibility with other devices.\nOnly select a different filesystem if you know what you're doing.\n" "vfat" "VFAT (FAT32), recommended." "ext2" "ext2" "ext3" "ext3" "ext4" "ext4" --ok-label="Select filesystem" ); then
15                                 echo FS: $fstype
16                         else
17                                 fstype=vfat
18                                 echo FS: $fstype
19                         fi
20                         if zenity --question --title="Confirm Pandora SD Card Creation" --text="The Pandora will now format your SD Card and create all the needed directories.\n\nALL EXISTING DATA WILL BE DELETED!\n\nPlease confirm the following selection:\nThe card will be formatted with $fstype and labelled $name.\n" --ok-label="Yes, do it" --cancel-label="Don't do it"; then
21                                 if gksudo umount $device; then
22                                         (
23                                         case $fstype in
24                                                 "vfat")
25                                                 gksudo "mkfs.vfat -n "$name" $device"
26                                         ;;
27                                                 "ext2") 
28                                                 gksudo "mkfs.ext2 -L "$name" $device"
29                                         ;;
30                                                 "ext3")
31                                                 gksudo "mkfs.ext3 -L "$name" $device"
32                                         ;;
33                                                 "ext4")
34                                                 gksudo "mkfs.ext4 -L "$name" $device"
35                                         ;;
36                                         esac
37                                 sync
38                                 gksudo mkdir /tmp/mnt
39                                 if gksudo mount $device /tmp/mnt; then
40                                                 user=$(cat /tmp/currentuser)
41                                                 gksudo mkdir /tmp/mnt/pandora
42                                                 gksudo mkdir /tmp/mnt/pandora/menu
43                                                 gksudo mkdir /tmp/mnt/pandora/apps
44                                                 gksudo mkdir /tmp/mnt/pandora/desktop
45                                                 gksudo mkdir /tmp/mnt/pandora/appdata
46                                                 echo -e "Place all PNDs that should appear in the menu into the menu-subfolder.\nPlace all PNDs that should appear on the desktop in the desktop-subfolder.\nPlace all PNDs that should appear both on the desktop AND in the menu into the apps-subfolder.\n\nPNDs will save their configuration into the appdata-subfolder." > /tmp/README.txt
47                                                 gksudo cp /tmp/README.txt /tmp/mnt/pandora
48                                                 gksudo "chown -R $user:users /tmp/mnt"                          
49                                                 sync
50                                                 gksudo umount $device
51                                                 gksudo rmdir /tmp/mnt   
52                                                 zenity --info --title="Directories created" --text "The needed directories have been created.\n\nPlease put your PNDs into:\n\\\pandora\\\menu\n\\\pandora\\\desktop\n\\\pandora\\\apps\n\nPlease remove and reinsert the card to remount it.\n"
53
54                                 else
55                                         zenity --title="Error" --error --text="Error.\nThe card could not be remounted, something probably went wrong formatting it.\n\nPlease remove and reinsert the card and try again." --timeout 10
56                                 fi
57                                 ) |
58                                                 zenity --progress \
59                                                 --title="Formatting..." \
60                                                 --text="Creating the SD Card...\nPlease wait a while..." \
61                                                 --pulsate
62                         
63                                 else
64                                         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
65                                 fi
66                         fi
67                         
68                 else
69                         if zenity --question --title="Confirm Pandora SD Card Creation" --text="The Pandora will now create all the needed directories on your SD Card.\n\nNo existing data will be deleted.\n\nPlease confirm the creation of the directories.\n" --ok-label="Yes, do it" --cancel-label="Don't do it"; then
70                                 mkdir $selection2/pandora
71                                 mkdir $selection2/pandora/menu
72                                 mkdir $selection2/pandora/apps
73                                 mkdir $selection2/pandora/desktop
74                                 mkdir $selection2/pandora/appdata
75                                 echo -e "Place all PNDs that should appear in the menu into the menu-subfolder.\nPlace all PNDs that should appear on the desktop in the desktop-subfolder.\nPlace all PNDs that should appear both on the desktop AND in the menu into the apps-subfolder.\n\nPNDs will save their configuration into the appdata-subfolder." > /tmp/README.txt
76                                 gksudo "cp /tmp/README.txt /$selection2/pandora"
77                                 zenity --info --title="Directories created" --text "The needed directories have been created.\n\nPlease put your PNDs into:\n\\\pandora\\\menu\n\\\pandora\\\desktop\n\\\pandora\\\apps\n"
78                         else
79                                  --title="Aborted" --error --text="The directories will not be created." --timeout 10
80                                          
81                         fi
82                 fi
83 fi