#!/bin/sh
# Get kernel from 20090404 (tested and proved ok):
# http://www.e-dynamics.be/openmoko/uImage-2.6.28-andy-tracking+gitr6+9c4451ff31b937a478f3d3eabef30b71cbe12b12-r3-om-gta02.bin
# http://www.e-dynamics.be/openmoko/fso-image-nox-om-gta02.jffs2
# http://www.e-dynamics.be/openmoko/modules-2.6.28-andy-tracking+gitr6+9c4451ff31b937a478f3d3eabef30b71cbe12b12-r3-om-gta02.tgz

# OR

# get kernel and rootfs from (tested but older kernel):
# http://downloads.freesmartphone.org/fso-stable/milestone5.1/om-gta02/
# download fso-console-image-om-gta02.jffs2
# and uImage-2.6.28-oe1+gitr34240a1c06ae36180dee695aa25bbae869b2aa26-r3-om-gta02.bin

#
# ./dfu-util -a kernel -R -D  uImage-2.6.28-...
# ./dfu-util -a rootfs -R -D fso-image-...
#
# after that reboot twice (first to let the new kernel boot and create
# all devices, second time you will have usb)

VERSION=20090601
DOWNLOAD_NAME=qte_20090601.tgz

download_install() {
   # remove and recreate the qtopia dir
   rm -rf /opt/Trolltech/Qtopia >/dev/null 2>&1
   mkdir -p /opt/Trolltech/Qtopia >/dev/null 2>&1
   cd /opt/Trolltech/Qtopia

   # get the files
   wget http://www.e-dynamics.be/openmoko/$DOWNLOAD_NAME
   # unzip, install
   gzip -dc $DOWNLOAD_NAME|tar xvf -
   rm $DOWNLOAD_NAME

   # better alarm
   cd /opt/Trolltech/Qtopia/etc/SystemRingTones/
   mv alarm.wav alarm.wav.orig
   wget http://www.e-dynamics.be/openmoko/alarm.wav
}

help() {
   echo "Download version is: $VERSION"
   echo use "Either \"$0 install\" or \"$0 update\""
}

if [ "$1" = "update" ]; then
   download_install
   exit
fi

if [ "$1" != "install" ]; then
   help
   exit
fi

# we're here, so we install, not update
download_install

# Launch at boot
cp /opt/Trolltech/Qtopia/qpe.sh /etc/init.d
chmod 755 /etc/init.d/qpe.sh
cd /etc/rc5.d
ln -s ../init.d/qpe.sh S98qpe.sh
# if shr, we remove the xserver config
/bin/rm /etc/rc5.d/S05xserver-nodm

cd /home/root
# get working asound.conf for voicenotes
wget http://www.e-dynamics.be/openmoko/asound.conf
cp asound.conf /etc
rm asound.conf
#cd /usr/share/openmoko/scenarios; cp capturehandset.state capturehandset.state.orig; cp voip-handset.state capturehandset.state

# do we need avahi???
#mv S21avahi-daemon _S21avahi-daemon

# Do something about eth0, at unsuspend it can't be dhcp by default, otherwise
# the wireless lan always becomes active
cd /etc/network
cp interfaces interfaces.orig
cat interfaces.orig |sed "s/iface eth0 inet dhcp/iface eth0 inet manual/" >interfaces

# if the console image is used, some fso stuff needs to be disabled
opkg remove -recursive frameworkd
#mv S35fso-monitord _S35fso-monitord
#mv S35fso-gpsd _S35fso-gpsd
#mv S29frameworkd _S29frameworkd

# remove non existent feed
rm /etc/opkg/armv4-feed.conf

opkg update
# bluetooth daemon needs to be downgraded to bluez3
##opkg install hal
opkg remove -recursive bluez4
#opkg install bluez-audio
#opkg install bluez-utils
#opkg install bluez-utils-alsa
#opkg install bluez-utils-compat
#opkg install libopenobex1
### the bluetooth init script needs to be changed
### replace DAEMON_NAME=bluetoothd with DAEMON_NAME=hcid
#echo "check that DAEMON_NAME=hcid in /etc/init.d/bluetooth"
# also the poweron/off scripts get a lift
#cd /opt/Trolltech/Qtopia/bin
#mv bt-poweron.sh bt-poweron.sh.orig
#mv bt-poweroff.sh bt-poweroff.sh.orig
#wget http://www.e-dynamics.be/openmoko/bt-poweron.sh
#wget http://www.e-dynamics.be/openmoko/bt-poweroff.sh
#chmod 755 bt-poweron.sh bt-poweroff.sh
# and the dbus config
#cd /etc/dbus-1/system.d/
#mv bluetooth.conf bluetooth.conf.orig
#wget http://www.e-dynamics.be/openmoko/bluetooth.conf

# for qmplayer, it can do this itself as well, but since we're installing anyway
cd /home/root
wget http://www.e-dynamics.be/openmoko/mplayer-glamo.conf
mkdir .mplayer >/dev/null 2>&1
cp mplayer-glamo.conf .mplayer/config
rm mplayer-glamo.conf
wget http://activationrecord.net/radekp/qmplayer/download/mplayer
cp mplayer /usr/bin
chmod 755 /usr/bin/mplayer
rm mplayer

# if the MS5.1 version is used, libts and libstdc++ are not installed
# for others: it doesn't hurt
opkg install libts-1.0-0
opkg install libstdc++6

# atd needed for alarms
# maybe we should use atd from the qtopia distro (rtc based), more lightweight
# that one can be compiled using:
# export QTOPIA_DEPOT_PATH=/opt/QtExtended/qt-extended-improved
# export QPEDIR=/opt/QtExtended/build/
# export PATH=/opt/toolchains/arm920t-eabi/bin/:$QPEDIR/bin:$PATH
# cd /opt/QtExtended/qt-extended-improved/src/3rdparty/tools/atd/
# /opt/QtExtended/build/bin/qbuild
# result is in /opt/QtExtended/build/src/3rdparty/tools/atd/
# copy it, use init script and done
cd /home/root
wget http://www.e-dynamics.be/openmoko/atd_0.70-r4_armv4t.ipk
# some have own versions, but have issues ..., so we remove the opkg cache
/bin/rm /var/lib/opkg/*
opkg install atd_0.70-r4_armv4t.ipk
rm atd_0.70-r4_armv4t.ipk

#reboot

# List of issues:
# See http://www.e-dynamics.be/openmoko/qt-issues.txt
