#!/bin/bash -x

VERSION="0.5"

## Check that we're running as root (or at least as fakeroot)
id=`id -u`
if [ "$id" != "0" ]; then
    echo "Must run as root (or fakeroot)."
    exit 1
fi
umask 002

## Make the tgz
export GZIP=-9
make
arm-linux-strip qcopilot
make dist
mkdir qcopilot-$VERSION
cd qcopilot-$VERSION
tar xzvvf ../qcopilot.tar.gz
cd ..
tar czvvf qcopilot-$VERSION.tgz qcopilot-$VERSION
rm -rf qcopilot.tar.gz qcopilot-$VERSION

## Make the ipk
rm -rf ipk
mkdir ipk
cd ipk
mkdir qcopilot
cd qcopilot
mkdir -p CONTROL usr/bin opt/Qtopia/apps/Applications opt/Qtopia/pics home/root/.qcopilot
cp ../../qcopilot usr/bin/
cp ../../qcopilot.desktop opt/Qtopia/apps/Applications/
cp ../../qcopilot.png opt/Qtopia/pics/
cp ../../case.png home/root/.qcopilot/
cat <<EOF >CONTROL/control
Package: qcopilot
Priority: optional
Version: $VERSION
Architecture: arm
Section: misc
Maintainer: Ian Goldberg <ian@cypherpunks.ca>
Depends: 
Description: A Palm Pilot (old hardware) emulator for the Zaurus
EOF
cd ..
ipkg-build qcopilot ..
cd ..
rm -rf ipk

## Make the README.html
echo "<pre>" > README.html
perl -pe 's/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g;' README >> README.html
echo "</pre>" >> README.html
