#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe  -fno-exceptions -fno-rtti"

P=setconf
V=0.7.7
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc python3.9-setuptools "
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 \
https://github.com/xyproto/$P/archive/refs/tags/$V.tar.gz   "  $USER
tar xvf $V*gz
cd $SRC
sed 's|2.7|3.9|' -i .travis.yml
sed 's|python|python3.9|' -i setconf.py
python3.9 setup.py install --prefix=/usr/local --root=/tmp/$P
cd /tmp

# doc
##########
mkdir -p $P-doc/usr/local/share/man/man1
mv $SRC/$P.1 $P-doc/usr/local/share/man/man1
gzip $P-doc/usr/local/share/man/man1/*

# main
#####
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $P/usr/local/share/doc/$P/COPYING

# submit finds wrong 755 permission
chmod 755 $P/usr/local/lib/python3.9/site-packages/setconf.py

# TCZ them
###########
LIST2="$P $P-doc "
for Z in $LIST2
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 'Title:          setconf-doc.tcz
Description:    man page 
Version:        0.7.7
Author:         Alexander F. Rødseth
Original-site:  https://github.com/xyproto/setconf
Copying-policy: GPL v2 
Size:           4.0K          		
Extension_by:   aus9 @linuxquestions.org  
Tags:           config 
Comments:       man page
                     
Change-log:     2024/08/01 v 0.7.7 on 15x
Current:        2024/08/01     ' > $P-doc.tcz.info
echo 'man-db.tcz      ' > $P-doc.tcz.dep

cat >> $P.tcz.info <<'EOF'
Title:          setconf.tcz
Description:    changing settings in config text files 
Version:        0.7.7
Author:         Alexander F. Rødseth
Original-site:  https://github.com/xyproto/setconf
Copying-policy: GPL v2 
Size:           24K          		
Extension_by:   aus9 @linuxquestions.org  
Tags:           config 
Comments:       Replacement for most sed replacements
                to alter config files, Makefile, headers and such
                
                old= sed 's|key=oldvalue|key=value|g' -i filename
                new= setconf filename key value

                sed still better if order of lines is important such as
                headers that need #include <limits.h> (before another line)
                More examples in man page
                     
Change-log:     2024/08/01 v 0.7.7 on 15x
Current:        2024/08/01     
EOF

echo 'python3.9.tcz      ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

