#!/bin/sh



if [ ! -d /mnt/cf ]; then
    echo "creating directory /mnt/cf"
    mkdir /mnt/cf
fi

if [ ! -d /mnt/pebble ]; then
    echo "creating directoty /mnt/pebble"
    mkdir /mnt/pebble
fi

# this stuff is too dangerous to do here
# I'll assume it has already been done.

#    fdisk /dev/hde
#    mke2fs /dev/hde1

echo "mounting /dev/sda1 to /mnt/cf"
mount /dev/sda1 /mnt/cf

if [ $? != 0 ]; then
    echo "mount failed, exiting"
    exit
fi

if [ ! -f ts_pebble-0.2.bz2 ]; then
    echo "using wget to download ts_pebble tree"
    wget www.embeddedx86.com/downloads/Linux/pebble/ts_pebble-0.2.bz2
    tar xjfv ts_pebble-0.2.bz2
fi

cd pebble

if [ ! -f pebble.v41.tar.bz2 ]; then
    echo "using wget to download pebble"
    wget www.nycwireless.net/pebble/pebble.v41.tar.bz2
    tar --numeric-owner -jxvf pebble.v41.tar.bz2
fi

echo "copying ts_pebble tree over default pebble tree"
cp -dpRv /mnt/ts/* /mnt/pebble

echo "removing /mnt/cf/pebble.v41.tar.bz2"
rm /mnt/cf/pebble.v41.tar.bz2

echo "unmounting compact flash /dev/sda1"
umount /dev/sda1

echo "running pebble update to get latest changes"
./pebble.update

echo "unmounting compact flash /dev/sda1 in case pebble.update didn't finish"
umount /dev/sda1