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

CFLAGS="-march=i486 -mtune=i686 -Os -pipe   " 
CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti  "
echo $CFLAGS && echo $CXXFLAGS

P=arandr
V=0.1.11
SRC=$P-$V

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

# list may be larger than loaded
cd /usr/local/lib
rm -rf *.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcp1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/plugin/libcc1plugin.la
rm -rf gcc/i486-pc-linux-gnu/12.2.0/liblto_plugin.la
cd /tmp
rm -rf /usr/lib/*.la
find / -name *.la

su -c "/usr/local/bin/wget -nc --no-check-certificate \
http://christian.amsuess.com/tools/$P/files/$SRC.tar.gz " $USER 
tar xvf $SRC*gz
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
###### 
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:     2023/08/24 v 0.1.11 on 14x 
Current:        2023/08/24    ' > $P-locale.tcz.info
echo 'arandr.tcz' > $P-locale.tcz.dep

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:       python3.6 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 which 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 output of
                Gdk-CRITICAL...gdk_atom_intern: assertion      
                
Change-log:     2023/08/24 v 0.1.11 on 14x 
Current:        2023/08/24  " > $P.tcz.info

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

