#!/bin/bash
#
#  unetbootin.SlackBuild is free software; you can redistribute it and/or modify it under the
#  terms of the GNU General Public License as published by the Free Software
#  Foundation; either version 2 of the License, or any later version.
#
#  unetbootin.SlackBuild is distributed in the hope that it will be useful, but WITHOUT ANY
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
#  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License along with
#  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
#  Place - Suite 330, Boston, MA 02111-1307, USA
#

# default settings
PACKAGE="unetbootin"
PACKAGE_EXT="gz"
VERSION=${VERSION:=625}
BUILD=${BUILD:=1}

if [ -f ~/.slackbuildrc ]; then
  . ~/.slackbuildrc
elif [ -f ../../runtime/slackbuildrc ]; then
  . ../../runtime/slackbuildrc
fi

check_required

SRC="$PACKAGE-source-$VERSION.tar.$PACKAGE_EXT"
URL="http://prdownloads.sourceforge.net/unetbootin/$SRC"

get_source $SRC $URL

PTMP=$TMP/unetbootin
rm -rf $PTMP
mkdir -p $PTMP
cd $PTMP
tar xfvz $CWD/$SRC

chown -R root:root .
chmod -R u+w,go+r-w,a-s .

lupdate unetbootin.pro
lrelease unetbootin.pro
qmake -config release "DEFINES += NOSTATIC" "RESOURCES -= unetbootin.qrc"
make
strip --strip-unneeded $PACKAGE

mkdir -p $PKG/usr/bin
cp -a $PTMP/$PACKAGE $PKG/usr/bin/$PACKAGE

mkdir -p $PKG/usr/share/applications
cp -a $PTMP/$PACKAGE.desktop  $PKG/usr/share/applications/$PACKAGE.desktop

mkdir -p $PKG/usr/share/$PACKAGE
for file in ${PACKAGE}*.qm; do
 	cp -a ${file} $PKG/usr/share/$PACKAGE/
done
for file in ${PACKAGE}*.png; do
 	size="${file/${PACKAGE}_}"
 	size="${size/.png}x${size/.png}"
 	mkdir -p $PKG/usr/share/icons/hicolor/${size}/apps
 	cp -a ${file} $PKG/usr/share/icons/hicolor/${size}/apps/$(echo $file | tr -d _$size)
done

mkdir -p $PKG/usr/share/icons/hicolor/scalable/apps/
cp -a $PTMP/unetbootin_icons.svg $PKG/usr/share/icons/hicolor/scalable/apps/$PACKAGE.svg

find $PKG/usr/share/icons -type f -exec chmod 0644 {} \;

mkdir -p $PKG/usr/share/pixmaps/
cp -a $PTMP/unetbootin_icons.svg $PKG/usr/share/pixmaps/$PACKAGE.svg
chmod 0644 $PKG/usr/share/pixmaps/$PACKAGE.svg

mkdir -p $PKG/usr/doc/$PACKAGE-$VERSION
cp -a README.TXT INSTALL  $PKG/usr/doc/$PACKAGE-$VERSION
cat $CWD/README.issues > $PKG/usr/doc/$PACKAGE-$VERSION/README.issues
chmod 0644 $PKG/usr/doc/$PACKAGE-$VERSION/INSTALL


fixup_package $PKG

# Clean up the extra stuff:
set +u
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/$PACKAGE-$VERSION
  rm -rf $PKG
fi