first-run-wizard: add to dialout grp, allow user to fix wrong area
[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 xmodmap /etc/skel/.pndXmodmap
11
12 # Ensure there is a wheel group for sudoers to be put into.
13 # TODO: Do this somewhere better.
14 groupadd wheel
15
16 # We load up a background image here.
17 export WALLPAPER='/usr/share/xfce4/backdrops/op-firstrun.png'
18 hsetroot -center $WALLPAPER
19
20 # Find out what unit the user has.
21 pnd_version=$(dmesg | grep OMAP3 | grep ES | awk '{print $3}')
22 es_version=$(dmesg | grep OMAP3 | grep ES | awk '{print $4}')
23 if [ "$pnd_version" == "OMAP3630" ]; then
24     pnd_version="1GHz"
25 fi
26   if [ "$pnd_version" == "OMAP3430/3530" ]; then
27     pnd_version="Rebirth"
28   if [ "$es_version" == "ES2.1" ]; then
29     pnd_version="Classic"
30   fi
31 fi
32
33 # Enable TV Out
34 /usr/pandora/scripts/op_tvout.sh
35
36 # Default error message (should a user hit cancel, validation fail etc.).
37 ERROR_WINDOW='zenity --title="Error" --error --text="Sorry! Please try again." --timeout 6'
38
39 RESET_ROOT="yes"
40
41 xset s off
42 xset -dpms
43
44 #Stop WiFi
45 rmmod board_omap3pandora_wifi wl1251_sdio wl1251
46
47 # Greet the user.
48
49 if zenity --question --title="Pandoras Box has been opened." --text="Welcome!\n\nPandora's Box has been opened.\n\nThis wizard will help you setting up your $pnd_version OpenPandora handheld before the first use.\n\nYou will be asked a few simple questions to personalise and configure your device.\n\nDo you want to set up your unit now or shut the unit down and do it later?" --ok-label="Start now" --cancel-label="Shutdown" ; then
50 # ----
51
52 # Calibrate touchscreen.
53
54 if zenity --question --title="Calibrate Touchscreen" --text="It is recommended to calibrate the touchscreen to make sure it accurately works.\n\nIf you do so, you will see a moving crosshair.\nUse the stylus to press the crosshair as accurate as possible.\n\nYou can always (re-)calibrate it from the Settings-Menu later in the OS as well." --ok-label="Calibrate Touchscreen" --cancel-label="Don't calibrate it"; then
55   . /etc/profile
56   TSLIB_CONSOLEDEVICE=none op_runfbapp ts_calibrate
57   /usr/pandora/scripts/op_touchinit.sh
58 while ! zenity --question --title="Check Calibration" --text="Your new calibration setting has been applied.\n\nPlease check if the touchscreen is now working properly.\nIf not, you might want to try a recalibration.\n\n(Hint: use the nubs to press the button if the touchscreen is way off)" --ok-label="The touchscreen is fine" --cancel-label="Recalibrate"; do
59       TSLIB_CONSOLEDEVICE=none op_runfbapp ts_calibrate
60   /usr/pandora/scripts/op_touchinit.sh  
61 done
62 fi
63
64 # Reset ROOT's password to something random 
65
66 # (I know the image build sets the password to something pusdo-random)
67 # (ok, urandom is not 100% secure but it's good enough for our needs)
68
69 if [ $RESET_ROOT == "yes" ]; then
70         rootpwd=$(cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?"|fold -w 30|head -n 1)
71 passwd "root" <<EOF
72 $rootpwd
73 $rootpwd
74 EOF
75         rootpwd=""
76 fi
77
78 # ----
79
80 # Setup the full name and username.
81
82 while ! name=$(zenity --title="Please enter your full name" --entry --text "Please enter your full name.") || [ "x$name" = "x" ] ; do
83         zenity --title="Error" --error --text="Please try again." --timeout 6
84 done
85
86 username_guess=$(echo "$name" | cut -d" " -f1 | tr A-Z a-z)
87
88 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
89         zenity --title="Error" --error --text="Please try again." --timeout 6
90 done
91
92 while ! useradd -c "$name,,," -G adm,audio,cdrom,netdev,plugdev,users,video,wheel,dialout "$username" ; do
93         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")
94 done
95
96 # ----
97
98 # Setup the users password.
99
100 password=""
101 while [ x$password = x ] ; do
102         password1=$(zenity --title=Password --entry --text="Please choose a new password." --hide-text)
103         password2=$(zenity --title=Confirm --entry --text="Confirm your new password." --hide-text)
104         if [ $password1 != $password2 ] ; then 
105                 zenity --title="Error" --error --text="The passwords do not match.\n\nPlease try again." --timeout 6
106         else 
107                 if [ x$password1 = x ] ; then
108                         zenity --title="Error" --error --text="Password cannot be blank!\n\nPlease try again." --timeout 6
109                 else
110                         password=$password1
111                 fi
112         fi
113 done
114
115 passwd "$username" <<EOF
116 $password
117 $password
118 EOF
119
120 # ----
121
122 # Pick a name for the OpenPandora.
123
124 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, no spaces." --entry-text "$username-openpandora") || [ "x$hostname" = "x" ]; do 
125         zenity --title="Error" --error --text="Please try again."
126 done
127
128
129 echo $hostname > /etc/hostname
130 hostname =$(sed 's/ /_/g' /etc/hostname)
131 echo $hostname > /etc/hostname
132 echo "127.0.0.1 localhost.localdomain localhost $hostname" > /etc/hosts
133 hostname -F /etc/hostname
134
135 # Set the correct user for Autologin and enable / disable it.
136
137 if zenity --question --title="Autologin" --text="If you like, you can setup your Pandora to autologin into the system at startup.\nWhile this is more convenient for most users, it features a potential security issue, as no password will be needed to access your desktop and personal files.\n\nDo you wish to automatically login at startup?" --ok-label="Yes" --cancel-label="No"; then         
138         # echo "PREFERED_USER=$username" > /etc/default/autologin
139         sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
140         sed -i 's/.*auto_login.*/auto_login yes/g' /etc/slim.conf
141 else
142         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 you're the only user of the OpenPandora but wish to disable autologin and use a password." --ok-label="Yes" --cancel-label="No"; then 
143                 sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
144                 sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
145         else
146                 sed -i "s/.*default_user.*/default_user/g" /etc/slim.conf
147                 sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
148         fi
149 fi
150
151 # ----
152
153 # Select the default interface and setup SLiM to pass that as a sesion to ~./.xinitrc
154
155 selection=""
156 while [ x$selection = x ]; do
157 selection=$(cat /etc/pandora/conf/gui.conf | awk -F\; '{print $1 "\n" $2 }' | zenity --width=500 --height=310 --title="Select the Default GUI" --list --column "Name" --column "Description" --text "You can now select your preferred GUI - the GUI that will be loaded automatically on startup of the unit.\n\nYou can either select XFCE4, which is a full desktop environment (similar to a normal PC).\nOr you could select MiniMenu, which is a minimal UI similar to gaming devices.\n\nIf you select the last choice (GUISwitch), you will be prompted to choose a GUI each time you boot your Pandora.\n\nThis setting can always be changed later by running the Startup-Settings." )
158 if [ x$selection = x ]; then
159   zenity --title="Error" --error --text="Please select a GUI." --timeout=6
160 fi
161 done
162
163 echo $selection
164
165 gui=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $3}')
166 stopcommand=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $4}')
167
168 echo $gui
169
170 if [ $gui ]; then 
171   sed -i "s/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=$gui/g" /home/$username/.xinitrc
172   echo $selection selected as default interface
173   zenity --info --title="Selected session" --text "You selected $selection as default setting." --timeout 6
174 else
175   sed -i 's/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=startxfce4/g' /home/$username/.xinitrc
176 fi
177
178 # ----
179
180 # Set the timezone and date/time
181
182 while [ "x$timezone" = "x" ]; do
183
184   while ! area=$(zenity --list --title "Select your time zone" --text="Please select your area" --column="Select your area" --print-column=1 "Africa" "America" "Asia" "Australia" "Europe" "Pacific" --width=500 --height=260) || [ "x$area" = "x" ] ; do
185         zenity --title="Error" --error --text="Please select your area." --timeout=6
186   done
187
188   timezone=$(ls -1 /usr/share/zoneinfo/$area | zenity ---width=500 --height=200 --title="Select your closest location" --list --column "Closest Location" --text "Please select the location closest to you")
189
190 done
191
192 echo $timezone
193 rm /etc/localtime && ln -s /usr/share/zoneinfo/$area/$timezone /etc/localtime
194 echo "$area/$timezone" > /etc/timezone
195
196 #Make sure we clean up any leading zeros in the day (as Zenity freaks out)
197 date_d=`date +%d | sed 's/^0//'`
198 date_m=`date +%m | sed 's/^0//'`
199 date_y=`date +%Y`
200
201 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
202         zenity --title="Error" --error --text="Please select the date." --timeout 6
203 done
204
205 echo $date
206
207 time_h=`date +%H`
208 time_m=`date +%M`
209
210 while ! time=$(zenity --title="Enter current time" --entry --text "Please enter the time in 24hour format (HH:MM).\n" --entry-text "$time_h:$time_m") || [ "x$time" = "x" ] ; do
211         zenity --title="Error" --error --text="Please input the time." --timeout 6
212 done
213
214 while ! date -d $time ; do
215         time=$(zenity --title="Enter current time" --entry --text "Please enter the time in 24hour format (HH:MM).\n" --entry-text "$time_h:$time_m")
216 done
217  
218 date +%Y%m%d -s $date
219 date +%H:%M -s $time
220 hwclock -u -w
221
222
223 # Let the user choose his desired clockspeed.
224
225 if [ "$pnd_version" == "1GHz" ]; then 
226       cpusel=$(zenity --title="Optional settings" --width="400" --height="300" --list --column "id" --column "Please select" --hide-column=1 --text="The CPU of the Pandora supports different speed settings.\nHigher speeds might make some units unstable and decrease the lifetime of your CPU.\n\nBelow are some quick profiles which will help you to configure your system the way you like it.\n" "1200" "Clockspeed: 1,2Ghz, OPP4 (probably unstable)" "1100" "Clockspeed: 1,1Ghz, OPP4 (should be stable)" "1000" "Clockspeed: 1GHz, OPP4 (Default Speed)" --ok-label="Select CPU Profile" )
227     else
228       cpusel=$(zenity --title="Optional settings" --width="400" --height="300" --list --column "id" --column "Please select" --hide-column=1 --text="The CPU of the Pandora supports different speed settings.\nHigher speeds might make some units unstable and decrease the lifetime of your CPU.\n\nBelow are some quick profiles which will help you to configure your system the way you like it.\n" "900" "Clockspeed: 900Mhz, OPP5 (probably unstable)" "800" "Clockspeed: 800Mhz, OPP5 (should be stable)" "600" "Clockspeed: 600MHz, OPP3 (Default Speed)" --ok-label="Select CPU Profile" )
229     fi
230     
231     case $cpusel in
232         "1200")
233         echo 4 > /proc/pandora/cpu_opp_max
234         sed -i "s/.*maxopp.*/maxopp:4/g" /etc/pandora/conf/cpu.conf
235         sed -i "s/.*max:.*/max:1300/g" /etc/pandora/conf/cpu.conf
236         sed -i "s/.*default.*/default:1200/g" /etc/pandora/conf/cpu.conf
237         sed -i "s/.*safe.*/safe:1200/g" /etc/pandora/conf/cpu.conf
238         sync
239         /usr/pandora/scripts/op_cpuspeed.sh -n 1200
240         zenity --info --title="CPU Speed set" --text "The maximum CPU Speed has been set to 1,2GHz." --timeout 6
241         ;;
242     
243         "1100")
244         echo 4 > /proc/pandora/cpu_opp_max
245         sed -i "s/.*maxopp.*/maxopp:4/g" /etc/pandora/conf/cpu.conf
246         sed -i "s/.*max:.*/max:1200/g" /etc/pandora/conf/cpu.conf
247         sed -i "s/.*default.*/default:1100/g" /etc/pandora/conf/cpu.conf
248         sed -i "s/.*safe.*/safe:1100/g" /etc/pandora/conf/cpu.conf
249         sync
250         /usr/pandora/scripts/op_cpuspeed.sh -n 1100
251         zenity --info --title="CPU Speed set" --text "The maximum CPU Speed has been set to 1,1GHz." --timeout 6
252         ;;
253
254         "1000")
255         echo 4 > /proc/pandora/cpu_opp_max
256         sed -i "s/.*maxopp.*/maxopp:4/g" /etc/pandora/conf/cpu.conf
257         sed -i "s/.*max:.*/max:1100/g" /etc/pandora/conf/cpu.conf
258         sed -i "s/.*default.*/default:1000/g" /etc/pandora/conf/cpu.conf
259         sed -i "s/.*safe.*/safe:1000/g" /etc/pandora/conf/cpu.conf
260         sync
261         /usr/pandora/scripts/op_cpuspeed.sh -n 1000
262         zenity --info --title="CPU Speed set" --text "The maximum CPU Speed has been set to 1GHz." --timeout 6
263         ;;      
264
265         "900")
266         echo 5 > /proc/pandora/cpu_opp_max
267         sed -i "s/.*maxopp.*/maxopp:5/g" /etc/pandora/conf/cpu.conf
268         sed -i "s/.*max:.*/max:950/g" /etc/pandora/conf/cpu.conf
269         sed -i "s/.*default.*/default:900/g" /etc/pandora/conf/cpu.conf
270         sed -i "s/.*safe.*/safe:900/g" /etc/pandora/conf/cpu.conf
271         sync
272         /usr/pandora/scripts/op_cpuspeed.sh -n 900
273         zenity --info --title="CPU Speed set" --text "The maximum CPU Speed has been set to 900MHz." --timeout 6
274         ;;
275         
276         "800")
277         echo 5 > /proc/pandora/cpu_opp_max
278         sed -i "s/.*maxopp.*/maxopp:5/g" /etc/pandora/conf/cpu.conf
279         sed -i "s/.*max:.*/max:900/g" /etc/pandora/conf/cpu.conf
280         sed -i "s/.*default.*/default:800/g" /etc/pandora/conf/cpu.conf
281         sed -i "s/.*safe.*/safe:800/g" /etc/pandora/conf/cpu.conf
282         sync
283         /usr/pandora/scripts/op_cpuspeed.sh -n 800
284         zenity --info --title="CPU Speed set" --text "The maximum CPU Speed has been set to 800MHz." --timeout 6
285         ;;
286
287
288         "600")
289         echo 3 > /proc/pandora/cpu_opp_max
290         sed -i "s/.*maxopp.*/maxopp:3/g" /etc/pandora/conf/cpu.conf
291         sed -i "s/.*max:.*/max:700/g" /etc/pandora/conf/cpu.conf
292         sed -i "s/.*default.*/default:600/g" /etc/pandora/conf/cpu.conf
293         sed -i "s/.*safe.*/safe:600/g" /etc/pandora/conf/cpu.conf
294         sync
295         /usr/pandora/scripts/op_cpuspeed.sh -n 600
296         zenity --info --title="CPU Speed set" --text "The maxmimum CPU Speed has been set to 600Mhz." --timeout 6
297         ;;
298
299 esac
300
301 #Enable / Disable TV Out on Startup
302
303 if zenity --question --title="TV Out on startup" --text="Do you want to enable the TV Output on startup?\n(Note: This needs a bit more power)" --ok-label="Enable TV Out" --cancel-label="Disable TV Out"; then 
304           touch /etc/pandora/conf/tvout.state
305           zenity --info --title="TV Out" --text "TV Out will be switched on with the last saved settings on bootup." --timeout 6
306         else
307         /usr/pandora/scripts/op_tvout.sh -d
308           if [ -f /etc/pandora/conf/tvout.state ]; then
309                 rm /etc/pandora/conf/tvout.state
310           fi
311           zenity --info --title="TV Out" --text "TV Out will not be switched on on bootup." --timeout 6
312 fi     
313
314 # ----
315
316 # NOTE: This is just a temporary fix! These daemons should be removed from startup in the OE recipes. Until the time is found, we'll do it from here.
317 update-rc.d -f samba remove
318 update-rc.d -f xinetd remove
319 update-rc.d -f avahi-daemon remove
320 update-rc.d -f apmd remove
321 update-rc.d -f banner remove
322 update-rc.d -f portmap remove
323 update-rc.d -f mountnfs remove
324 update-rc.d -f blueprobe remove
325 update-rc.d -f dropbear remove
326 update-rc.d -f wl1251-init remove
327 # leave this one alone, needed for OTG host mode, powersaving should be ok on 3.2.39 at least
328 #update-rc.d -f usb-gadget remove
329
330 # prevent wifi from being autoloaded on later kernels, let wl1251-init script do it
331 if ! grep -q 'blacklist wl1251_sdio' /etc/modprobe.conf 2> /dev/null; then
332   echo 'blacklist wl1251_sdio' >> /etc/modprobe.conf
333 fi
334 # we don't ship firmware for rtl8192cu, and it was reported not to work
335 # with the right firmware anyway (not verified though)
336 # vendor 8192cu is compiled instead for now
337 if ! grep -q 'blacklist rtl8192cu' /etc/modprobe.conf 2> /dev/null; then
338   echo 'blacklist rtl8192cu' >> /etc/modprobe.conf
339 fi
340
341 # add Midi Module and zram
342 echo snd-seq>>/etc/modules
343 echo zram>>/etc/modules
344
345 # get rid of some dirs in /media that OE creates but are unlikely to be used
346 rmdir /media/card /media/cf /media/mmc1 /media/net /media/realroot /media/union 2> /dev/null
347
348 # Write the control file so this script is not run on next boot 
349 # (hackish I know but I want the flexability to drop a new script in later esp. in the early firmwares).
350
351 touch /etc/pandora/first-boot
352 # Make the control file writeable by all to allow the user to delete to rerun the wizard on next boot.
353 chmod 0666 /etc/pandora/first-boot
354
355
356
357
358
359 # Let the user run optional config stuff.
360
361 while mainsel=$(zenity --title="Optional settings" --width="400" --height="300" --list --column "id" --column "Please select" --hide-column=1 --text="This concludes the mandatory part of the First Boot Wizard.\n\nYou can now either continue to boot the system or change some more settings.\n\n\nThank you for buying the OpenPandora. Enjoy using the device." "speed" "Advanced CPU-Speed and Overclocking-Settings" "startup" "Advanced Startup-Settings" "video" "Video Settings" --ok-label="Change selected Setting" --cancel-label="Finish Setup"); do
362
363 case $mainsel in
364   "speed")
365   /usr/pandora/scripts/op_cpusettings.sh
366   ;;
367
368    "startup")
369   echo $username > /tmp/currentuser
370   /usr/pandora/scripts/op_startupmanager.sh
371   ;;
372
373    "video")
374   /usr/pandora/scripts/op_lcdsettings.sh
375   ;;
376
377 esac
378 done
379 # ----
380
381 rm /tmp/nocleanwarn
382 # ----
383 else
384 poweroff
385 fi