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

# no compiler flags IMHO

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

# may not be needed it ensures any found are all arandr
rm -rf /usr/local/share/locale

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
http://christian.amsuess.com/tools/$P/files/$P-$V.tar.gz " $USER 
tar xvf $P*gz
cd $SRC
python setup.py build
touch /tmp/Ztime
python setup.py install
cd /tmp

# main
######
SCREEN=/usr/local/lib/python2.7/site-packages/screenlayout
mkdir -p $P/usr/local/share/doc/$P
mkdir -p $P/usr/local/lib/python2.7/site-packages
mkdir -p $P/usr/local/bin
mv $SCREEN $P/usr/local/lib/python2.7/site-packages/
mv /usr/local/bin/arandr $P/usr/local/bin/
mv /usr/local/bin/unxrandr $P/usr/local/bin/
echo 'see doc tcz for license' > $P/usr/local/share/doc/$P/COPYING

# desktop
#########
DESK=/usr/local/share/applications
mkdir -p $P$DESK
mv $DESK/$P.desktop $P$DESK/
echo 'X-FullPathIcon=/usr/local/share/icons/Adwaita/48x48/devices/video-display.png
' >> $P$DESK/$P.desktop

# locale
#########
LOC=/usr/local/share/locale
mkdir -p $P-locale/usr/local/share
mv $LOC $P-locale/usr/local/share/

# doc
#####
MAN=/tmp/$P-doc/usr/local/share/man/man1
mkdir -p $P-doc/usr/local/share/doc/$P
mkdir -p $MAN
cd $SRC/data
# man pages did not display correctly from gz files so
# use the basic data txt files instead
cp arandr.1.txt $MAN/arandr.1
cp unxrandr.1.txt $MAN/unxrandr.1
cd /tmp
cp $SRC/README $P-doc/usr/local/share/doc/$P
cp $SRC/COPYING $P-doc/usr/local/share/doc/$P

# dev...no .h use src pls
#####

# 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 'arandr.tcz' > $P-locale.tcz.dep

echo 'arandr.tcz
docutils.tcz 
pygtk-dev.tcz
intltool.tcz ' > $P-dev.tcz.dep

echo 'adwaita-icon-theme.tcz
python.tcz 
pygtk.tcz > $P.tcz.dep

echo 'Title:          arandr.tcz  
Description:    Front end to libXrandr
Version:        0.1.9
Author:         see doc for authors  
Original-site:  http://christian.amsuess.com/tools/arandr/#project
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xrandr libxrandr 
Comments:       a(nother)(x)randr, monitor resolutions app

                Steps
                #####
                Run a window manager with Xorg please.

                $ tce-load -i arandr
                wbar -> arandr or $ arandr
                GUI should show < name of connection >,
                -------I see HDMI-2, but I am on DVI cable.
                other choices for me, DP-1 and other HDMIs

                Ouputs -> < name of your connection>
                -> Resolution -> Choice your numbers eg 800x600 
                -> Click the Apply button 
                (expect Monitor to go black for a couple of seconds)
                And then new resolution should occur
               
                If instead of size you wish to rotate, instead of 
                Resolution choose Orientation. On my PC, 
                rotate left...rotates clockwise and no need 
                to click apply for rotation.

                I am unable to test 2 monitors and Primary was
                unticked. YMMV
                
                Compiled for 64 9.x
Change-log:     2018/04/05  First version 
Current:        2018/04/05 ' > $P.tcz.info

echo 'Title:          arandr-doc.tcz
Description:    docs
Version:        0.1.9
Author:         see doc for authors 
Original-site:  http://christian.amsuess.com/tools/arandr/#project
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Some docs
                man pages may display poorly, may need
                utf-8 terminal?

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

echo 'Title:          arandr-locale.tcz
Description:    locales
Version:        0.1.9
Author:         see doc for authors 
Original-site:  http://christian.amsuess.com/tools/arandr/#project
Copying-policy: GPL v3
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       for non-english users untested

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

submitqc --libs