pandora-first-run-wizard: add user to cdrom group
[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 # Default error message (should a user hit cancel, validation fail etc.).
21 ERROR_WINDOW='zenity --title="Error" --error --text="Sorry! Please try again." --timeout 6'
22
23 RESET_ROOT="yes"
24
25 DISPLAY=:0 xset s off
26
27 # Greet the user.
28
29 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 new 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
30 # ----
31
32 # Reset ROOT's password to something random 
33
34 # (I know the image build sets the password to something pusdo-random)
35 # (ok, urandom is not 100% secure but it's good enough for our needs)
36
37 if [ $RESET_ROOT == "yes" ]; then
38         rootpwd=$(cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?"|fold -w 30|head -n 1)
39 passwd "root" <<EOF
40 $rootpwd
41 $rootpwd
42 EOF
43         rootpwd=""
44 fi
45
46 # ----
47
48 # Ask the user to calibrate the touchscreen.
49
50 #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 
51 #       # Make sure we have a sane environment as this script will be run long before any /etc/profile stuff.
52 #       . /etc/profile.d/tslib.sh
53 #       # Delete the pointercal file (do we want to do that?)
54 #       # rm /etc/pointercal
55 #       # Spawn the ts_* tools as subprocesses that will return to the script.
56 #       echo Running ts_calibrate       
57 #       /usr/bin/ts_calibrate
58 #       wait
59 #       echo Running ts_test
60 #       /usr/bin/ts_test
61 #       wait
62 #fi
63
64 # ----
65
66 # Setup swap partition if the user has placed an SD with a swap partition on it.
67
68 #swap_part=$(sfdisk -l /dev/mmcblk? | grep swap | cut -d" " -f1)
69 #if [ x$swap_part != x ] ; then
70 #       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")
71 #       if [ "$use_swap" = "Use swap on $swap_part" ] ; then
72 #               swapon $swap_part
73 #                       echo "$swap_part none swap sw 0 0" >> /etc/fstab
74 #       fi
75 #fi
76
77 # ----
78
79 # Setup the full name and username.
80
81 while ! name=$(zenity --title="Please enter your full name" --entry --text "Please enter your full name.") || [ "x$name" = "x" ] ; do
82         zenity --title="Error" --error --text="Please try again." --timeout 6
83 done
84
85 username_guess=$(echo "$name" | cut -d" " -f1 | tr A-Z a-z)
86
87 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
88         zenity --title="Error" --error --text="Please try again." --timeout 6
89 done
90
91 while ! useradd -c "$name,,," -G adm,audio,cdrom,netdev,plugdev,users,video,wheel "$username" ; do
92         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")
93 done
94
95 # ----
96
97 # Setup the users password.
98
99 password=""
100 while [ x$password = x ] ; do
101         password1=$(zenity --title=Password --entry --text="Please choose a new password." --hide-text)
102         password2=$(zenity --title=Confirm --entry --text="Confirm your new password." --hide-text)
103         if [ $password1 != $password2 ] ; then 
104                 zenity --title="Error" --error --text="The passwords do not match.\n\nPlease try again." --timeout 6
105         else 
106                 if [ x$password1 = x ] ; then
107                         zenity --title="Error" --error --text="Password cannot be blank!\n\nPlease try again." --timeout 6
108                 else
109                         password=$password1
110                 fi
111         fi
112 done
113
114 passwd "$username" <<EOF
115 $password
116 $password
117 EOF
118
119 # ----
120
121 # Pick a name for the OpenPandora.
122
123 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 
124         zenity --title="Error" --error --text="Please try again."
125 done
126
127
128 echo $hostname > /etc/hostname
129 hostname =$(sed 's/ /_/g' /etc/hostname)
130 echo $hostname > /etc/hostname
131 echo "127.0.0.1 localhost.localdomain localhost $hostname" > /etc/hosts
132 hostname -F /etc/hostname
133
134 # Set the correct user for Autologin and enable / disable it.
135
136 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         
137         # echo "PREFERED_USER=$username" > /etc/default/autologin
138         sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
139         sed -i 's/.*auto_login.*/auto_login yes/g' /etc/slim.conf
140 else
141         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 
142                 sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
143                 sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
144         else
145                 sed -i "s/.*default_user.*/default_user/g" /etc/slim.conf
146                 sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
147         fi
148 fi
149
150 # ----
151
152 # Select the default interface and setup SLiM to pass that as a sesion to ~./.xinitrc
153
154 selection=""
155 while [ x$selection = x ]; do
156 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." )
157 if [ x$selection = x ]; then
158   zenity --title="Error" --error --text="Please select a GUI." --timeout=6
159 fi
160 done
161
162 echo $selection
163
164 gui=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $3}')
165 stopcommand=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $4}')
166
167 echo $gui
168
169 if [ $gui ]; then 
170   sed -i "s/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=$gui/g" /home/$username/.xinitrc
171   echo $selection selected as default interface
172   zenity --info --title="Selected session" --text "You selected $selection as default setting." --timeout 6
173 else
174   sed -i 's/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=startxfce4/g' /home/$username/.xinitrc
175 fi
176
177 # ----
178
179 # Set the timezone and date/time
180
181 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
182         zenity --title="Error" --error --text="Please select your area." --timeout=6
183 done
184
185 while ! 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") || [ "x$timezone" = "x" ] ; do
186         zenity --title="Error" --error --text="Please select your location." --timeout=6
187 done
188
189 echo $timezone
190 rm /etc/localtime && ln -s /usr/share/zoneinfo/$area/$timezone /etc/localtime
191
192 #Make sure we clean up any leading zeros in the day (as Zenity freaks out)
193 date_d=`date +%d | sed 's/^0//'`
194 date_m=`date +%m | sed 's/^0//'`
195 date_y=`date +%Y`
196
197 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
198         zenity --title="Error" --error --text="Please select the date." --timeout 6
199 done
200
201 echo $date
202
203 time_h=`date +%H`
204 time_m=`date +%M`
205
206 while ! time=$(zenity --title="Enter current time" --entry --text "Please enter the time in 24hour format (HH:MM).\n\nThe screen might blank out after you changed the time.\nDon't panic. Simply press a button on the keyboard.\n" --entry-text "$time_h:$time_m") || [ "x$time" = "x" ] ; do
207         zenity --title="Error" --error --text="Please input the time." --timeout 6
208 done
209
210 while ! date -d $time ; do
211         time=$(zenity --title="Enter current time" --entry --text "Please enter the time in 24hour format (HH:MM).\n\nThe screen might blank out after you changed the time.\nDon't panic. Simply press a button on the keyboard.\n" --entry-text "$time_h:$time_m")
212 done
213  
214 date +%Y%m%d -s $date
215 date +%H:%M -s $time
216
217 # ----
218
219 # 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.
220 update-rc.d -f samba remove
221 update-rc.d -f xinetd remove
222 update-rc.d -f avahi-daemon remove
223 update-rc.d -f apmd remove
224 update-rc.d -f usb-gadget remove
225 update-rc.d -f banner remove
226 update-rc.d -f portmap remove
227 update-rc.d -f mountnfs remove
228 update-rc.d -f blueprobe remove
229 update-rc.d -f dropbear remove
230 update-rc.d -f wl1251-init remove
231
232 # get rid of some dirs in /media that OE creates but are unlikely to be used
233 rmdir /media/card /media/cf /media/mmc1 /media/net /media/realroot /media/union 2> /dev/null
234
235 # Write the control file so this script is not run on next boot 
236 # (hackish I know but I want the flexability to drop a new script in later esp. in the early firmwares).
237
238 touch /etc/pandora/first-boot
239 # Make the control file writeable by all to allow the user to delete to rerun the wizard on next boot.
240 chmod 0666 /etc/pandora/first-boot
241
242
243 # Let the user run optional config stuff.
244
245 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" "CPU-Speed and Overclocking-Settings" "startup" "Startup-Settings" "lcd" "LCD-Settings" --ok-label="Change selected Setting" --cancel-label="Continue to Boot"); do
246
247 case $mainsel in
248   "speed")
249   /usr/pandora/scripts/op_cpusettings.sh
250   ;;
251
252    "startup")
253   echo $username > /tmp/currentuser
254   /usr/pandora/scripts/op_startupmanager.sh
255   ;;
256
257    "lcd")
258   /usr/pandora/scripts/op_lcdsettings.sh
259   ;;
260
261 esac
262 done
263
264 # ----
265
266
267 # ----
268 else
269 poweroff
270 fi