pandora-first-run-wizard: Added reboot instead of set up now.
[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 # Greet the user.
26
27 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 for use.\n\nDo you want to setup your unit now or shutdown the unit and do it later?" --ok-label="Start now" --cancel-label="Shutdown" ; then
28
29 # ----
30
31 # Reset ROOT's password to something random 
32
33 # (I know the image build sets the password to something pusdo-random)
34 # (ok, urandom is not 100% secure but it's good enough for our needs)
35
36 if [ $RESET_ROOT == "yes" ]; then
37         rootpwd=$(cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?"|fold -w 30|head -n 1)
38 passwd "root" <<EOF
39 $rootpwd
40 $rootpwd
41 EOF
42         rootpwd=""
43 fi
44
45 # ----
46
47 # Ask the user to calibrate the touchscreen.
48
49 #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 
50 #       # Make sure we have a sane environment as this script will be run long before any /etc/profile stuff.
51 #       . /etc/profile.d/tslib.sh
52 #       # Delete the pointercal file (do we want to do that?)
53 #       # rm /etc/pointercal
54 #       # Spawn the ts_* tools as subprocesses that will return to the script.
55 #       echo Running ts_calibrate       
56 #       /usr/bin/ts_calibrate
57 #       wait
58 #       echo Running ts_test
59 #       /usr/bin/ts_test
60 #       wait
61 #fi
62
63 # ----
64
65 # Setup swap partition if the user has placed an SD with a swap partition on it.
66
67 #swap_part=$(sfdisk -l /dev/mmcblk? | grep swap | cut -d" " -f1)
68 #if [ x$swap_part != x ] ; then
69 #       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")
70 #       if [ "$use_swap" = "Use swap on $swap_part" ] ; then
71 #               swapon $swap_part
72 #                       echo "$swap_part none swap sw 0 0" >> /etc/fstab
73 #       fi
74 #fi
75
76 # ----
77
78 # Setup the full name and username.
79
80 while ! name=$(zenity --title="Please enter your full name" --entry --text "Please enter your full name.") || [ "x$name" = "x" ] ; do
81         zenity --title="Error" --error --text="Please try again." --timeout 6
82 done
83
84 username_guess=$(echo "$name" | cut -d" " -f1 | tr A-Z a-z)
85
86 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
87         zenity --title="Error" --error --text="Please try again." --timeout 6
88 done
89
90 while ! useradd -c "$name,,," -G adm,audio,video,netdev,wheel,plugdev,users "$username" ; do
91         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")
92 done
93
94 # ----
95
96 # Setup the users password.
97
98 password=""
99 while [ x$password = x ] ; do
100         password1=$(zenity --title=Password --entry --text="Please choose a new password." --hide-text)
101         password2=$(zenity --title=Confirm --entry --text="Confirm your new password." --hide-text)
102         if [ $password1 != $password2 ] ; then 
103                 zenity --title="Error" --error --text="The passwords do not match.\n\nPlease try again." --timeout 6
104         else 
105                 if [ x$password1 = x ] ; then
106                         zenity --title="Error" --error --text="Password cannot be blank!\n\nPlease try again." --timeout 6
107                 else
108                         password=$password1
109                 fi
110         fi
111 done
112
113 passwd "$username" <<EOF
114 $password
115 $password
116 EOF
117
118 # ----
119
120 # Pick a name for the OpenPandora.
121
122 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 
123         zenity --title="Error" --error --text="Please try again."
124 done
125
126 echo $hostname > /etc/hostname
127 echo "127.0.0.1 localhost.localdomain localhost $hostname" > /etc/hosts
128 hostname -F /etc/hostname
129
130 # Set the correct user for Autologin and enable / disable it.
131
132 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       
133         # echo "PREFERED_USER=$username" > /etc/default/autologin
134         sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
135         sed -i 's/.*auto_login.*/auto_login yes/g' /etc/slim.conf
136 else
137         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 
138                 sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
139                 sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
140         else
141                 sed -i "s/.*default_user.*/default_user/g" /etc/slim.conf
142                 sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
143         fi
144 fi
145
146 # ----
147
148 # Select the default interface and setup SLiM to pass that as a sesion to ~./.xinitrc
149
150 selection=$(cat /etc/pandora/conf/gui.conf | awk -F\; '{print $1 "\n" $2 }' | zenity --width=500 --height=300 --title="Select the Default GUI" --list --column "name" --column "description" --text "select defaultgui" )
151 echo $selection
152
153 gui=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $3}')
154 stopcommand=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $4}')
155
156 echo $gui
157
158 if [ $gui ]; then 
159   sed -i "s/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=$gui/g" /home/$username/.xinitrc
160   echo $selection selected as default interface
161   zenity --info --title="Selected session" --text "You selected $selection as default setting. You can always change your default GUI later." --timeout 6
162 else
163   sed -i 's/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=startxfce4/g' /home/$username/.xinitrc
164 fi
165
166 # ----
167
168 # Set the timezone and date/time
169
170 while ! timezone=$(zenity --list --title "Select your timezone" --text="Please select your timezone" --column="Select your timezone" --print-column=1 "GMT (London, Lisbon, Portugal, Casablanca, Morocco)" "GMT+1 (Paris, Berlin, Amsterdam, Bern, Stockholm)" "GMT+2 (Athens, Helsinki, Istanbul)" "GMT+3 (Kuwait, Nairobi, Riyadh, Moscow)" "GMT+4 (Abu Dhabi, Iraq, Muscat, Kabul)" "GMT+5 (Calcutta, Colombo, Islamabad, Madras, New Delhi)" "GMT+6 (Almaty, Dhakar, Kathmandu)" "GMT+7 (Bangkok, Hanoi, Jakarta)" "GMT+8 (Beijing, Hong Kong, Kuala Lumpar, Singapore, Taipei)" "GMT+9 (Osaka, Seoul, Sapporo, Tokyo, Yakutsk)" "GMT+10 (Brisbane, Melbourne, Sydney, Vladivostok)" "GMT+11 (Magadan, New Caledonia, Solomon Is)" "GMT+12 (Auckland, Fiji, Kamchatka, Marshall Is., Wellington, Suva)" "GMT-1 (Azores, Cape Verde Is.)" "GMT-2 (Mid-Atlantic)" "GMT-3 (Brasilia, Buenos Aires, Georgetown)" "GMT-4 (Atlantic Time, Caracas)" "GMT-5 (Bogota, Lima, New York)" "GMT-6 (Mexico City, Saskatchewan, Chicago, Guatamala)" "GMT-7 (Denver, Edmonton, Mountain Time, Phoenix, Salt Lake City)" "GMT-8 (Anchorage, Los Angeles, San Francisco, Seattle)" "GMT-9 (Alaska)" "GMT-10 (Hawaii, Honolulu)" "GMT-11 (Midway Island, Samoa)" "GMT-12 (Eniwetok, Kwaialein)" "UTC" "Universal" --width=500 --height=450) || [ "x$timezone" = "x" ] ; do
171         zenity --title="Error" --error --text="Please select a timezone." --timeout=6
172 done
173 timezone=`echo $timezone | sed  's/(.*)//g'`
174 echo $timezone
175 echo rm /etc/localtime && ln -s /usr/share/zoneinfo/Etc/$timezone /etc/localtime
176
177 #Make sure we clean up any leading zeros in the day (as Zenity freaks out)
178 date_d=`date +%d | sed 's/^0//'`
179 date_m=`date +%m`
180 date_y=`date +%Y`
181
182 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
183         zenity --title="Error" --error --text="Please select the date." --timeout 6
184 done
185
186 echo $date
187
188 time_h=`date +%H`
189 time_m=`date +%M`
190
191 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
192         zenity --title="Error" --error --text="Please input the time." --timeout 6
193 done
194
195 while ! date -d $time ; do
196         time=$(zenity --title="Enter actual time" --entry --text "Please enter the time in 24hour format (HH:MM):" --entry-text "$time_h:$time_m")
197 done
198  
199 date +%Y%m%d -s $date
200 date +%H:%M -s $time
201
202 # ----
203
204 # Finsh up and boot the system.
205
206 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
207
208 # ----
209
210 # Write the control file so this script is not run on next boot 
211 # (hackish I know but I want the flexability to drop a new script in later esp. in the early firmwares).
212
213 touch /etc/pandora/first-boot
214 # Make the control file writeable by all to allow the user to delete to rerun the wizard on next boot.
215 chmod 0666 /etc/pandora/first-boot
216
217 # ----
218 else
219 poweroff
220 fi