#!/bin/sh

[ `id -u` != 0 ] && { echo "Must be root"; exit 1; }

PACKAGE="inxi"
ME="Kingdomcome"

TCUSER=`cat /etc/sysconfig/tcuser`
THISDIR=`pwd`
PKGDIR=${THISDIR}/${PACKAGE}

BUILDDEPS="squashfs-tools-4.0.tcz bash.tcz gawk.tcz pci-utils.tcz"
for dep in ${BUILDDEPS}; do
   sudo -u ${TCUSER} tce-load -w -i $dep
done

[ -d ${PKGDIR} ] && rm -rf ${PKGDIR}/*

mkdir -p ${PKGDIR}/tmp/usr/local/bin
cd ${PKGDIR}/tmp/usr/local/bin/
wget http://smxi.org/${PACKAGE} && chmod +x ${PACKAGE} || exit 1

VERSION=`${PKGDIR}/tmp/usr/local/bin/inxi -V | awk '/Version/ {print $2}'`

########## error message suppression ##########
sed -i '/non X/d' ${PACKAGE}
###############################################

cd ${PKGDIR}/tmp/
mkdir -pm 775 usr/local/tce.installed
cat <<EOF> usr/local/tce.installed/inxi
#!/bin/sh

busybox cp -p /tmp/tcloop/inxi/usr/local/bin/inxi /usr/local/bin
EOF
chmod 775 usr/local/tce.installed/inxi
chown -R root:staff usr/local/tce.installed

find usr/ -not -type d > ../${PACKAGE}.tcz.list
mksquashfs ./ ../${PACKAGE}.tcz

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

cat <<EOF> ${PACKAGE}.tcz.dep
bash.tcz
coreutils.tcz
gawk.tcz
grep.tcz
pci-utils.tcz
procps.tcz
EOF

size=`du -h ${PACKAGE}.tcz | cut -f1`
today=`date +%Y/%m/%d`
cat <<EOF> ${PACKAGE}.tcz.info
Title:		${PACKAGE}.tcz
Description:	Universal, portable system info script
Version:	${VERSION}
Author:		Michiel de Boer, Scott Rogers, & Herald Hope
Original-site:	http://www.inxi.org
Copying-policy:	GPLv3
Size:		${size}
Extension_by:	${ME}
Comments:	Commonly used in IRC, also can be run from CLI
		inxi -h will show possible switches to use for different outputs
		Modified to suppress error message for those using TinyX.
		Depends on bash, coreutils, gawk, pci-utils, and procps
		
		This extension uses recursive deps
		This extension is PPI compatible
Change-log:	2009/07/21 First Version
		2009/08/22 Bumped to 1.1.13
		2009/10/12 Bumped to 1.1.14
		2009/11/29 Bumped to 1.2.7
		2010/01/04 Bumped to 1.2.8
		2010/02/15 Bumped to 1.4.4
		2010/02/22 Bumped to 1.4.6
		2010/04/04 Bumped to 1.4.8
Current:	${today} Bumped to ${VERSION}
EOF

# 2009/07/21 First Version
# 2009/08/22 Bumped to 1.1.13
# 2009/10/12 Bumped to 1.1.14
# 2009/11/29 Bumped to 1.2.7
# 2010/01/04 Bumped to 1.2.8
# 2010/02/15 Bumped to 1.4.4
# 2010/02/22 Bumped to 1.4.6
# 2010/04/04 Bumped to 1.4.8, convert to recursive dep
# 2010/06/22 Bumped to 1.4.10
