#!/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=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc gettext py3.9cairo-dev python3.9-docutils  "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
http://christian.amsuess.com/tools/$P/files/$SRC.tar.gz \
http://tinycorelinux.net/15.x/x86_64/tcz/arandr.tcz
unsquashfs arandr.tcz # to get the pixmap
tar xvf $SRC*gz
cd $SRC
python3.9 setup.py install --prefix=/usr/local --root=/tmp/$P
cd /tmp

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

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

# main
###### 
# desktop
#########
DESK=$P/usr/local/share/applications/$P.desktop
sed 's|display|arandr|' -i $DESK
sed 's|HardwareSettings;|System;Utility;|' -i $DESK
sed 's|true|false|' -i $DESK # no need for startup notify stuff
echo 'X-FullPathIcon=/usr/local/share/pixmaps/arandr.png' >> $DESK

# pixmap
#########
mkdir -p $P/usr/local/share/pixmaps
SRC2=squashfs-root/usr/local/share/pixmaps/$P.png
cp $SRC2 $P/usr/local/share/pixmaps/

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

# submit finds some perms
chmod 644 $DESK
chmod 755 $P/usr/local/lib/python3.9/site-packages/screenlayout/*.py
# but this leads to one new error 
chmod 644 $P/usr/local/lib/python3.9/site-packages/screenlayout/__init__.py

# 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 . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          arandr-doc.tcz
Description:    man pages
Version:        0.1.11
Author:         chrysn 
Original-site:  https://gitlab.com/arandr/arandr
Copying-policy: GPL v3
Size:           4.0K
Extension_by:   aus9  @ linuxquestions.org
Tags:           monitor resolution 
Comments:       man pages
                
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
                2023/04/27 v 0.1.11 on 14x 
                2024/10/13 on 15x used python3.9 - move from svg to png 
Current:        2025/11/14 on 16x rebuilt against updated python3.9  ' > arandr-doc.tcz.info
echo 'man-db.tcz' >  arandr-doc.tcz.dep

echo 'Title:          arandr-locale.tcz
Description:    locales
Version:        0.1.11
Author:         chrysn 
Original-site:  https://gitlab.com/arandr/arandr
Copying-policy: GPL v3
Size:           76K
Extension_by:   aus9  @ linuxquestions.org
Tags:           monitor resolution
Comments:       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
                2023/04/27 v 0.1.11 on 14x 
                2024/10/13 on 15x used python3.9 - move from svg to png 
Current:        2025/11/14 on 16x rebuilt against updated python3.9  ' > $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:  https://gitlab.com/arandr/arandr
Copying-policy: GPL v3
Size:           72K
Extension_by:   aus9  @ linuxquestions.org
Tags:           monitor resolution
Comments:       monitor resolution app
                You need to 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" 

                For wayland desktops, try wlr-randr     
                
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
                2023/04/27 v 0.1.11 on 14x 
                2024/10/13 on 15x used python3.9 - move from svg to png 
Current:        2025/11/14 on 16x rebuilt against updated python3.9 ' > $P.tcz.info 

# new dep.....FileNotFoundError: [Errno 2] No such file or directory: 'xrandr'

echo 'py3.9gobject.tcz
gtk3-gir.tcz 
Xorg-7.7-bin.tcz' > $P.tcz.dep


# NOPE submitqc plays up again!....it rebuilds list and creates usr/blah blah AND usr_1 against arandr, others are fine
# arandr.tcz.tcz.list does not match extension content. Making new arandr.tcz.list ... Done.
# submitqc --libs
# rm -rf *.zsync


