#!/bin/sh

. /etc/init.d/tc-functions

checkroot

export CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti"
export CPPFLAGS="-I/usr/local/include"
export LDFLAGS="-L/usr/local/lib"
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig

TODAY=`date +%Y/%m/%d`
PACKAGE="pidgin-tray-icons-humanity"
#SEP="-"
VERSION="0.3"
MIRROR="http://gnome-look.org/CONTENT/content-files/"
DESCRIPTION="humanity tray icons for pidgin"
ME="jls_legalize (unsenepopiu at tin dot it)"
AUTHORS="rowancompsci guy"
HOMEPAGE="http://gnome-look.org/content/show.php/Pidgin+Tray+Icons?content=119879"
LICENSE="GPL"
DEPS="pidgin.tcz"
BUILDDEPS="squashfs-tools-4.0.tcz"
FLAGS=""
TCUSER=`cat /etc/sysconfig/tcuser`
SRC="119879-Pidgin%20Tray%20Icons.tar.gz"
THISDIR=`pwd`
PKGDIR="${THISDIR}/${PACKAGE}"
SRCDIR="Pidgin Tray Icons"
TCEDIR="$(cat /opt/.tce_dir)"

clean(){
	rm -rf ${THISDIR}/${PACKAGE}
}
environment(){
	for each in ${DEPS} ${BUILDDEPS}; do
		APPNAME=$(getbasefile "$each" 1)
		if [ ! -f /usr/local/tce.installed/"${APPNAME}" ]; then
			if [ ! -e ${TCEDIR}/optional/${each} ]; then
				sudo -u ${TCUSER} tce-load -w ${each}
			fi
			sudo -u ${TCUSER} tce-load -i ${TCEDIR}/optional/${each}
		fi
	done
	[ -d "${PKGDIR}" ] && rm -rf ${PKGDIR}
	mkdir -p ${PKGDIR}/tmp
	cd ${PKGDIR} && wget "${MIRROR}${SRC}"
	tar xzf "${SRC}"
}

workit(){
	cd ${PKGDIR}/tmp
	mkdir -p usr/local/share/pixmaps/pidgin/tray/
	cp -a ../"${SRCDIR}"/humanity/* usr/local/share/pixmaps/pidgin/tray/
}

packageit(){
   cd ${PKGDIR}/tmp
   for dir in `ls -A`; do
      find ${dir} -not -type d | sort >> ../${PACKAGE}.tcz.list
   done

   mksquashfs . ../${PACKAGE}.tcz

   cd ${PKGDIR}
   md5sum ${PACKAGE}.tcz > ${PACKAGE}.tcz.md5.txt

   for each in ${DEPS}; do echo ${each} >> ${PACKAGE}.tcz.dep; done

   size=`du -h ${PACKAGE}.tcz | cut -f 1`

cat <<EOF> ${PACKAGE}.tcz.info
Title:		${PACKAGE}.tcz
Description:	${DESCRIPTION}
Version:		${VERSION}
Author:		${AUTHORS}
Original-site:	${HOMEPAGE}
Copying-policy:${LICENSE}
Size:		${size}
Extension_by:	${ME}
Comments:
			This extension is PPI compatible.
Change-log:	----
Current:		${TODAY} First version 
EOF
}
tarit(){	
	cd ${PKGDIR}
	tar cvf ../${PACKAGE}.tar ${PACKAGE}.tcz* ../${PACKAGE}.tcbuild
}
#here we go
clean
environment
workit
packageit
tarit