diff options
Diffstat (limited to 'recipes-extra/startup/rpi-first-run-wizard/first-run-wizard.sh')
| -rw-r--r-- | recipes-extra/startup/rpi-first-run-wizard/first-run-wizard.sh | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/recipes-extra/startup/rpi-first-run-wizard/first-run-wizard.sh b/recipes-extra/startup/rpi-first-run-wizard/first-run-wizard.sh new file mode 100644 index 0000000..4393b68 --- /dev/null +++ b/recipes-extra/startup/rpi-first-run-wizard/first-run-wizard.sh | |||
| @@ -0,0 +1,213 @@ | |||
| 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 | # Quickly 'hacked' for the Raspberry Pi to provide a simple 1st boot wizard. | ||
| 6 | |||
| 7 | # You can start the wizard from the shell using 'xinit ./first-boot-init.sh' | ||
| 8 | |||
| 9 | export LANG=en_GB.UTF-8 | ||
| 10 | export GTK2_RC_FILES=/usr/share/themes/Xfce/gtk-2.0/gtkrc | ||
| 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 | # Default error message (should a user hit cancel, validation fail etc.). | ||
| 17 | ERROR_WINDOW='zenity --title="Error" --error --text="Sorry! Please try again." --timeout 6' | ||
| 18 | |||
| 19 | RESET_ROOT="yes" | ||
| 20 | |||
| 21 | DISPLAY=:0 xset s off | ||
| 22 | |||
| 23 | # Greet the user. | ||
| 24 | |||
| 25 | 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 | ||
| 26 | # ---- | ||
| 27 | |||
| 28 | # Reset ROOT's password to something random | ||
| 29 | |||
| 30 | # (I know the image build sets the password to something pusdo-random) | ||
| 31 | # (ok, urandom is not 100% secure but it's good enough for our needs) | ||
| 32 | |||
| 33 | if [ $RESET_ROOT == "yes" ]; then | ||
| 34 | rootpwd=$(cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?"|fold -w 30|head -n 1) | ||
| 35 | passwd "root" <<EOF | ||
| 36 | $rootpwd | ||
| 37 | $rootpwd | ||
| 38 | EOF | ||
| 39 | rootpwd="" | ||
| 40 | fi | ||
| 41 | |||
| 42 | # ---- | ||
| 43 | |||
| 44 | # Setup swap partition if the user has placed an SD with a swap partition on it. | ||
| 45 | |||
| 46 | swap_part=$(sfdisk -l /dev/mmcblk? | grep swap | cut -d" " -f1) | ||
| 47 | if [ x$swap_part != x ] ; then | ||
| 48 | 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") | ||
| 49 | if [ "$use_swap" = "Use swap on $swap_part" ] ; then | ||
| 50 | swapon $swap_part | ||
| 51 | echo "$swap_part none swap sw 0 0" >> /etc/fstab | ||
| 52 | fi | ||
| 53 | fi | ||
| 54 | |||
| 55 | # ---- | ||
| 56 | |||
| 57 | # Setup the full name and username. | ||
| 58 | |||
| 59 | while ! name=$(zenity --title="Please enter your full name" --entry --text "Please enter your full name.") || [ "x$name" = "x" ] ; do | ||
| 60 | zenity --title="Error" --error --text="Please try again." --timeout 6 | ||
| 61 | done | ||
| 62 | |||
| 63 | username_guess=$(echo "$name" | cut -d" " -f1 | tr A-Z a-z) | ||
| 64 | |||
| 65 | 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 | ||
| 66 | zenity --title="Error" --error --text="Please try again." --timeout 6 | ||
| 67 | done | ||
| 68 | |||
| 69 | while ! useradd -c "$name,,," -G adm,audio,video,netdev,wheel,plugdev,users "$username" ; do | ||
| 70 | 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") | ||
| 71 | done | ||
| 72 | |||
| 73 | # ---- | ||
| 74 | |||
| 75 | # Setup the users password. | ||
| 76 | |||
| 77 | password="" | ||
| 78 | while [ x$password = x ] ; do | ||
| 79 | password1=$(zenity --title=Password --entry --text="Please choose a new password." --hide-text) | ||
| 80 | password2=$(zenity --title=Confirm --entry --text="Confirm your new password." --hide-text) | ||
| 81 | if [ $password1 != $password2 ] ; then | ||
| 82 | zenity --title="Error" --error --text="The passwords do not match.\n\nPlease try again." --timeout 6 | ||
| 83 | else | ||
| 84 | if [ x$password1 = x ] ; then | ||
| 85 | zenity --title="Error" --error --text="Password cannot be blank!\n\nPlease try again." --timeout 6 | ||
| 86 | else | ||
| 87 | password=$password1 | ||
| 88 | fi | ||
| 89 | fi | ||
| 90 | done | ||
| 91 | |||
| 92 | passwd "$username" <<EOF | ||
| 93 | $password | ||
| 94 | $password | ||
| 95 | EOF | ||
| 96 | |||
| 97 | # ---- | ||
| 98 | |||
| 99 | # Pick a name for the OpenPandora. | ||
| 100 | |||
| 101 | 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 | ||
| 102 | zenity --title="Error" --error --text="Please try again." | ||
| 103 | done | ||
| 104 | |||
| 105 | |||
| 106 | echo $hostname > /etc/hostname | ||
| 107 | hostname =$(sed 's/ /_/g' /etc/hostname) | ||
| 108 | echo $hostname > /etc/hostname | ||
| 109 | echo "127.0.0.1 localhost.localdomain localhost $hostname" > /etc/hosts | ||
| 110 | hostname -F /etc/hostname | ||
| 111 | |||
| 112 | # Set the correct user for Autologin and enable / disable it. | ||
| 113 | |||
| 114 | 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 | ||
| 115 | # echo "PREFERED_USER=$username" > /etc/default/autologin | ||
| 116 | sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf | ||
| 117 | sed -i 's/.*auto_login.*/auto_login yes/g' /etc/slim.conf | ||
| 118 | else | ||
| 119 | 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 | ||
| 120 | sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf | ||
| 121 | sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf | ||
| 122 | else | ||
| 123 | sed -i "s/.*default_user.*/default_user/g" /etc/slim.conf | ||
| 124 | sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf | ||
| 125 | fi | ||
| 126 | fi | ||
| 127 | |||
| 128 | # ---- | ||
| 129 | |||
| 130 | # Select the default interface and setup SLiM to pass that as a sesion to ~./.xinitrc | ||
| 131 | |||
| 132 | selection="" | ||
| 133 | while [ x$selection = x ]; do | ||
| 134 | 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 "Please select the Default GUI" ) | ||
| 135 | if [ x$selection = x ]; then | ||
| 136 | zenity --title="Error" --error --text="Please select a GUI." --timeout=6 | ||
| 137 | fi | ||
| 138 | done | ||
| 139 | |||
| 140 | echo $selection | ||
| 141 | |||
| 142 | gui=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $3}') | ||
| 143 | stopcommand=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $4}') | ||
| 144 | |||
| 145 | echo $gui | ||
| 146 | |||
| 147 | if [ $gui ]; then | ||
| 148 | sed -i "s/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=$gui/g" /home/$username/.xinitrc | ||
| 149 | echo $selection selected as default interface | ||
| 150 | zenity --info --title="Selected session" --text "You selected $selection as default setting. You can always change your default GUI later." --timeout 6 | ||
| 151 | else | ||
| 152 | sed -i 's/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=startxfce4/g' /home/$username/.xinitrc | ||
| 153 | fi | ||
| 154 | |||
| 155 | # ---- | ||
| 156 | |||
| 157 | # Set the timezone and date/time | ||
| 158 | |||
| 159 | 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 | ||
| 160 | zenity --title="Error" --error --text="Please select your area." --timeout=6 | ||
| 161 | done | ||
| 162 | |||
| 163 | 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 | ||
| 164 | zenity --title="Error" --error --text="Please select your location." --timeout=6 | ||
| 165 | done | ||
| 166 | |||
| 167 | echo $timezone | ||
| 168 | rm /etc/localtime && ln -s /usr/share/zoneinfo/$area/$timezone /etc/localtime | ||
| 169 | |||
| 170 | # Make sure we clean up any leading zeros in the day (as Zenity freaks out) | ||
| 171 | date_d=`date +%d | sed 's/^0//'` | ||
| 172 | date_m=`date +%m | sed 's/^0//'` | ||
| 173 | date_y=`date +%Y` | ||
| 174 | |||
| 175 | 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 | ||
| 176 | zenity --title="Error" --error --text="Please select the date." --timeout 6 | ||
| 177 | done | ||
| 178 | |||
| 179 | echo $date | ||
| 180 | |||
| 181 | time_h=`date +%H` | ||
| 182 | time_m=`date +%M` | ||
| 183 | |||
| 184 | 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 | ||
| 185 | zenity --title="Error" --error --text="Please input the time." --timeout 6 | ||
| 186 | done | ||
| 187 | |||
| 188 | while ! date -d $time ; do | ||
| 189 | time=$(zenity --title="Enter actual time" --entry --text "Please enter the time in 24hour format (HH:MM):" --entry-text "$time_h:$time_m") | ||
| 190 | done | ||
| 191 | |||
| 192 | date +%Y%m%d -s $date | ||
| 193 | date +%H:%M -s $time | ||
| 194 | |||
| 195 | # ---- | ||
| 196 | |||
| 197 | # Finsh up and boot the system. | ||
| 198 | |||
| 199 | 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 | ||
| 200 | |||
| 201 | # ---- | ||
| 202 | |||
| 203 | # Write the control file so this script is not run on next boot | ||
| 204 | # (hackish I know but I want the flexability to drop a new script in later esp. in the early firmwares). | ||
| 205 | |||
| 206 | touch /etc/rpi/first-boot | ||
| 207 | # Make the control file writeable by all to allow the user to delete to rerun the wizard on next boot. | ||
| 208 | chmod 0666 /etc/rpi/first-boot | ||
| 209 | |||
| 210 | # ---- | ||
| 211 | else | ||
| 212 | poweroff | ||
| 213 | fi | ||
