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

export CFLAGS="-mtune=generic -Os -pipe"
export CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe "


# v 2.8.5 wget has a read error so getting slightly older version
# wget failed too but used firefox to get it
P=man-db
V=2.8.4
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc xz libtool intltool libpipeline-dev \
gdbm-dev groff db-dev "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc \
#####see above \
http://ftp.yzu.edu.tw/nongnu/$P/$SRC.tar.xz " $USER
mkdir $P
xz -d $SRC*xz && tar xvf $SRC*tar
cd $SRC
./configure --disable-automatic-update --disable-setuid
make -j5
make install-strip DESTDIR=/tmp/$P
cd /tmp

# locale
#########
mkdir -p $P-locale/usr/local/share/man
mv $P/usr/local/share/locale $P-locale/usr/local/share/
mv $P/usr/local/share/man/it $P-locale/usr/local/share/man/

# doc
#####
mkdir -p $P-doc/usr/local/share/doc/$P
cp $SRC/docs/COPYING $P-doc/usr/local/share/doc/$P
mv $P/usr/local/share/doc/$P/*ps $P-doc/usr/local/share/doc/$P/
mv $P/usr/local/share/doc/$P/*txt $P-doc/usr/local/share/doc/$P/
mv $P/usr/local/share/man $P-doc/usr/local/share/
cp $SRC/README $P-doc/usr/local/share/doc/$P

# the readme shows colin watson as last author

# no dev
#####

# 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

ls -hal

echo 'man-db.tcz ' > $P-locale.tcz.dep
echo 'man-db.tcz ' > $P-doc.tcz.dep
echo 'gdbm.tcz
libpipeline.tcz
groff.tcz 
less.tcz ' > $P.tcz.dep

echo 'Title:          man-db.tcz
Description:    terminal software mainly to read man pages 
Version:        2.8.4
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v2
Size:           260K
Extension_by:   aus9 at gmx dot com
Tags:           man-db man
Comments:       terminal software to read man pages eg
                $ man <man-page-name>
 
                WARNING setting setuid for user=man has not been compiled so 
                $ mandb -t (and some others) will fail. Most people will only
                want to read man pages and not create them here. IMHO
               
                Compiled for 10.x
Change-log:     2015/07/07 First version (gordon64)
                2018/0/08 2.7.1 -> 2.8.2 (aus9)
Current:        2019/01/08 2.8.2 -> 2.8.4  ' > $P.tcz.info

echo 'Title:          man-db-doc.tcz
Description:    docs
Version:        2.8.5
Author:         Colin Watson
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v2
Size:           132K
Extension_by:   aus9 at gmx dot com
Tags:           man-db man
Comments:       Some docs

                Compiled for 10.x
Change-log:     2015/07/07 First version (gordon64)
                2018/0/08 2.7.1 -> 2.8.2 (aus9)
Current:        2019/01/08 2.8.2 -> 2.8.4  '  > $P-doc.tcz.info

echo 'Title:          man-db-locale.tcz
Description:    locales
Version:        2.8.5
Author:         Colin Watson 
Original-site:  http://savannah.nongnu.org/projects/man-db
Copying-policy: GPL v2
Size:           264K		
Extension_by:   aus9 at gmx dot com
Tags:           locale man-db man 
Comments:       for non-english users untested.
                Contains Italian man pages

                Compiled for 10.x
Change-log:     2015/07/07 First version (gordon64)
                2018/0/08 2.7.1 -> 2.8.2 (aus9)
Current:        2019/01/08 2.8.2 -> 2.8.4  '  > $P-locale.tcz.info

submitqc --libs
