#!/bin/bash
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=volumeicon
V=0.5.1
SRC=$P-git
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc git autoconf automake libtool-dev intltool \
gettext-dev gtk3-dev alsa-dev imagemagick "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
git clone https://github.com/Maato/volumeicon.git
mv $P $SRC
cd $SRC
./autogen.sh
./autogen.sh autoupdate
# and ignored various warnings
./configure --prefix=/usr/local --disable-oss --disable-notify
make -j5 # seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp

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

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

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

# desktop - icon
################
cd $P/usr/local/share/volumeicon/gui 
convert appicon.svg -resize 48x48 $P.png
rm -rf appicon.svg
cd /tmp
mkdir -p $P/usr/local/share/pixmaps
cp $P/usr/local/share/volumeicon/gui/$P.png  $P/usr/local/share/pixmaps/

# no desktop
mkdir -p $P/usr/local/share/applications
echo '[Desktop Entry]
Name=volumeicon
Exec=volumeicon 
Icon=volumeicon
Terminal=false
X-FullPathIcon=/usr/local/share/pixmaps/volumeicon.png
Type=Application
Categories=Sound;Utility; ' > $P/usr/local/share/applications/$P.desktop

# submit is finding space between the status icon names but adding hypen borks the status icon


# 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:          volumeicon-doc.tcz 
Description:    man pages
Version:        0.5.1
Author:         various
Original-site:  https://github.com/Maato/volumeicon
Copying-policy: GPL v3 
Size:           8.0K
Extension_by:   aus9 @linuxquestions.org 
Tags:           alsa
Comments:       # general command use
                $ man volumeicon 

                # volume adjustments
                $ man 5 volumeicon 

Change-log:     2024/11/06 v git-nov on 15x
Current:        2024/11/06' > $P-doc.tcz.info
echo 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          volumeicon-locale.tcz 
Description:    locales for volumeicon
Version:        0.5.1
Author:         various
Original-site:  https://github.com/Maato/volumeicon
Copying-policy: GPL v3 
Size:           20K
Extension_by:   aus9 @linuxquestions.org 
Tags:           alsa
Comments:       not tested by me

Change-log:     2023/03/13 v 0.5.1 on 14x
Current:        2024/11/06 v git-nov on 15x more locales fix desktop' > $P-locale.tcz.info
echo 'volumeicon.tcz' > $P-locale.tcz.dep

echo 'Title:          volumeicon.tcz 
Description:    alsa volume applet for system trays
Version:        0.5.1
Author:         various
Original-site:  https://github.com/Maato/volumeicon
Copying-policy: GPL v3 
Size:           44K
Extension_by:   aus9 @linuxquestions.org 
Tags:           alsa
Comments:       Tested on icewm & jwm
                alsa sound must be set up first please.
                You may need more alsa TCES

                For a RH mouse user, left click mutes master volume
                right click opens context menu
                Depending on your dark or light themes, 
                context menu -> preferences -> status icon
                .....change icon dark to light or whatever
                context menu -> open mixer = alsamixer

                Autostart applet add line to existing file,
                its not a script just a file
                $ cat ~/X.d/volumeicon
                volumeicon 
                
                Or $ volumeicon & # in a terminal

Change-log:     2023/03/13 Original 0.5.1 on 14x
Current:        2024/11/06 v git-nov on 15x more locales fix desktop, no svg' > $P.tcz.info

readelf -d $P/usr/local/bin/volumeicon | grep 'NEEDED'
# libgtk-3.so.0]libgdk-3.so.0] gtk3  
# libpangocairo-1.0.so.0]libpango-1.0.so.0]pango gtk3  
# libharfbuzz.so.0]harfbuzz
# libatk-1.0.so.0]at-spi2-core gtk3
# libcairo-gobject.so.2]libcairo.so.2]cairo pango gtk3       
# libgdk_pixbuf-2.0.so.0] gdk-pixbuf2 gtk3 
# libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0]glib2 harfbuzz             
# libasound.so.2]libasound....... alsa....because open mixer is alsamixer which is alsa TCE
# libX11.so.6]libX11

echo 'gtk3.tcz
harfbuzz.tcz
alsa.tcz
libX11.tcz  ' > $P.tcz.dep


submitqc --libs
rm -rf *.zsync
