#!/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 CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=arandr
V=0.1.11
SRC=git-20230427

# src changelog Note dependency on cairo

USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc git python3.6 python3.6-docutils-locale py3.6cairo-dev gettext "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "git clone https://gitlab.com/$P/$P " $USER 
mv $P $SRC
cd $SRC
python3.6 setup.py install --prefix=/usr/local --root=/tmp/$P
cd /tmp

# locale
#########
LOC=usr/local/share/locale
mkdir -p $P-locale/$LOC
mv $P/$LOC $P-locale/usr/local/share/
# note no locale-man-pages are created so doc not all that useful

# no doc
#####
rm -rf $P/usr/local/share/man 

# main
###### 
# desktop
#########
DESK=$P/usr/local/share/applications/$P.desktop
sed 's|display|preferences-desktop-display|' -i $DESK
sed 's|HardwareSettings;|System;Utility;|' -i $DESK
echo 'X-FullPathIcon=/usr/local/share/icons/Adwaita/48x48/legacy/preferences-desktop-display.png' >> $DESK

mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v3' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
#######
LIST="$P $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 'Title:          arandr-locale.tcz
Description:    locales
Version:        0.1.11
Author:         chrysn 
Original-site:  http://christian.amsuess.com/tools/arandr/#project
Copying-policy: GPL v3
Size:           76K
Extension_by:   aus9 
Tags:           xrandr monitor screen graphics 
Comments:       localed untested by me

Change-log:     2018/04/05 v 0.1.9 on 9x used python2.7
                2020/08/01 v 0.1.10 on 11x used python3.6
Current:        2023/04/27 v 0.1.11 on 14x    ' > $P-locale.tcz.info

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

cat >> $P.tcz.info <<'EOF'
echo "Title:          arandr.tcz  
Description:    Front end to libXrandr
Version:        0.1.11
Author:         chrysn 
Original-site:  http://christian.amsuess.com/tools/arandr/#project
Copying-policy: GPL v3
Size:           68K
Extension_by:   aus9 
Tags:           xrandr monitor screen graphics
Comments:       monitor resolution app
                MUST be on Xorg (2d or 3d). 
                Click Outputs for your active HDMI* DVI* etc 
                -> Resolution -> Choose your preference  
                -> Click the Tick button  
                I am unable to test 2 monitors.
                
                If you wish to save new setting -> Click the 
                download icon and choose a filename (example) 1920
                .sh is added and creates $HOME/.screenlayout/1920.sh 
                after you press the save button or press enter
                
                To automate it -> (change below to your filename please)
                echo '$HOME/.screenlayout/1920.sh &' > $HOME/.X.d/monitor
                
                To test without reboot, exit to prompt and run $ startx 
                If unhappy, delete $HOME/.X.d/monitor 

                It is safe to ignore any terminal output of
                "Gdk-CRITICAL...gdk_atom_intern: assertion"      
                
Change-log:     2018/04/05 v 0.1.9 on 9x used python2.7
                2020/08/01 v 0.1.10 on 11x used python3.6
Current:        2023/04/27 v 0.1.11 on 14x
EOF

echo 'python3.6.tcz
py3.6gobject.tcz
gtk3-gir.tcz
adwaita-icon-theme.tcz    ' > $P.tcz.dep

submitqc --libs
