pandora-scripts: try to fix currentuser/home mess
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_createsd.sh
1 #!/bin/bash
2
3 . /usr/pandora/scripts/op_common.sh
4 user=$(get_user)
5
6 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
7 selection2=$(echo "$selection" | sed 's/ /\\\\040/g')
8 device=$(grep "${selection2}" /proc/mounts | awk '{print $1}')
9
10                 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
11                         if label=$(zenity --title="Enter label" --entry --text "Please enter a Label for your SD Card.") ; then
12                                 name="${label// /_}"
13                                 echo Label: $name
14                         else
15                                 name=PANDORA
16                                 echo Label: $name
17                         fi
18                         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
19                                 echo FS: $fstype
20                         else
21                                 fstype=vfat
22                                 echo FS: $fstype
23                         fi
24                         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
25                                 if gksudo umount $device; then
26                                         (
27                                         case $fstype in
28                                                 "vfat")
29                                                 gksudo "mkfs.vfat -F 32 -n "$name" $device"
30                                         ;;
31                                                 "ext2") 
32                                                 gksudo "mkfs.ext2 -L "$name" $device"
33                                         ;;
34                                                 "ext3")
35                                                 gksudo "mkfs.ext3 -L "$name" $device"
36                                         ;;
37                                                 "ext4")
38                                                 gksudo "mkfs.ext4 -L "$name" $device"
39                                         ;;
40                                         esac
41                                 sync
42                                 gksudo mkdir /tmp/mnt
43                                 if gksudo mount $device /tmp/mnt; then
44                                                 gksudo mkdir /tmp/mnt/pandora
45                                                 gksudo mkdir /tmp/mnt/pandora/menu
46                                                 gksudo mkdir /tmp/mnt/pandora/apps
47                                                 gksudo mkdir /tmp/mnt/pandora/desktop
48                                                 gksudo mkdir /tmp/mnt/pandora/appdata
49                                                 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
50                                                 gksudo cp /tmp/README.txt /tmp/mnt/pandora
51                                                 gksudo "chown -R $user:users /tmp/mnt"                          
52                                                 sync
53                                                 gksudo umount $device
54                                                 gksudo rmdir /tmp/mnt   
55                                                 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"
56
57                                 else
58                                         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
59                                 fi
60                                 ) |
61                                                 zenity --progress \
62                                                 --title="Formatting..." \
63                                                 --text="Creating the SD Card...\nPlease wait a while..." \
64                                                 --pulsate
65                         
66                                 else
67                                         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
68                                 fi
69                         fi
70                         
71                 else
72                         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
73                                 mkdir $selection2/pandora
74                                 mkdir $selection2/pandora/menu
75                                 mkdir $selection2/pandora/apps
76                                 mkdir $selection2/pandora/desktop
77                                 mkdir $selection2/pandora/appdata
78                                 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
79                                 gksudo "cp /tmp/README.txt /$selection2/pandora"
80                                 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"
81                         else
82                                  --title="Aborted" --error --text="The directories will not be created." --timeout 10
83                                          
84                         fi
85                 fi
86 fi