omap3-pandora-kernel2: otg patch test release
[openpandora.oe.git] / recipes / pandora-system / pandora-first-run-wizard / first-run-wizard.sh
index e7e6fd2..3d82718 100755 (executable)
@@ -22,10 +22,15 @@ ERROR_WINDOW='zenity --title="Error" --error --text="Sorry! Please try again." -
 
 RESET_ROOT="yes"
 
-# Greet the user.
+xset s off
+xset -dpms
+
+#Stop WiFi
+rmmod board_omap3pandora_wifi wl1251_sdio wl1251
 
-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
+# Greet the user.
 
+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
 # ----
 
 # Reset ROOT's password to something random 
@@ -87,7 +92,7 @@ while ! username=$(zenity --title="Enter your username" --entry --text "Please c
        zenity --title="Error" --error --text="Please try again." --timeout 6
 done
 
-while ! useradd -c "$name,,," -G adm,audio,video,netdev,wheel,plugdev,users "$username" ; do
+while ! useradd -c "$name,,," -G adm,audio,cdrom,netdev,plugdev,users,video,wheel "$username" ; do
        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")
 done
 
@@ -119,22 +124,25 @@ EOF
 
 # Pick a name for the OpenPandora.
 
-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 
+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 
        zenity --title="Error" --error --text="Please try again."
 done
 
+
+echo $hostname > /etc/hostname
+hostname =$(sed 's/ /_/g' /etc/hostname)
 echo $hostname > /etc/hostname
 echo "127.0.0.1 localhost.localdomain localhost $hostname" > /etc/hosts
 hostname -F /etc/hostname
 
 # Set the correct user for Autologin and enable / disable it.
 
-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              
+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        
        # echo "PREFERED_USER=$username" > /etc/default/autologin
        sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
        sed -i 's/.*auto_login.*/auto_login yes/g' /etc/slim.conf
 else
-       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 
+       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 
                sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
                sed -i 's/.*auto_login.*/auto_login no/g' /etc/slim.conf
        else
@@ -147,7 +155,14 @@ fi
 
 # Select the default interface and setup SLiM to pass that as a sesion to ~./.xinitrc
 
-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" )
+selection=""
+while [ x$selection = x ]; do
+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." )
+if [ x$selection = x ]; then
+  zenity --title="Error" --error --text="Please select a GUI." --timeout=6
+fi
+done
+
 echo $selection
 
 gui=$(grep $selection /etc/pandora/conf/gui.conf | awk -F\; '{print $3}')
@@ -158,7 +173,7 @@ echo $gui
 if [ $gui ]; then 
   sed -i "s/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=$gui/g" /home/$username/.xinitrc
   echo $selection selected as default interface
-  zenity --info --title="Selected session" --text "You selected $selection as default setting. You can always change your default GUI later." --timeout 6
+  zenity --info --title="Selected session" --text "You selected $selection as default setting." --timeout 6
 else
   sed -i 's/.*DEFAULT_SESSION=.*/DEFAULT_SESSION=startxfce4/g' /home/$username/.xinitrc
 fi
@@ -167,16 +182,20 @@ fi
 
 # Set the timezone and date/time
 
-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
-       zenity --title="Error" --error --text="Please select a timezone." --timeout=6
+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
+       zenity --title="Error" --error --text="Please select your area." --timeout=6
 done
-timezone=`echo $timezone | sed  's/(.*)//g'`
+
+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
+       zenity --title="Error" --error --text="Please select your location." --timeout=6
+done
+
 echo $timezone
-echo rm /etc/localtime && ln -s /usr/share/zoneinfo/Etc/$timezone /etc/localtime
+rm /etc/localtime && ln -s /usr/share/zoneinfo/$area/$timezone /etc/localtime
 
 #Make sure we clean up any leading zeros in the day (as Zenity freaks out)
 date_d=`date +%d | sed 's/^0//'`
-date_m=`date +%m`
+date_m=`date +%m | sed 's/^0//'`
 date_y=`date +%Y`
 
 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
@@ -188,25 +207,99 @@ echo $date
 time_h=`date +%H`
 time_m=`date +%M`
 
-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
+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
         zenity --title="Error" --error --text="Please input the time." --timeout 6
 done
 
 while ! date -d $time ; do
-       time=$(zenity --title="Enter actual time" --entry --text "Please enter the time in 24hour format (HH:MM):" --entry-text "$time_h:$time_m")
+       time=$(zenity --title="Enter current time" --entry --text "Please enter the time in 24hour format (HH:MM).\n" --entry-text "$time_h:$time_m")
 done
  
 date +%Y%m%d -s $date
 date +%H:%M -s $time
+hwclock -u -w
 
-# ----
 
-# Finsh up and boot the system.
+#Let's ask the user about clockspeed
+while ! cpusel=$(zenity --title="Optional settings" --width="400" --height="350" --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" "1100" "Clockspeed: 1,1Ghz, OPP5 (should be stable on 1GHz units)" "1000" "Clockspeed: 1GHz, OPP5 (most probably unstable on 600Mhz units)" "800" "Clockspeed: 800MHz, OPP5 (should be stable on all units)" "600" "Clockspeed: 600MHz, OPP3 (600 MHz units only)" --ok-label="Select CPU Profile" ); do
+    zenity --title="Error" --error --text="Please select your desired CPU Speed profile." --timeout=6
+done
 
-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
+case $cpusel in
+  "1100")
+  echo 5 > /proc/pandora/cpu_opp_max
+  sed -i "s/.*maxopp.*/maxopp:5/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*max:.*/max:1200/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*default.*/default:1100/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*safe.*/safe:1100/g" /etc/pandora/conf/cpu.conf
+  default_cpu=1100
+  ;;
+
+  "1000")
+  echo 5 > /proc/pandora/cpu_opp_max
+  sed -i "s/.*maxopp.*/maxopp:5/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*max:.*/max:1100/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*default.*/default:1000/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*safe.*/safe:1000/g" /etc/pandora/conf/cpu.conf
+  default_cpu=1000
+  ;;
+
+  "800")
+  echo 5 > /proc/pandora/cpu_opp_max
+  sed -i "s/.*maxopp.*/maxopp:5/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*max:.*/max:900/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*default.*/default:800/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*safe.*/safe:800/g" /etc/pandora/conf/cpu.conf
+  default_cpu=800
+  ;;
+
+
+
+  "600")
+  echo 3 > /proc/pandora/cpu_opp_max
+  sed -i "s/.*maxopp.*/maxopp:3/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*max:.*/max:700/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*default.*/default:600/g" /etc/pandora/conf/cpu.conf
+  sed -i "s/.*safe.*/safe:600/g" /etc/pandora/conf/cpu.conf
+  default_cpu=600
+  ;;
+
+esac
 
 # ----
 
+# 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.
+update-rc.d -f samba remove
+update-rc.d -f xinetd remove
+update-rc.d -f avahi-daemon remove
+update-rc.d -f apmd remove
+update-rc.d -f banner remove
+update-rc.d -f portmap remove
+update-rc.d -f mountnfs remove
+update-rc.d -f blueprobe remove
+update-rc.d -f dropbear remove
+update-rc.d -f wl1251-init remove
+# leave this one alone, needed for OTG host mode, powersaving should be ok on 3.2.39 at least
+#update-rc.d -f usb-gadget remove
+
+# prevent wifi from being autoloaded on later kernels, let wl1251-init script do it
+if ! grep -q 'blacklist wl1251_sdio' /etc/modprobe.conf 2> /dev/null; then
+  echo 'blacklist wl1251_sdio' >> /etc/modprobe.conf
+fi
+# we don't ship firmware for rtl8192cu, and it was reported not to work
+# with the right firmware anyway (not verified though)
+# vendor 8192cu is compiled instead for now
+if ! grep -q 'blacklist rtl8192cu' /etc/modprobe.conf 2> /dev/null; then
+  echo 'blacklist rtl8192cu' >> /etc/modprobe.conf
+fi
+
+# add Midi Module and zram
+echo snd-seq>>/etc/modules
+echo zram>>/etc/modules
+
+# get rid of some dirs in /media that OE creates but are unlikely to be used
+rmdir /media/card /media/cf /media/mmc1 /media/net /media/realroot /media/union 2> /dev/null
+
 # Write the control file so this script is not run on next boot 
 # (hackish I know but I want the flexability to drop a new script in later esp. in the early firmwares).
 
@@ -214,4 +307,42 @@ touch /etc/pandora/first-boot
 # Make the control file writeable by all to allow the user to delete to rerun the wizard on next boot.
 chmod 0666 /etc/pandora/first-boot
 
+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
+  . /etc/profile
+  TSLIB_CONSOLEDEVICE=none op_runfbapp ts_calibrate
+  /usr/pandora/scripts/op_touchinit.sh
+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
+      TSLIB_CONSOLEDEVICE=none op_runfbapp ts_calibrate
+  /usr/pandora/scripts/op_touchinit.sh  
+done
+fi
+
+
+
+# Let the user run optional config stuff.
+
+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" "lcd" "LCD-Settings" --ok-label="Change selected Setting" --cancel-label="Finish Setup"); do
+
+case $mainsel in
+  "speed")
+  /usr/pandora/scripts/op_cpusettings.sh
+  ;;
+
+   "startup")
+  echo $username > /tmp/currentuser
+  /usr/pandora/scripts/op_startupmanager.sh
+  ;;
+
+   "lcd")
+  /usr/pandora/scripts/op_lcdsettings.sh
+  ;;
+
+esac
+done
+# ----
+
+
 # ----
+else
+poweroff
+fi