#!/bin/sh
#KUSTOMIZER - to tune Openmoko 2008.12 Linux distribution into an usable phone/PDA/toy/something on Openmoko Freerunner
#Copyright (C) 2009 Risto H. Kurppa risto \a/ kurppa \dot/ fi http://risto.kurppa.fi/blog

KUSTOMIZER IS NOT SUPPORTED NOR DEVELOPED ANY MORE
IT'S NOT RECOMMENDED TO USE IT ANY MORE




#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

# PLEASE SEND ALL SUGGESTIONS, COMMENTS & FEEDBACK to risto \a/ kurppa \dot/ fi

# Version 0.41 - 2009-04-28
# CHANGELOG
# (new) aapotap to rotate the screen
# (new) knj repository, http://wiki.openmoko.org/wiki/Knjrepository
# (new) jdd - jack detection daemon
# (new) knjmokowifi wifi manager, see http://wiki.openmoko.org/wiki/KnjMokoWifi
# (fix) typo: dim time -> blank time
# (removed) omnewrotate - didn't work as expected..


# Version 0.4 2009-03-15
# KNOWN ISSUES
# many packages from opkg.org fail to install
# mokomode, gpsdcontrol, wlan and meooem icons need to be global=visible in all categories because of sortdesk
# navit doesn't show the 'ETA' etc any more
# navit speak is unclear :(

# CHANGELOG
# (new) Kustomizer mailing list started: joing by mailing kustomizer+subscribe@googlegroups.com
# (new) wlan
# (new) install log stored to a file!
# (new) enter key added to the default keyboard
# (new) Finger keyboard http://lists.openmoko.org/nabble.html#nabble-td2217821
# (new) browse keyboard http://www.opkg.org/package_144.html
# (new) Voicenote http://www.opkg.org/package_140.html
# (new) qtopia calendar
# (new) Mokomodes http://users.jyu.fi/~hejajama/openmoko/mokomode_0.1_arm.ipk
# (new) pipes http://www.opkg.org/package_155.html
# (new) OMnewrotateMOD http://www.opkg.org/package_148.html
# (new) leafpad http://www.opkg.org/package_152.html
# (new) perpendicular http://www.opkg.org/package_150.html
# (new) voicenote http://www.opkg.org/package_140.html
# (new) acceleroids http://www.opkg.org/package_154.html
# (new) qtopia notes/text edit
# (new) findutils
# (new) qtopia ringtone/profile settings tool (check wrench -> profiles)
# (new) netsurf - another not-working web-browser for you to play with (http://cc.oulu.fi/~rantalai/freerunner/netsurf/)
# (new) openmoko-browser2
# (fix) changed the following to point from repositories to original url: centerim, openttd, numpty, xlogical
# (fix) Password now asked already in the first stage
# (fix) ntpclient installed & time updated in the first stage
# (fix) gpsd doesn't ask for autostart anymore -> one interaction less required during the installation
# (fix) added libexif to make tangogps 0.9.6 work 
# (fix) sortdesk now installed from projects.openmoko.org to make sure it's installed
# (fix) pythm-fix by yebo gogo (=some packages from SHR & then custom pythm .tar.gz..)
# (fix) typo when installing enca - but enca still fails in md5sum mismatch..
# (fix) gwaterpas icon
# (fix) Another try with dillo-ssl
# (removed) tapuntap(aatap) - installed omnewrotatemod instead
# (removed) openmoko-mediaplayer2 - pythm does ~the same
# (removed) wireshark - not often needed..
# (removed) tangogps sample config - new yaouh version has fixed this?
# (removed) xmahjongg - it never installed..
# (removed) gpssight - installation fails
# (removed) liquidwar - package segfaults opkg..


# Version 0.35 - 2009-02-20
# CHANGELOG
# (new) pymixer from http://wiki.openmoko.org/wiki/Neo_Freerunner_audio_subsystem#Alsamixer_channel_controls
# (new) Bytestore settiong builder: http://lists.openmoko.org/nabble.html#nabble-td2353361
# (new)    - Dillo SSL works!
# (new)    - Not suspending when USB connected
# (new)    - Improved Mokoservices
# (new)    - Tangogps configuration file (for yaouh)
# (new) yaouh map tile updater
# (new) AppManager package installer GUI
# (update) fbreader now installed from http://www.mikeasoft.com/~mike/openmoko/fbreader_0.8.2a-r7+elleopatches_om-gta02.ipk
# (fix) often-not-available enca package doesn't prevent any more other libraries from being installed -> more ok installs :)
# (fix) pythm icon
# (fix) more pythm fixes & required packages..
# (fix) openmoko-agps icon
# (fix) navit icon
# (removed) btgps (bluetooth-gps - not working, broken bluez-utils :(
# (removed) xskat (card game)
# (removed) moko-eightball (toy)
# KNOWN ISSUES

# Version 0.3 - 2009-02-19
# KNOWN ISSUES
# Many opkg.org packages fail to install because of bad packaging. They're still in there in case the packages are fixed at some stage.
# /dev/dsp is sometimes reserved (by speech-dispatcher?) so other apps can't use it
# GSM registration takes a long time
# CHANGELIST
# (fix) all possible packages installed using default & opkg.org & navit repositories
# (new) tried to fix speech-dispatcher -bug, see http://lists.openmoko.org/nabble.html#nabble-td2175057
# (new) password required for the root user during installation
# (new) ssh-over-wlan allowed
# (new) navit repository added -> updates from svn 1793 to 2051+ :)
# (new) Backups copies of some changed files stored to /home/root/backup
# (new) ntp to set clock in time
# (new) Sortdesk icons (thanks Yoann - http://lists.openmoko.org/pipermail/community/2009-February/041915.html)
# (new) opentts -> navit speech guidance works more or less
# (new) Sample book for fbreader included: http://www.gutenberg.org/etext/24948
# (new) linball
# (new) gtick http://wiki.openmoko.org/wiki/GTick
# (new) guitartune http://www.opkg.org/package_115.html
# (new) pythm http://www.opkg.org/package_1.html
# (new) fourier - sounds work -> returned
# (new) pypennotes
# (new) openmiaocat
# (new) agps
# (new) pythm & a fix to make it work w. python 2.5.
# (removed) mofi - doesn't work :(
# (removed) pidgin - segfaults
# (removed) scummvm - useless..
# (removed) yaouh - doesn't co-operate with latest tangogps versions without some hacking :(

# Version 0.2 changelog - released 2009-02-06
# (new) two run system:
# 1st run: illume-theme, wrench, qwerty are installed, opkg.org, storage.conf/qpe-bug fixed. Then restarted
# 2nd run: user needs to start Kustomizer again (and switch suspend/dim off!!) -> the rest is installed
# Rewriting the instructions
# General cleaning
# (new) ntpclient 
# (new) http://www.opkg.org/package_121.html - MokoMaze
# (new) ttf-liberation-mono (vala-terminal uses this)
# (new) battery http://wiki.openmoko.org/wiki/Forcing_fast_charge_mode
# (new) runs /media/card/customscript - the user can add his own stuff there
# (new) automatic prevention of suspend & dimming
# (update) yaouh - version update
# (update) neon - version update
# (remove) Finnish keyboard layout & dictionary
# (remove) custom scripts from card
# (remove) cellhunter - on FSO-based only?
# (remove) Guitartune - on FSO-based only and libfft fails to install
# (remove) fourier - libfft fails to install
# (remove) zomg and appmanager - less used..
# (remove) pingus - doesn't install
# (remove) mumpot - useless for most
# (remove) usbmode - battery replaces most of this
# (fix) watch checkrate changed from 1s to 2s
# (fix) libglade-2.0 -> libglade-2.0-0

#TODO:

# PRIORITY 1
# Sortdesk forces meooem and gpsdcontrol icons to be global or they don't work -> FAIL

# THE REST
# Move all config things to first stage & install apps in 2nd stage
# remove gpsdcontrol? (useless with mokoservices?)
# working wlan-tool
# Intone mplayer frontend: http://n2.nabble.com/Annuncing-new-Project---Intone-mplayer-frontend-tp2357405p2357405.html
# navit northing on by default
# (config) disable wlan by default?
# FBreader line spacing to ~2.8 or so (.FBreader/ui.xml)
# (new) pdf-viewer
# (new) http://users.jyu.fi/~hejajama/openmoko/mode/
# (config) Midori default font size
# (config) set locales (ask?)
# (config) Change startup graphics
# (config) Make the keylock image smaller so that it wouldn't cover the whole screen
# http://wiki.openmoko.org/wiki/FDOM -> maybe drop illume-theme but install terminal keyboard & qwerty -button. Problem is that after this there's no way to change the screen blanking time..
# (check) https://docs.openmoko.org/trac/ticket/2192#comment:3 -> illume keyboard on asu theme


#####################################################
## ON DESKTOP COMPUTER (written for Ubuntu 8.10 and newer)
#####################################################
# I'm sure you've done the backups and know enough so don't blame me if things break :)
# For more information please visit http://wiki.openmoko.org/wiki/Kustomizer

## PREPARE
# install required packages:
# a) run: sudo apt-get install dfu-util bind9 
# dfu-util is also available from http://downloads.openmoko.org/distro/releases/Om2008.9/dfu-util

## FLASH
# for more details, see http://wiki.openmoko.org/wiki/Flashing_the_Neo_Freerunner
# download the required image files
# b) run: wget http://downloads.openmoko.org/distro/releases/Om2008.12/Om2008.12-om-gta02.uImage.bin & wget http://downloads.openmoko.org/distro/releases/Om2008.12/Om2008.12-om-gta02.rootfs.jffs2
# c) Connect your freerunner to the computer with the USB cable
# d) start your Freerunner holding the AUX button down to get to the NOR menu
# e) run: sudo time dfu-util -a kernel -R -D Om2008.12-om-gta02.uImage.bin
# f) run: sudo time dfu-util -a rootfs -R -D Om2008.12-om-gta02.rootfs.jffs2
# g) Start & restart Freerunner to be able to log in over USB ssh
# h) Go to 'Settings' and change 'Suspend' to 'off' or Freerunner will suspend and the installation will fail.

## CONNECT
# Connect over usb-ssh with shared internet connection
# Don't run the script on Freerunner's screen! It can be done but not recommended if you don't know what you're doing.
# Download a script to help you & change the permission
# i) run: wget http://www.kurppa.fi/freerunner/fr_bind && chmod 755 fr_bind
# j) run: ./fr_bind
# k) First it asks for your Ubuntu -password to restart the interface & bind9 - type it in
# l) After this it asks for Freerunner password - it's empty, just hit Enter 
# For more details check http://wiki.openmoko.org/wiki/Usb_networking#Ubuntu_8.10_-_Easy_Way

#####################################################
## FREERUNNER
#####################################################
# 1) Make sure you've turned 'Suspend' to 'off' in the Settings.
# 2) Make sure you can SSH in over USB so that Freerunner has Internet connection (ping google.com?)
# 3) run: wget http://www.kurppa.fi/freerunner/kustomizer_latest && chmod 755 kustomizer_latest
# 4) run: ./kustomizer_latest
#   Now it will install the most important fixes. You can stop here or after Kustomizer has restared your phone, you can
# 5) Reconnect ovet SSH to Freerunner, make sure it has internet connection over USB
# 6) run: ./kustomizer_latest
#   This time it'll install GPRS and many applications.

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#START OF THE ACTUAL SCRIPT
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

cd /home/root
touch kustomizer.log

firststage ()
{
#suspend off
dbus-send --system --dest=org.openmoko.Power / org.openmoko.Power.Core.RequestResourceState string:cpu string:kustomizer string:on
#screen dimming off
DISPLAY=:0 xset s 0 0

echo " _           _             _             "
echo "| |_ _ _ ___| |_ ___ _____|_|___ ___ ___ "
echo "| '_| | |_ -|  _| . |     | |- _| -_|  _|"
echo "|_,_|___|___|_| |___|_|_|_|_|___|___|_|  "
echo "Welcome to KUSTOMIZER for OM 2008.12"
echo "Enjoy it!!!"
echo "  "
echo "Installation log will be saved to kustomizer.log"
echo "  "

backupdir="/home/root/backup"
if ! [ -d $backupdir ]
then
 mkdir $backupdir
fi

# If this is the first run, we go to this loop to install some stuff that requires a restart
qpefile="$backupdir/Storage.conf"
if ! [ -e "$qpefile" ]
then

echo " -> First run detected."
echo " -> Freerunner will be RESTARTED SOON to apply some changes. Then run Kustomizer again over SSH to complete the installation. "
echo "  "
##############################
## opkg.org repository
##############################
echo " -> Adding opkg.org community repository & updating the databases"
echo "src/gz opkgorg http://www.opkg.org/packages" > /etc/opkg/opkg-feed.conf
echo " -> Updating package databases"
echo "  "
opkg update

##############################
## illume theme & raster's keyboard
##############################

echo "  "
echo " -> Installing new theme & keyboard & config tool"
echo "  "
#source: http://wiki.openmoko.org/wiki/Illume#How_to_install_the_illume_.28Raster.27s.29_keyboard_.3F
opkg install illume-config xterm nano ntpclient
#this will add "export QTOPIA_NO_VIRTUAL_KEYBOARD=1" to start of /etc/X11/Xsession.d/89qtopia
cd /etc/X11/Xsession.d
cp 89qtopia $backupdir/89qtopia
wget http://www.kurppa.fi/freerunner/config_files/89qtopia -O 89qtopia
opkg install illume-config-illume
echo 'E_PROFILE="-profile illume"' > /etc/enlightenment/default_profile
rm -rf ~/.e/e/config/illume
#remove dropshadow
rm /usr/lib/enlightenment/modules/dropshadow -rf

##################################
# ENTER KEY TO THE DEFAULT KEYBOARD
#################################

KEYBOARD="/usr/lib/enlightenment/modules/illume/keyboards/Default.kbd"
[ -e "$KEYBOARD" ] && {
       grep -qi "return" $KEYBOARD || {
               echo "adding 'Return' key to default keyboard"

               echo >>"$KEYBOARD" "# added by '$0'"
               echo >>"$KEYBOARD" "key 85 25 20 10"
               echo >>"$KEYBOARD" "    normal enter.png Return"
       }
}

# --------------

##########################
# Finger keyboard http://lists.openmoko.org/nabble.html#nabble-td2217821
###########################
cd /usr/lib/enlightenment/modules/illume/keyboards/
wget http://www.mimuw.edu.pl/~makbet/Keyboard-ng.kbd
# restart enlightenment
killall -HUP enlightenment

#########################
# prevent qpe from scanning through you uSD card
# http://wiki.openmoko.org/wiki/2008.8#Known_Issues
###########################
echo " -> Preventing qpe from eating CPU resources"
echo "  "
cd /opt/Qtopia/etc/default/Trolltech
cp Storage.conf $backupdir/Storage.conf
wget http://kurppa.fi/freerunner/config_files/Storage.conf -O Storage.conf

##############################
## AUDIO
##############################
echo " -> Installing files for better phone audio quality"
echo "  "
	#fixed gsmhandset.state
	cd /usr/share/openmoko/scenarios/
	cp gsmhandset.state $backupdir/gsmhandset.state
	wget http://users.tkk.fi/~tajyrink/moko/gsmhandset.state -O gsmhandset.jyrinki.state
	cp gsmhandset.jyrinki.state gsmhandset.state

##############################33
# SECURITY ETC
################################

#Set clock
echo " -> Updating time from ntp server"
ntpclient -s -h 0.pool.ntp.org

#Ask for a new password
echo " -> Let's set a password to protect your phone"
echo " "
passwd

#Enable ssh over WLAN
echo " -> Now that we have a password, let's allow SSH over WLAN"
echo " "
echo "DROPBEAR_PORT=22" > /etc/default/dropbear

echo " -> First stage done, RESTARTING in 10s!!!"
echo " -> THE FIRST STAGE IS NOW COMPLETED!!"
echo "  "
echo " -> If you want to install GPRS and a bunch of applications, after restarting:"
echo " -> 0) Go to top-menu -> wrench -> power -> change blank time to 'off'"
echo " -> 1) Answer 'recover' on the crash screen or 'yes' to 'do you want to unload module' questions"
echo " -> 2) Reconnect to Freerunner over SSH."
echo " -> 3) Make sure Freerunner can access Internet over SSH"
echo " -> 4) Rerun Kustomizer (type ./kustomizer_latest)"
echo " "
echo " Join the kustomizer mailing list by mailing kustomizer+subscribe@googlegroups.com "
echo " Also check the wiki page at http://wiki.openmoko.org/wiki/Kustomizer"

sleep 10
shutdown -r now &
#sleep 5
#dbus-send --system --dest=org.openmoko.Power / org.openmoko.Power.Core.RemoveRequestedResourceState string:cpu string:kustomizer
exit
fi

}
firststage 2>&1 | tee -a kustomizer.log

##############################
## SECOND RUN
##############################

secondstage ()
{
echo " -> Second run detected, c00l :)"
echo " -> This run will install GPRS and a variety of applications"

infofile="/home/root/kustomizer_messages.log"
rm $infofile > /dev/null 2> /dev/null

#info display on freerunner screen with xterm
DISPLAY=:0 xterm -e "watch -tn 2 cat $infofile" &

echo " _           _             _             ">>$infofile
echo "| |_ _ _ ___| |_ ___ _____|_|___ ___ ___ ">>$infofile
echo "| '_| | |_ -|  _| . |     | |- _| -_|  _|">>$infofile
echo "|_,_|___|___|_| |___|_|_|_|_|___|___|_|  ">>$infofile
echo "KUSTOMIZER for Openmoko 2008.12">> $infofile
echo "You'll be shown some progress information here" >> $infofile
echo "If you get a message of Enlightenment crashing, press 'Recover'">>$infofile
echo "--------------------------">>$infofile

echo " -> Check your Freerunner screen for a simple progress display :)"
echo " "
echo " -> Let's start with adding Navit & KNJ repository and upgrading"

#see http://wiki.openmoko.org/wiki/Navit
echo src navit http://download.navit-project.org/navit/openmoko/svn >/etc/opkg/navit-feed.conf
wget http://downloads.kaspernj.org/openmoko/repository/knjrepository.conf -O /etc/opkg/knjrepository.conf

opkg update
opkg upgrade

##############################
## LINKING /home/root/Maps
##############################

if [ -d "/media/card/Maps" ]
then
    echo "Configuring Navit & Tangogps map directories">>$infofile
    echo " -> Configuring Navit & Tangogps map directories"

	if [ -d "/home/root/Maps" ]
	then
	echo " -> Moving old /home/root/Maps to /home/media/Maps_original"
	mv /home/root/Maps /home/root/Maps_original
	fi
	echo " -> Linking /home/root/Maps to /media/card/Maps"
	ln -s /media/card/Maps /home/root/Maps
fi

##############################
## MOKOSERVICES && TAP/UNTAP from FDOMizer
##############################
cd /tmp
wget http://files.tdobson.net/openmoko/freerunner/fdom/FDOMizer20081023.tar.gz

file="FDOMizer20081023.tar.gz"
if [ -e "$file" ]
then
	echo " -> Installing some parts of FDOM"
	tar zxf FDOMizer20081023.tar.gz
	cd FDOMizer/

	#THIS IS FROM FDOMIZER by Nacho Seijo nacho.seijo@gmail.com, see http://www.tuxbrain.com/fdom_en.html
	#installs services application and all scripts needed to use gprs
	tar -xzf mokoservicescripts.tar.gz -C /tmp
	cd /tmp/mokoscripts
	chmod a+x gprs-*
	cp gprs-* /etc/ppp/
	cp gprs /etc/ppp/peers/
	chmod a+x gprs* wifistatus nowifi mokoservices.py
	cp gprs* wifistatus nowifi mokoservices.py /usr/bin
	cp mokoservices.png /usr/share/pixmaps/
	#cp mokoservices.desktop /usr/share/applications

	Ugly, I know.. tapuntap will be replaced by a bit more simple script by Aapo Rantalainen
	cd /tmp/FDOMizer/
	cd tapUntap
	chmod a+x tapuntap.py
	cp tapuntap.py /usr/bin
	cp tapuntap.desktop /usr/share/applications
	cp tapuntap.png /usr/share/pixmaps
	wget http://kurppa.fi/freerunner/config_files/aapotap.py -O /usr/bin/tapuntap.py
	chmod 755 /usr/bin/tapuntap.py
fi


##############################
##INSTALL ALL COOL APPS!!
##############################

#xlogical wireshark wireshark-common segfaults the installation in installed from opkg.org repository!

echo "Installing packages from the repositories - this takes a while..">>$infofile
echo " "
echo " -> Installing packages from the repositories"
echo " -> SOME PACKAGES WON'T INSTALL: can't find / segfault / md5sum mismatch"
echo " -> It's just bad packaging and we need to wait for someone to fix the packages.. :("
echo " "
opkg install bluez-utils python-ecore python-edbus python-edje python-evas python-dbus python-textutils \
mtpaint openmoko-agpsui libglade-2.0-0 gpsd libmokoui2-0 \
libsqlite3-0 libpixman-1-0 libglib-2.0-0 libdbus-glib-1-2 libdbus-1-3 libcurl4 libcairo2 \
libsdl-image-1.2-0 libsdl-1.2-0 libpng3 libgcrypt11 midori alsa-oss alsa-utils-aplay pong gtk+ libgnutls13 \
tzdata tzdata-europe python-pygame python-subprocess qtopia-phone-x11-calculator curl python-pygtk \
libgpg-error0 ttf-liberation-mono gsm0710muxd findutils

echo "Installing all cool apps around the Net.. ">>$infofile

#temporarily removed. The server is often down but the fbreader works better than the one installed from opkg.org..
#http://mikeasoft.com/~mike/openmoko/enca_1.9-r3_armv4t.ipk \
#http://www.mikeasoft.com/~mike/openmoko/fbreader_0.8.2a-r7+elleopatches_om-gta02.ipk 

#Changed to this instead of opkg install http://package http://etc if this would work better..
cd /tmp
wget http://downloads.freesmartphone.org/fso-testing/feeds/armv4t/enca_1.9-r3_armv4t.ipk
wget http://3v8.net/~sander/openmoko/libxft2_2.1.12-r1_armv4t.ipk
wget http://www.angstrom-distribution.org/feeds/2007/ipk/glibc/armv4t/base/libmad0_0.15.1b-r0_armv4t.ipk
wget http://www.angstrom-distribution.org/feeds/2007/ipk/glibc/armv4t/base/libmpeg2-0_0.4.0b-r4_armv4t.ipk
wget http://www.angstrom-distribution.org/feeds/2007/ipk/glibc/armv4t/base/libfftw3-3_3.1.2-r1_armv4t.ipk
wget http://downloads.openmoko.org/repository/testing/armv4t/libsdl-1.2-0_1.2.11-r6_armv4t.opk
wget http://projects.openmoko.org/frs/download.php/497/libconfig_1.3.1_armv4t.ipk
wget http://projects.openmoko.org/frs/download.php/496/imlib2_1.4.1_armv4t.ipk
wget http://buildhost.automated.it/OM2007.2/packages/armv4t/zenity_2.20.1-r0_armv4t.ipk
wget http://www.ecirc.net/openmoko/libfltk_1.1.9-0_armv4t.ipk
wget http://pcl210-00.fit.vutbr.cz/openmoko/libexif_0.6.17_armv4t.ipk

opkg install *pk
# BLUEZ BROKEN -> DOESN*T WORK! remoko http://remoko.googlecode.com/files/remoko-server_0.2.1_svnr119-r0_armv4t.ipk \

echo "We're almost there, be patient :)">>$infofile

opkg install orrery
opkg install duke3d
opkg install libboost-signals libboost-signals1.33.1
opkg install leafpad
opkg install pipes
opkg install fbreader
#To be sure we get the latest one / a working one..
opkg install tangogps http://pcl210-00.fit.vutbr.cz/openmoko/tangogps_0.9.6-r1_armv4t.ipk
opkg install vala-terminal gwaterpas openmoocow fourier mokomaze acceleroids
opkg install gtkaddpoi minimo meooem gpsdcontrol neon qwo openmoko-browser2 
opkg install shortom
opkg install ledclock mokox48 ffalarms illume-keyboards-browser
opkg install mokoconv 
opkg install guitartune
opkg install agps
opkg install openmiaocat
opkg install jdd
opkg install gtick
opkg install AppManager
opkg install yaouh
opkg install knjmokowifi_latest # from knj repository
opkg install voicenote http://kimaidou.kilu.de/openmoko/voicenote/voicenote_0.3_arm.ipk
opkg install qtopia-phone-x11-ringprofile qtopia-phone-x11-ringprofile-app-data qtopia-phone-x11-datebook qtopia-phone-x11-textedit

opkg install --force-depends perpendicular 

#Netsurf
opkg install http://cc.oulu.fi/~rantalai/freerunner/netsurf/lcms_1.15-r0_armv4t.opk \
http://cc.oulu.fi/~rantalai/freerunner/netsurf/netsurf_1.2-r0.1_armv4t.opk

#navit & speech stuff, see 
# http://projects.openmoko.org/frs/?group_id=86
# http://wiki.openmoko.org/wiki/Navit#Speech
wget http://projects.openmoko.org/frs/download.php/103/speech-dispatcher_0.6.5-r3_pulse_armv4t.ipk.tgz
tar zxf speech-dispatcher_0.6.5-r3_pulse_armv4t.ipk.tgz

opkg install \
http://projects.openmoko.org/frs/download.php/100/espeak-pulse_1.31-r1_armv4t.ipk \
speech-dispatcher_0.6.5-r3+pulse_armv4t.ipk navit

#random apps
opkg install \
http://downloads.tuxfamily.org/3v1deb/openmoko/libwebkit-1.0-1_0.1%2bsvnr37056_armv4t.ipk \
http://hdr.meetr.de/neo/openmoko/battery/battery_0.20080721_armv4t.ipk \
http://linball.sf.net/linball-openmoko_0.2_armv4t.opk linball \
http://aiurlano.netsons.org/OpenMoko/ipk/armv4t/pypennotes_0.3b-r1_armv4t.ipk \
http://users.jyu.fi/~hejajama/openmoko/mokomode_0.1_arm.ipk \
http://openttd.projects.openmoko.org/openttd_0.6-r0.6_armv4t.opk \
http://centerim.projects.openmoko.org/centerim_4.22.7-r0.1_armv4t.opk \
http://projects.openmoko.org/frs/download.php/602/numptyphysics_0.3-svn116_armv4t.opk \
http://xlogical.projects.openmoko.org/xlogical_1.0-8-r0.2_armv4t.opk \
http://www.opkg.org/packages/wlan_0.3_arm.ipk

cd /
#wget http://filmsbykris.com/freerunner-debian/ko-user/ko-lightsaber.tar.gz && tar zxf ko-lightsaber.tar.gz
wget http://filmsbykris.com/freerunner-debian/ko-user/ko-dice.tar.gz && tar zxf ko-dice.tar.gz

#pymixer from http://wiki.openmoko.org/wiki/Neo_Freerunner_audio_subsystem#Alsamixer_channel_controls
wget http://handheldshell.com/pymixer.py 
wget http://handheldshell.com/volume.desktop
cp pymixer.py /usr/bin
chmod u+x /usr/bin/pymixer.py
cp volume.desktop /usr/share/applications
opkg install python-pygtk
opkg install http://handheldshell.com/python-pyalsaaudio_0.3-ml0_armv4t.ipk

#pythm
opkg install \
http://shr.bearstech.com/shr-unstable/ipk/armv4t/mplayer-common_0.0.1-r0_armv4t.ipk \
http://shr.bearstech.com/shr-unstable/ipk/armv4t/libxv1_1.0.3-r1_armv4t.ipk \
http://shr.bearstech.com/shr-unstable/ipk/armv4t/libmp3lame0_3.96.1-r4_armv4t.ipk \
http://shr.bearstech.com/shr-unstable/ipk/armv4t/mplayer_0.0+1.0rc2-r12_armv4t.ipk \
http://downloads.tuxfamily.org/3v1deb/openmoko/python-mokoui2_0.1.0+svnr4342_armv4t.ipk \
http://downloads.freesmartphone.org/fso-testing/feeds/armv4t/gst-plugin-mad_0.10.7-r2_armv4t.ipk \
http://downloads.freesmartphone.org/fso-testing/feeds/armv4t/libxml2_2.7.2-r0_armv4t.ipk \
http://downloads.freesmartphone.org/fso-testing/feeds/armv4t/libid3tag0_0.15.1b-r1_armv4t.ipk \
http://downloads.freesmartphone.org/fso-testing/feeds/armv4t/libmad0_0.15.1b-r4_armv4t.ipk \
python-pyalsaaudio python-gst gst-plugin-playbin gst-plugin-ogg python-mokoui2 mutagen
#cp /usr/lib/python2.6/site-packages /usr/lib/python2.5/site-packages -R

ln -s /usr/lib/python2.6/site-packages/pythm/ /usr/lib/python2.5/site-packages/pythm
ln -s /usr/lib/python2.6/site-packages/mutagen/ /usr/lib/python2.5/site-packages/mutagen

cd /home/root
wget http://www.kurppa.fi/freerunner/config_files/Pythm-0.5.1.tar.gz
tar xvzf Pythm-0.5.1.tar.gz
cp Pythm-0.5.1/conf/pythm.conf-example /etc/pythm.conf #(I changed the renice to -11 and the standard music directory to /media/card)
cp Pythm-0.5.1/conf/pythm.desktop /usr/share/applications #(I took an icon and "created" the .desktop file which is sadly missing in about every package)

##############################
## Bytestore setting builder
##############################

echo "Applying various fixes and config files">>$infofile
echo "Thanks BYTESTORE!!">>$infofile

echo " "
echo " -> Applying various fixes and config files"
echo " -> Thanks BYTESTORE!!"
echo " "

cd /tmp
wget http://openmoko.spb.ru/repository/settingbuilder_bytestore.tar.gz
tar zxf ./settingbuilder_bytestore.tar.gz
cd install

echo " -> install dillo"
opkg install http://misc.andi.de1.cc/dillo/dillo_2.0-r1_armv4t.opk
opkg install --force-overwrite dillo-ssl
echo "copy settings for dillo"
cd dillo
sh install.sh

#echo " -> install qwerty button & asu theme"
#cd ../qwerty                             
#sh install.sh                           

#echo " -> install pidgin"
#opkg install pidgin pidgin-data libpurple-protocol-icq
#echo "install pidgin locale-ru"
#opkg install pidgin-locale-ru

#echo " -> patching QPE"
#cd ../qpe
#sh install.sh

echo " -> copy voice settings"
cd ../scenarios
sh install.sh

echo " -> usb detect cable settings"
cd ../usbcable
sh install.sh

echo " -> install mokoservices and gsm0710muxd"
cd ../services
sh install.sh

echo " -> install Tangogps and copy repository config"
cd ../tangogps
#sh install.sh
mkdir /home/root/.gconf/apps/
mkdir /home/root/.gconf/apps/tangogps/
cp ./%gconf.xml /home/root/.gconf/apps/%gconf.xml
cp ./tangogps/%gconf.xml /home/root/.gconf/apps/tangogps/%gconf.xml 

#return gsmhandset.state
cd /usr/share/openmoko/scenarios/
cp gsmhandset.jyrinki.state gsmhandset.state

##############################
## GPRS
##############################
echo "Installing GPRS settings">>$infofile
cd /
wget http://users.tkk.fi/~tajyrink/moko/openmoko-gprs.tar
gprsfile="openmoko-gprs.tar"
if [ -e "$gprsfile" ]
then
	tar xvf openmoko-gprs.tar
	rm openmoko-gprs.tar
	wget http://www.kurppa.fi/freerunner/config_files/89qtopia.advanced -O /etc/X11/Xsession.d/89qtopia
fi

##############################
#agps
##############################

agpsfile="/usr/bin/agps"
if [ -e "$agpsfile" ]
then
  #Should add something to run this only if GPRS is on - or turn GPRS automatically on to run this..
  echo "#!/bin/sh">$agpsfile
  echo "/etc/init.d/gpsd start">>$agpsfile
  echo "echo 1 >/sys/bus/platform/drivers/neo1973-pm-gps/neo1973-pm-gps.0/pwron">>$agpsfile
  #You will have to have registered for an account by emailing: agps-account@u-blox.com
  #-la -lo = latitude & longnitude
  # -al = altitude
  # -p = precision, in km (radius of a circle from the coordinates given)
  echo "/usr/bin/agps-onlinec -c full -u YOUR-EMAIL-ADDRESS -k YOURPASSWORD -la 60.976 -lo 25.6942 -al 40 -p 150">>$agpsfile
fi


##############################
## Application configuration
##############################
echo "Configuring some applications">>$infofile
echo "Configuring some applications"

#FBREADER sample book
file="/usr/bin/FBReader"
if [ -e "$file" ]
then
	cd /home/root
	wget http://www.gutenberg.org/files/24948/24948-0.zip
	unzip 24948-0.zip
	mv 24948-0.txt FB_samplebook.txt
fi

#NAVIT
if [ -d "/home/root/.navit" ]
then
  cd /home/root/.navit
  cp navit.xml $backupdir/navit.xml
else 
  mkdir /home/root/.navit
fi

cd /home/root/.navit
wget http://www.kurppa.fi/freerunner/config_files/navit.xml
cp /media/card/Maps/navit/*.txt /home/root/.navit

#SPEECH-DISPATCHER -bug fix trial..
#http://lists.openmoko.org/nabble.html#nabble-td2175057
dispatcherfile="/etc/init.d/speech-dispatcher"
if [ -e "$dispatcherfile" ]
then
  cp /etc/init.d/speech-dispatcher $backupdir/speech-dispatcher
  wget http://kurppa.fi/freerunner/config_files/speech-dispatcher -O /etc/init.d/speech-dispatcher
  ln -s /usr/lib/libaoss.so.0 /usr/lib/libaoss.so 
  cd /etc/speech-dispatcher/modules/
  wget http://www.kurppa.fi/freerunner/config_files/speech-dispatcher-modules.tar.gz
  tar zxf speech-dispatcher-modules.tar.gz
fi

#MEOOEM
#add Helsinki and run meooem to update the weather icon
echo "city_code=FIXX0002" >> /etc/meooem.conf
meooem

#Xmahjongg config - NOT INSTALLED-> CONFIG NOT USED
#file="/usr/bin/xmah.sh"
#if [ -e "$file" ]
#then
#  #fixed xmahjongg script
#  xmahjonggfile="/usr/bin/xmah.sh"
#  echo "#!/usr/bin/env sh" > $xmahjonggfile
#  echo "DISPLAY=:0 /usr/bin/xrandr -o 3 && /usr/bin/xmahjongg --tileset small; DISPLAY=:0 /usr/bin/xrandr -o 0" >> $xmahjonggfile
#  chmod 755 /usr/bin/xmah.sh
#fi

#WEBKIT
#Source: see "[OE] Getting the curl-based apps (Webkit browsers!) working with HTTPS" mail 
#by Marco Trevisan (Treviño) at openmoko-community 27th of January
#Also some packages are installed earlier because of this, like libwebkit
cd /
wget http://downloads.tuxfamily.org/3v1deb/openmoko/libcurl-gnutls-unsafe.tar.bz2
tar jxf libcurl-gnutls-unsafe.tar.bz2

##################################
#ICON FIXES
##################################
cd /usr/share/applications/
echo "Categories=Utility" >> battery.desktop
echo "Icon=mokoservices" >> volume.desktop
echo "Icon=calculator/Calculator" >> openmoko-agpsui.desktop

cd /usr/share/pixmaps
cp openmoko-mediaplayer.png mplayer.png 2> /dev/null
cp fourier.png mplayer.png 2> /dev/null
cp guitartune.png mplayer.png 2> /dev/null
cp /usr/share/icons/hicolor/128x128/apps/navit.png navit.png

file="/bin/perpendicular"
if [ -e "$file" ]
then
perpendifile="/usr/share/applications/perpendicular.desktop"
echo "[Desktop Entry]" >> $perpendifile
echo "Name=Perpendicular" >> $perpendifile
echo "GenericName=Perpendicular" >> $perpendifile
echo "Comment=Shows perpendicular" >> $perpendifile
echo "Exec= perpendicular" >> $perpendifile
echo "Icon=/usr/share/pixmaps/omnewrotate.png" >> $perpendifile
echo "Terminal=false" >> $perpendifile
echo "Type=Application" >> $perpendifile
echo "Categories=Office;" >> $perpendifile
echo "MimeType=text/x-vcard;" >> $perpendifile
echo "StartupNotify=false" >> $perpendifile
fi

file="/usr/bin/mtpaint"
if [ -e "$file" ]
then
mtpaintfile="/usr/share/applications/mtpaint.desktop"
echo "[Desktop Entry]" >> $mtpaintfile
echo "Encoding=UTF-8" >> $mtpaintfile
echo "Name=Mtpaint" >> $mtpaintfile
echo "TryExec=mtpaint" >> $mtpaintfile
echo "GenericName=Mtpaint" >> $mtpaintfile
echo "Comment=Mt paint" >> $mtpaintfile
echo "StartupNotify=false" >> $mtpaintfile
echo "Exec=mtpaint" >> $mtpaintfile
echo "Icon=pyefl-sudoku" >> $mtpaintfile
echo "Terminal=false" >> $mtpaintfile
echo "Type=Application" >> $mtpaintfile
echo "Categories=Applications;Game;ENLIGHTENMENT;" >> $mtpaintfile
fi

# XMAHJONGG not installed anymore (it actually never installed...)
#file="/usr/bin/xmah.sh"
#if [ -e "$file" ]
#then
#  #Xmahjongg icon
#  xmahjonggfile="/usr/share/applications/xmahjongg.desktop"
#  echo "[Desktop Entry]" >> $xmahjonggfile
#  echo "Encoding=UTF-8" >> $xmahjonggfile
#  echo "Name=Xmahjongg" >> $xmahjonggfile
#  echo "StartupNotify=false" >> $xmahjonggfile
#  echo "Exec=xmah.sh" >> $xmahjonggfile
#  echo "Icon=xmahjongg" >> $xmahjonggfile
#  echo "Terminal=false" >> $xmahjonggfile
#  echo "Type=Application" >> $xmahjonggfile
#  echo "Categories=Applications;Game;ENLIGHTENMENT;" >> $xmahjonggfile
#fi

cd /usr/share/pixmaps
wget http://www.kurppa.fi/freerunner/config_files/gwaterpas.png

#Sort icons to folders
echo "Sorting icons to categories">>$infofile

cp /usr/share/applications/ $backupdir/icons -r
opkg install http://projects.openmoko.org/frs/download.php/613/sortdesk_1.2_armv4t.ipk

sortdesk add Games
sortdesk add Net
sortdesk add GPS
sortdesk add Tools
sortdesk add Apps

cd /usr/share/pixmaps/sortdesk
wget http://www.kurppa.fi/freerunner/config_files/sortdesk_icons.tar.gz
tar -zxf sortdesk_icons.tar.gz

cd /usr/share/applications/Home

#games
folder="/home/root/.sortdesk/Games/";
mv ko-dice* $folder 
mv pyefl-sudoku* $folder 
mv xlogical* $folder
mv acceleroids* $folder
mv pong* $folder 
mv numpty* $folder 
mv pipes* $folder 
mv duke3d* $folder 
mv openttd* $folder 
mv mokomaze* $folder
mv linball* $folder
mv openmoocow* $folder 
mv openmiaocat* $folder 

#Net
folder="/home/root/.sortdesk/Net"
mv midori* $folder
mv minimo* $folder
mv openmoko-browser* $folder
mv centerim* $folder
mv dillo* $folder
mv netsurf* $folder

#GPS
folder="/home/root/.sortdesk/GPS"
mv navit* $folder
mv om-locations* $folder
mv openmoko-agps* $folder
mv yaouh* $folder
mv orrery* $folder
mv tangogps* $folder
mv gtkadd* $folder
mv agps* $folder

#Tools
folder="/home/root/.sortdesk/Tools"
mv battery* $folder
mv gwaterpas* $folder
mv perpendi* $folder
mv exposure* $folder
mv AppManager* $folder
mv ledclock* $folder
mv ffalarms* $folder
mv mokoconv* $folder
mv qtopia-calculator* $folder
mv xterm* $folder

#Apps
folder="/home/root/.sortdesk/Apps"
mv fbreader* $folder
mv pypennotes* $folder
mv voicenote* $folder
mv mokox48* $folder
mv mtpaint* $folder
mv fourier* $folder
mv neon* $folder
mv leafpad* $folder
mv guitartune* $folder
mv gtick* $folder
mv pythm* $folder
mv qtopia-textedit* $folder

#Globals - because sortdesk fails..
mv gpsdcontrol* ..
mv meooem* ..
mv mokomode* ..
mv wlan* ..

#left in Home:
# vala-terminal
# phone utils
# assassin
# mokoservices
# qtopia-calendar


############################
# FINISHING
############################

#run custom scripts
customfile="/media/card/customscript"
if [ -e "$customfile" ]
then
  echo "Running your custom script file">>$infofile
  echo " -> Found your custom script file at $customfile, running it now!"
  echo " "
  $customfile
fi

###RESTART
echo "That's all folks!">>$infofile
echo "Enlightenment will crash on the first starts, thats life. Just click 'Recover' and you'll be fine.">>$infofile
echo " Join the kustomizer mailing list by mailing kustomizer+subscribe@googlegroups.com " >>$infofile
echo " Also check the wiki page at http://wiki.openmoko.org/wiki/Kustomizer" >>$infofile
echo " " >>$infofile
echo "Enjoy your freedom!!">>$infofile
echo "!!!! RESTART IN 30s">>$infofile

echo " -> That's all folks!"
echo " -> You can find the installation log file, kustomizer.log in your home directory on Freerunner."
echo " -> Enlightenment will crash on the first starts, thats life. Just click 'Recover' and you'll be fine."
echo " "
echo " Join the kustomizer mailing list by mailing kustomizer+subscribe@googlegroups.com "
echo " Also check the wiki page at http://wiki.openmoko.org/wiki/Kustomizer"
echo " -> Enjoy your freedom!!"
echo " "
echo " "
echo "!!! RESTART IN 30s"
echo " "

sleep 30
shutdown -r now &
dbus-send --system --dest=org.openmoko.Power / org.openmoko.Power.Core.RemoveRequestedResourceState string:cpu string:kustomizer
rm $infofile > /dev/null 2> /dev/null

}
secondstage 2>&1 | tee -a kustomizer.log

