# Variables
TODAY=`date +%Y/%m/%d`
PACKAGE="XML-NamespaceSupport"
VERSION="1.12"
DESCRIPTION="simple generic namespace processor"
AUTHORS="Robin Berjon"
HOMEPAGE="http://search.cpan.org/~perigrin/XML-NamespaceSupport-1.12/lib/XML/NamespaceSupport.pm"
LICENSE="See Original-site"
ME="rhermsen"
DESTDIR=/tmp/dest/${PACKAGE}
TMPDIR=/tmp/submit/${PACKAGE}

# Workdir
sudo rm -r /tmp/${PACKAGE}
mkdir /tmp/${PACKAGE}
cd /tmp/${PACKAGE}

# Source
wget http://search.cpan.org/CPAN/authors/id/P/PE/PERIGRIN/XML-NamespaceSupport-1.12.tar.gz

tar xf /tmp/${PACKAGE}/${PACKAGE}-${VERSION}.tar.gz
cd /tmp/${PACKAGE}/${PACKAGE}-${VERSION}

perl Makefile.PL
find . -name Makefile -type f -exec sed -i 's/-O2//g' {} \;
make
sudo rm -r ${DESTDIR}
mkdir -p  ${DESTDIR}
make DESTDIR=${DESTDIR} install

sudo rm -r ${TMPDIR}*
#mkdir -p  ${TMPDIR}/usr/local/lib/perl5/5.24.0/i486-linux/
mkdir -p  ${TMPDIR}/usr/local/lib/perl5/site_perl/5.24.0/XML/
#mkdir -p  ${TMPDIR}/usr/local/lib/perl5/site_perl/5.24.0/i486-linux/auto/XML/

#mv ${DESTDIR}/usr/local/lib/perl5/5.24.0/i486-linux/* ${TMPDIR}/usr/local/lib/perl5/5.24.0/i486-linux/
mv ${DESTDIR}/usr/local/lib/perl5/site_perl/5.24.0/XML/* ${TMPDIR}/usr/local/lib/perl5/site_perl/5.24.0/XML/
#mv ${DESTDIR}/usr/local/lib/perl5/site_perl/5.24.0/i486-linux/auto/XML/ ${TMPDIR}/usr/local/lib/perl5/site_perl/5.24.0/i486-linux/auto/XML/

cd /tmp/submit/
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:       XML::NamespaceSupport
                This module offers a simple way to process namespaced XML names
                (unames) from within any application that may need them. It
                also helps maintain a prefix to namespace URI map, and provides
                a number of basic checks.
                The model for this module is SAX2's NamespaceSupport class,
                readable at
                http://www.saxproject.org/namespaces.html
                It adds a few perlisations where we thought it appropriate, and supports
                the Namespaces in XML 1.1 specification.
                
                This extension is PPI compatible
Change-log:     ${TODAY} First Version, 1.12
Current:        ${TODAY} First Version, 1.12
EOF

mkdir -p  ${TMPDIR}-doc/usr/local/share/man/man3/
mv ${DESTDIR}/usr/local/share/man/man3/* ${TMPDIR}-doc/usr/local/share/man/man3/

cd /tmp/submit/
sudo cat <<EOF> ${PACKAGE}-doc.tcz.info
Title:          ${PACKAGE}-doc.tcz
Description:    ${DESCRIPTION}
Version:        ${VERSION}
Author:         ${AUTHORS}
Original-site:  ${HOMEPAGE}
Copying-policy: ${LICENSE}
Size:           ${size}
Extension_by:   ${ME}
Comments:       XML::NamespaceSupport
                This module offers a simple way to process namespaced XML names
                (unames) from within any application that may need them. It
                also helps maintain a prefix to namespace URI map, and provides
                a number of basic checks.
                The model for this module is SAX2's NamespaceSupport class,
                readable at
                http://www.saxproject.org/namespaces.html
                It adds a few perlisations where we thought it appropriate, and supports
                the Namespaces in XML 1.1 specification.
                
                This extension is PPI compatible
Change-log:     ${TODAY} First Version, 1.12
Current:        ${TODAY} First Version, 1.12
EOF

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

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

cd $TMPDIR
find $TMPDIR -perm 777 -exec chmod 755 {} \;
find $TMPDIR -perm 555 -exec chmod 755 {} \;
find $TMPDIR -perm 444 -exec chmod 644 {} \;
find $TMPDIR -perm 666 -exec chmod 644 {} \;
find $TMPDIR -perm 664 -exec chmod 644 {} \;
sudo chown -R root:root $TMPDIR

cd /tmp/submit/

mksquashfs $TMPDIR ${PACKAGE}.tcz

cd $TMPDIR
sudo sh -c "find usr -not -type d > ${PACKAGE}.tcz.list"
sudo mv ../${PACKAGE}.tcz .
sudo mv ../${PACKAGE}.tcz.info .

# Create md5 file

sudo sh -c "md5sum ${PACKAGE}.tcz > ${PACKAGE}.tcz.md5.txt"

# Cleanup temp directory

sudo rm -r -f usr

# create documentation extension

cd $TMPDIR-doc
find $TMPDIR-doc -perm 777 -exec chmod 755 {} \;
find $TMPDIR-doc -perm 555 -exec chmod 755 {} \;
find $TMPDIR-doc -perm 444 -exec chmod 644 {} \;
find $TMPDIR-doc -perm 666 -exec chmod 644 {} \;
find $TMPDIR-doc -perm 664 -exec chmod 644 {} \;
sudo chown -R root:root $TMPDIR-doc

cd /tmp/submit/

mksquashfs $TMPDIR-doc ${PACKAGE}-doc.tcz

cd $TMPDIR-doc
sudo sh -c "find usr -not -type d > ${PACKAGE}-doc.tcz.list"
sudo mv ../${PACKAGE}-doc.tcz .
sudo mv ../${PACKAGE}-doc.tcz.info .

# Create md5 file

sudo sh -c "md5sum ${PACKAGE}-doc.tcz > ${PACKAGE}-doc.tcz.md5.txt"

# Cleanup temp directory

sudo rm -r -f usr

