#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

CFLAGS="-mtune=generic -Os -pipe"
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

P=asunder
V=2.9.2
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc gtk2-dev libcddb-dev intltool "
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://littlesvr.ca/$P/releases/$SRC.tar.bz2"  $USER
mkdir $P
tar jxvf $SRC*bz2
cd $SRC
./configure
make -j5
make install-strip DESTDIR=/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/doc/$P
cp $SRC/AUTHORS $P-doc/usr/local/share/doc/$P/
cp $SRC/COPYING $P-doc/usr/local/share/doc/$P/

# main
#####
APP=$P/usr/local/share/applications/$P.desktop
echo 'X-FullPathIcon=/usr/local/share/pixmaps/asunder.png' >> $APP
sed 's|Asunder|asunder|g' -i $APP

# TCZ them
###########
LIST2="$P $P-doc $P-locale "
for Z in $LIST2
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 'asunder.tcz' > $P-locale.tcz.dep
echo 'libcddb.tcz
cdparanoia.tcz
lxde-icon-theme.tcz' > $P.tcz.dep

echo 'Title:          asunder.tcz
Description:    GUI audio ripper and encoder 
Version:        2.9.2
Author:         many see doc AUTHORS
Original-site:  http://littlesvr.ca/asunder
Copying-policy: GPL v2 June 1991
Size:           72K          		
Extension_by:   aus9 at gmx dot com
Tags:           graphical GUI audio cd ripper encoder
Comments:       GTK2 graphical audio ripper

                In order to use it, cddb needs online access 
                There is a short delay for info to populate the GUI

                Quick Tips 
                extra TCEs can be loaded with asunder already running
                untick any tracks before Preferences and choosing
                format:
                --wav already supported
                --mp3 needs lame.tcz
                --ogg needs vorbis-tools .tcz
                --flac needs flac.tcz (loaded by vorbis-tools too)
                --wavpack needs wavpack.tcz
                I suggest you until M3U playlist under preferences too
                Now its safe to click that RIP button
                RESULTS are under each artist Dir.

                Compiled for 10x
Change-log:     2019/04/07 first version
Current:        2019/04/07  ' > $P.tcz.info

echo 'Title:          asunder-doc.tcz
Description:    documents
Version:        2.9.2
Author:         see AUTHORS
Original-site:  http://littlesvr.ca/asunder
Copying-policy: GPL v2 June 1991
Size:           12K          		
Extension_by:   aus9 at gmx dot com
Tags:           graphical GUI audio cd ripper encoder
Comments:       Documents

                Compiled for 10x
Change-log:     2019/04/07 first version
Current:        2019/04/07  ' > $P-doc.tcz.info

echo 'Title:          asunder-locale.tcz
Description:    locales 
Version:        2.9.2
Author:         many see doc AUTHORS
Original-site:  http://littlesvr.ca/asunder
Copying-policy: GPL v2 June 1991
Size:           176K          		
Extension_by:   aus9 at gmx dot com
Tags:           graphical GUI audio cd ripper encoder
Comments:       locales untested by me

                Compiled for 10x
Change-log:     2019/04/07 first version
Current:        2019/04/07  ' > $P-locale.tcz.info

submitqc --libs
