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

# do not load any locales or man pages please

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe"
export LDFLAGS="-Wl,-O1"

P=arandr
V=0.1.10
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc python3.6 python3.6-docutils-locale gettext "
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 \
http://christian.amsuess.com/tools/$P/files/$SRC.tar.gz " $USER 
tar xvf $SRC*gz
cd $SRC
python3.6 setup.py build
python3.6 setup.py install
cd /tmp

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

# doc
#####
mkdir -p $P-doc/usr/local/share/doc/$P
mv /usr/local/share/man $P-doc/usr/local/share
cp $SRC/COPYING $P-doc/usr/local/share/doc/$P

# main
######  /usr/local/lib/python3.6/site-packages/arandr-0.1.10-py3.6.egg-info
SCREEN=usr/local/lib/python3.6/site-packages
mkdir -p $P/usr/local/share/doc/$P
mkdir -p $P/usr/local/lib/python3.6/site-packages
mkdir -p $P/usr/local/bin
mv /$SCREEN/screenlayout $P/$SCREEN
mv /usr/local/bin/arandr $P/usr/local/bin/
mv /usr/local/bin/unxrandr $P/usr/local/bin/
echo 'see doc tcz for COPYING' > $P/usr/local/share/doc/$P/COPYING
EGG=/usr/local/lib/python3.6/site-packages/arandr-0.1.10-py3.6.egg-info
mv $EGG $P/usr/local/lib/python3.6/site-packages

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

# 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 'Title:          arandr-doc.tcz
Description:    docs
Version:        0.1.10
Author:         chrysn 
Original-site:  http://christian.amsuess.com/tools/arandr/#project
Copying-policy: GPL v3
Size:           20K
Extension_by:   aus9 
Tags:           xrandr
Comments:       Some docs
                
Change-log:     2018/04/05 Original 0.1.9 on 9x
Current:        2020/08/01 -> 0.1.10 on 11x
' > $P-doc.tcz.info

echo 'Title:          arandr-locale.tcz
Description:    locales
Version:        0.1.10
Author:         chrysn 
Original-site:  http://christian.amsuess.com/tools/arandr/#project
Copying-policy: GPL v3
Size:           76K
Extension_by:   aus9 
Tags:           xrandr 
Comments:       for non-english users untested

Change-log:     2018/04/05 Original 0.1.9 on 9x
Current:        2020/08/01 -> 0.1.10 on 11x
 ' > $P-locale.tcz.info

echo "Title:          arandr.tcz  
Description:    Front end to libXrandr
Version:        0.1.10
Author:         chrysn 
Original-site:  http://christian.amsuess.com/tools/arandr/#project
Copying-policy: GPL v3
Size:           68K
Extension_by:   aus9 
Tags:           xrandr monitor screen
Comments:       monitor resolutions app
                MUST be on Xorg (2d or 3d). 
                Click Outputs < HDMI* or DVI*> 
                -> Resolution -> Choose your preference  
                -> Click the Tick button 
                I am unable to test 2 monitors but recommend
                you tick the primary radio button.
                
                If you wish to save new setting -> Click the 
                download icon and choose a filename maybe 1920
                (.sh is added by the TCE and created at 
                ~/.screenlayout/1920.sh)
                
                To automate it -> (change file-name below)
                echo '.screenlayout/1920.sh &' > ~./X.d/monitor
                
                My choices were limited under Xorg 2d versus 3d 
                I suggest use a WM that has window decorations  
                if you go from high to low numbers, so you can 
                re-position to get to some buttons. YMMV                
                
Change-log:     2018/04/05 Original 0.1.9 on 9x needed python (2.7)
Current:        2020/08/01 -> 0.1.10 on 11x needed python3.6
" > $P.tcz.info

echo 'arandr.tcz' > $P-locale.tcz.dep
echo 'man-db.tcz' $P-doc.tcz.dep
echo 'python3.6.tcz
py3.6gobject.tcz
gtk3-gir.tcz
adwaita-icon-theme.tcz
libXrandr.tcz' > $P.tcz.dep

submitqc --libs
