#!/bin/sh
#
######################################################
# Build script for TinyCore 3.x                      #
#                                                    #
# See .info for details                              #
#                                                    #
# June 25, 2010                                      #
######################################################

######################################################
# Configure extension creation parameters            #
######################################################

SRCNAM=thunderbird-6.0.2.tar.bz2
WRKDIR=thunderbird
EXTNAM=thunderbird
TMPDIR=/tmp/thunderbird

######################################################
# Prepare extension creation                         #
######################################################

# Remove dirs and files left from previous creation

rm -r -f $WRKDIR

rm -r -f $TMPDIR

# Unpack source in current directory

tar -xf $SRCNAM


# Crete temporary directory

mkdir -p $TMPDIR/usr/local
cp -r -f $WRKDIR $TMPDIR/usr/local

# Delete source directory

rm -r -f $WRKDIR

# Add TC specific files

mkdir -p $TMPDIR/usr/local/share/applications
mkdir -p $TMPDIR/usr/local/share/pixmaps
mkdir -p $TMPDIR/usr/local/tce.installed

cp *.desktop $TMPDIR/usr/local/share/applications
cp *.png $TMPDIR/usr/local/share/pixmaps
cp $EXTNAM.ins $TMPDIR/usr/local/tce.installed/$EXTNAM

# Adjust access rigths

find $TMPDIR/ -type d | xargs chmod -v 755;

chmod -R 775 $TMPDIR/usr/local/tce.installed/
chown -R tc.staff $TMPDIR/usr/local/tce.installed/

# Strip executables

find $TMPDIR | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded

###################################################
# Create base extension in temp dir               #
###################################################

cd $TMPDIR
cd ..
mksquashfs $TMPDIR $EXTNAM.tcz
cd $TMPDIR
find usr -not -type d > $EXTNAM.tcz.list
mv ../$EXTNAM.tcz .

# Create md5 file

md5sum $EXTNAM.tcz > $EXTNAM.tcz.md5.txt

# Cleanup temp directory

rm -r -f usr
