32180cbf2fea81ac89d60af5f49a2d254c5b97e4
[openpandora.oe.git] / recipes / pandora-system / pandora-first-run-wizard / first-run-wizard.sh
1 #!/bin/sh
2
3 # Initially based on the scripts by JohnX/Mer Project - http://wiki.maemo.org/Mer/
4 # Reworked for the OpenPandora - John Willis/Michael Mrozek
5
6 # You can start the wizard from the shell using 'xinit ./first-boot-init.sh'
7
8 export LANG=en_GB.UTF-8
9 export GTK2_RC_FILES=/usr/share/themes/Xfce/gtk-2.0/gtkrc
10
11 # Ensure there is a wheel group for sudoers to be put into.
12 # TODO: Do this somewhere better.
13 groupadd wheel
14
15 # We load up a background image here.
16 export WALLPAPER='/usr/share/xfce4/backdrops/op-firstrun.png'
17 hsetroot -center $WALLPAPER
18
19 # Default error message (should a user hit cancel, validation fail etc.).
20 ERROR_WINDOW='zenity --title="Error" --error --text="Sorry! Please try again." --timeout 6'
21
22 RESET_ROOT="yes"
23
24 # Greet the user.
25
26 zenity --info --title="Pandoras Box has been opened." --text="Welcome!\n\nPandora's Box has been opened.\n\nThis wizard will help you setting up your new OpenPandora handheld before the first use.\n\nYou will be asked a few simple questions to personalise and configure your device for use." --timeout 45
27
28 # ----
29
30 # Reset ROOT's password to something random 
31
32 # (I know the image build sets the password to something pusdo-random)
33 # (ok, urandom is not 100% secure but it's good enough for our needs)
34
35 if [ $RESET_ROOT == "yes" ]; then
36         rootpwd=$(cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?"|fold -w 30|head -n 1)
37 passwd "root" <<EOF
38 $rootpwd
39 $rootpwd
40 EOF
41         rootpwd=""
42 fi
43
44 # ----
45
46 # Ask the user to calibrate the touchscreen.
47
48 if zenity --question --title="Touchscreen calibration" --text="It is recommended to calibrate and test the device touchscreen.\n\nDo you wish to calibrate the touchscreen now?" --ok-label="Yes" --cancel-label="No"; then 
49         # Make sure we have a sane environment as this script will be run long before any /etc/profile stuff.
50         . /etc/profile.d/tslib.sh
51         # Delete the pointercal file (do we want to do that?)
52         # rm /etc/pointercal
53         # Spawn the ts_* tools as subprocesses that will return to the script.
54         echo Running ts_calibrate       
55         /usr/bin/ts_calibrate
56         wait
57         echo Running ts_test
58         /usr/bin/ts_test
59         wait
60 fi
61
62 # ----
63
64 # Setup swap partition if the user has placed an SD with a swap partition on it.
65
66 #swap_part=$(sfdisk -l /dev/mmcblk? | grep swap | cut -d" " -f1)
67 #if [ x$swap_part != x ] ; then
68 #       use_swap=$(zenity --title="Enable swap?" --text "Swap partition found on SD card. Would you like to use it?\n\nWarning: This SD must remain in the system to use the swap." --list --radiolist --column " " --column "Answer" TRUE "Use swap on $swap_part" FALSE "Do not use swap")
69 #       if [ "$use_swap" = "Use swap on $swap_part" ] ; then
70 #               swapon $swap_part
71 #                       echo "$swap_part none swap sw 0 0" >> /etc/fstab
72 #       fi
73 #fi
74
75 # ----
76
77 # Setup the full name and username.
78
79 while ! name=$(zenity --title="Please enter your full name" --entry --text "Please enter your full name.") || [ "x$name" = "x" ] ; do
80         zenity --title="Error" --error --text="Please try again." --timeout 6
81 done
82
83 username_guess=$(echo "$name" | cut -d" " -f1 | tr A-Z a-z)
84
85 while ! username=$(zenity --title="Enter your username" --entry --text "Please choose a short username.\n\nIt should be all lowercase and contain only letters and numbers." --entry-text "$username_guess") || [ "x$username" = "x" ] ; do
86         zenity --title="Error" --error --text="Please try again." --timeout 6
87 done
88
89 while ! useradd -c "$name,,," -G adm,audio,video,netdev,wheel,plugdev "$username" ; do
90         username=$(zenity --title="Please check username" --entry --text "Please ensure that your username consists of only\nletters and numbers and is not already in use on the system." --entry-text "$username")
91 done
92
93 # ----
94
95 # Setup the users password.
96
97 password=""
98 while [ x$password = x ] ; do
99         password1=$(zenity --title=Password --entry --text="Please choose a new password." --hide-text)
100         password2=$(zenity --title=Confirm --entry --text="Confirm your new password." --hide-text)
101         if [ $password1 != $password2 ] ; then 
102                 zenity --title="Error" --error --text="The passwords do not match.\n\nPlease try again." --timeout 6
103         else 
104                 if [ x$password1 = x ] ; then
105                         zenity --title="Error" --error --text="Password cannot be blank!\n\nPlease try again." --timeout 6
106                 else
107                         password=$password1
108                 fi
109         fi
110 done
111
112 passwd "$username" <<EOF
113 $password
114 $password
115 EOF
116
117 # ----
118
119 # Pick a name for the OpenPandora.
120
121 while ! hostname=$(zenity --title="Name your Pandora" --entry --text "Please choose a name for your OpenPandora.\n\nIt should only contain letters, numbers and dashes." --entry-text "$username-openpandora") || [ "x$hostname" = "x" ]; do 
122         zenity --title="Error" --error --text="Please try again."
123 done
124
125 echo $hostname > /etc/hostname
126 echo "127.0.0.1 localhost.localdomain localhost $hostname" > /etc/hosts
127 hostname -F /etc/hostname
128
129 # Set the correct user for Autologin and enable / disable it.
130
131 if zenity --question --title="Autologin" --text="Do you wish to automatically login at startup?\n\nSecurity warning: This skips the password check on startup" --ok-label="Yes" --cancel-label="No"; then       
132         # echo "PREFERED_USER=$username" > /etc/default/autologin
133         sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
134         sed -i 's/.*auto_login.*/auto_login yes/g' /etc/slim.conf
135 else
136         if zenity --question --title="User" --text="Do you wish to have your username automatically populated in the login screen?\n\nNote: This is ideal if your the only user of the OpenPandora but wish to disable autologin and use a password." --ok-label="Yes" --cancel-label="No"; then 
137                 sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
138                 sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
139         else
140                 sed -i "s/.*default_user.*/default_user/g" /etc/slim.conf
141                 sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
142         fi
143 fi
144
145 # ----
146
147 # Select the default interface and setup SLiM to pass that as a sesion to ~./.xinitrc
148
149 while ! launcher=$(zenity --list --title="Default User Interface" --text="Please choose your default application launcher.\n\nYou can always change this setting later." --column "return" --print-column=1 --hide-column=1 --column "Pick a launcher" "xfce" "Desktop environment (Xfce)" "pmenu" "Gaming-console like launcher (PMenu)") || [ "x$launcher" = "x" ]; do 
150         zenity --title="Error" --error --text="Please select a default launcher." --timeout 6
151 done
152
153 if [ $launcher == "xfce" ]; then 
154         sed -i 's/.*sessions.*/sessions xfce4,pmenu/g' /etc/slim.conf
155         echo Xfce selected as default interface
156 else
157         sed -i 's/.*sessions.*/sessions pmenu,xfce4/g' /etc/slim.conf
158         echo PMenu selected as default interface
159 fi
160
161 # ----
162
163 # Set the timezone and date/time
164
165 while ! timezone=$(zenity --list --title "Select your timezone" --text="Please select your timezone" --column="Select your timezone" --print-column=1 "GMT" "GMT+1" "GMT+2" "GMT+3" "GMT+4" "GMT+5" "GMT+6" "GMT+7" "GMT+8" "GMT+9" "GMT+10" "GMT+11" "GMT+12" "GMT-1" "GMT-2" "GMT-3" "GMT-4" "GMT-5" "GMT-6" "GMT-7" "GMT-8" "GMT-9" "GMT-10" "GMT-11" "GMT-12" "GMT-13" "GMT-14" "UCT" "UTC" "Universal" --width=250 --height=450) || [ "x$timezone" = "x" ] ; do
166         zenity --title="Error" --error --text="Please select a timezone." --timeout=6
167 done
168
169 echo $timezone
170 echo rm /etc/localtime && ln -s /usr/share/zoneinfo/Etc/$timezone /etc/localtime
171
172 #Make sure we clean up any leading zeros in the day (as Zenity freaks out)
173 date_d=`date +%d | sed 's/^0//'`
174 date_m=`date +%m`
175 date_y=`date +%Y`
176
177 while ! date=$(zenity --calendar --text="Please select the current date" --title "Please select the current date" --day=$date_d --month=$date_m --year=$date_y --date-format="%Y%m%d" --width=500) || [ "x$date" = "x" ] ; do
178         zenity --title="Error" --error --text="Please select the date." --timeout 6
179 done
180
181 echo $date
182
183 time_h=`date +%H`
184 time_m=`date +%M`
185
186 while ! time=$(zenity --title="Enter actual time" --entry --text "Please enter the time in 24hour format (HH:MM):" --entry-text "$time_h:$time_m") || [ "x$time" = "x" ] ; do
187         zenity --title="Error" --error --text="Please input the time." --timeout 6
188 done
189
190 while ! date -d $time ; do
191         time=$(zenity --title="Enter actual time" --entry --text "Please enter the time in 24hour format (HH:MM):" --entry-text "$time_h:$time_m")
192 done
193  
194 date +%Y%m%d -s $date
195 date +%H:%M -s $time
196
197 # ----
198
199 # Finsh up and boot the system.
200
201 zenity --info --title="Finished" --text "This concludes the First Boot Wizard.\n\nYour chosen interface will start in a few seconds\n\nThankyou for buying the OpenPandora. Enjoy using the device!" --timeout 6
202
203 # ----
204
205 # Write the control file so this script is not run on next boot 
206 # (hackish I know but I want the flexability to drop a new script in later esp. in the early firmwares).
207
208 touch /etc/pandora/first-boot
209 # Make the control file writeable by all to allow the user to delete to rerun the wizard on next boot.
210 chmod 0666 /etc/pandora/first-boot
211
212 # ----