#Maintainer: Dimitris Jemos <djemos~at~slackel~dot~gr>

#Mandatory
pkgname=frostwire
pkgver=5.3.9
pkgrel=1dj
arch=noarch
source=("http://main1.frostwire.com/frostwire/$pkgver/$pkgname-$pkgver.noarch.tar.gz" "frostwire.desktop" "icons.tar.gz" "java-version-detection.patch")
sourcetemplate=http://people.salixos.org/djemos/salix/$pkgname
#Optional
docs=("COPYING" "EULA.txt" "changelog")
url=http://www.frostwire.com


slackdesc=\
(
 #|-----handy-ruler------------------------------------------------------|
  "frostwire (P2P File sharing Client)"
  "Frostwire is a cross-platform, open-source peer-to-peer filesharing" 
  "client for the Gnutella and BitTorrent protocols."
  "It is written in Java and is a fork of Limewire that includes all of "
  "the free LimeWire version's functionality, plus a few features of" 
  "LimeWire Pro's fee based upgrades."
  "This is essentially a repackaging of the official binary from"
  ""
  "homepage: http://www.frostwire.com/"
)

build() {
        
cd $startdir/src/$pkgname-$pkgver.noarch || return 1

# FS#15544 (Java version detection fails when _JAVA_OPTIONS is set)
  patch -Np0 -i "$startdir/src/java-version-detection.patch" || return 1
    
#make launch script
mkdir -p $startdir/pkg/usr/bin/        
cat << EOF > $startdir/pkg/usr/bin/$pkgname
#!/bin/sh
cd /usr/share/frostwire
./frostwire
EOF
           
chmod 0755 $startdir/pkg/usr/bin/$pkgname               
     
# Just copy stuff around
  
mkdir -p $startdir/pkg/usr/share/$pkgname-$pkgver
cp -a ./* $startdir/pkg/usr/share/$pkgname-$pkgver

# except root dir
rm -rf $startdir/pkg/usr/share/$pkgname-$pkgver/root

#make link     
(
cd $startdir/pkg/usr/share
ln -s $pkgname-$pkgver $pkgname
)
                 
# Copy icons to the right place
ICONSIZES="64 48 32 16"
for i in $ICONSIZES; do
mkdir -p $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps;
mv $startdir/src/$pkgname-$i.png $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps/$pkgname.png;
done;
	
mkdir -p $startdir/pkg/usr/share/pixmaps  || return 1
cp $startdir/pkg/usr/share/icons/hicolor/48x48/apps/frostwire.png $startdir/pkg/usr/share/pixmaps  || return 1
        
mkdir -p $startdir/pkg/usr/share/applications || return 1
cp $startdir/src/frostwire.desktop $startdir/pkg/usr/share/applications/ || return 1
sed -i "s/Categories=.*/Categories=Application;Network;/" $startdir/pkg/usr/share/applications/frostwire.desktop || return 1
sed -i "s/.png//" $startdir/pkg/usr/share/applications/frostwire.desktop || return 1  
chown -R root:root $startdir/pkg            
	
}



# Doinst
doinst() {   

if [ -x /usr/bin/update-desktop-database ]; then
 /usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
fi

}