#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi
# no compiler flags IMHO

P=docutils
V=0.14
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc python-setuptools python-dev  "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
http://downloads.sourceforge.net/$P/$P-$V.tar.gz " $USER 
tar xvf $P*gz
cd $P-$V
python setup.py build
touch /tmp/Ztime
python setup.py install
cd /tmp

# dev as no dot.h files use the source pls
#####

# main
#####
SITE=/usr/local/lib/python2.7/site-packages
mkdir -p $P/usr/local/share/doc/$P
mkdir -p $P$SITE
mkdir -p $P/usr/local/bin
mv $SITE/$P $P$SITE/
# copying is complex 
cp $SRC/COPYING.txt $P/usr/local/share/doc/$P/COPYING
mv /usr/local/bin/rst* $P/usr/local/bin/
# ^^ moves 12 executables

# locale
#########
PLANG=$P$SITE/$P/languages
LOC=$P-locale$SITE/$P
mkdir -p $LOC
mv $PLANG $LOC/
# put English back into main
mkdir -p $PLANG
mv $LOC/languages/en* $PLANG/
mv $LOC/languages/*init* $PLANG/
# ^^ moves 2 english and 2 script files

# doc
#####
DOC=/tmp/$P-doc/usr/local/share/doc/$P
mkdir -p $DOC
cd $SRC
cp COPYING.txt $DOC/COPYING
cp FAQ.txt $DOC/
cp README.txt $DOC/
cp THANKS.txt $DOC/
mv docs $DOC/
mv licenses $DOC/
cd /tmp

# TCZ them
#######
LIST="$P $P-doc $P-locale"
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

echo 'docutils.tcz' > $P-locale.tcz.dep

echo 'python.tcz
python-setuptools.tcz ' > $P.tcz.dep

echo 'Title:          docutils.tcz  
Description:    Python documentation utilities
Version:        0.14
Author:         David Goodger  
Original-site:  https://sourceforge.net/projects/docutils/files/
Copying-policy: see COPYING as various
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           python documents 
Comments:       Help build docs for python packages
                            
                Compiled for 64 9.x
Change-log:     2018/04/06  First version 
Current:        2018/04/06 ' > $P.tcz.info

echo 'Title:          docutils-doc.tcz
Description:    docs
Version:        0.14
Author:         David Goodger 
Original-site:  https://sourceforge.net/projects/docutils/files/
Copying-policy: see COPYING as various
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Some docs

                Compiled for 64 9.x
Change-log:     2018/04/06  First version 
Current:        2018/04/06 ' > $P-doc.tcz.info

echo 'Title:          docutils-locale.tcz
Description:    locales
Version:        0.14
Author:         David Goodger 
Original-site:  https://sourceforge.net/projects/docutils/files/
Copying-policy: see COPYING as various
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           python 
Comments:       for non-english users untested
                Note the pathway to the python files pls.

                Compiled for 64 9.x
Change-log:     2018/04/06  First version 
Current:        2018/04/06 ' > $P-locale.tcz.info

submitqc --libs