#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild

CWD=`pwd`
NAME=winetools
TMP=${TMP:-/tmp}
PKG=$TMP/package-$NAME

VERSION=0.9jo.III
ARCH=i386
BUILD=2lu

if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
rm -rf $PKG
mkdir -p $PKG/usr/bin/
mkdir -p $PKG/usr/share/winetools
mkdir -p $PKG/usr/doc/winetools-$VERSION

cd $TMP
tar xvzf $CWD/$NAME-0.9jo-III.tar.gz
cd $TMP/$NAME-0.9jo-III
cp -R * $PKG/usr/share/winetools
cd $PKG
ln -s CHANGELOG.txt EULA_en.ie6.txt TODO.txt README* usr/doc/winetools-$VERSION
ln -s /usr/share/winetools/wt0.9jo $PKG/usr/bin/wt2
ln -s /usr/share/winetools/wt$VERSION $PKG/usr/bin/winetools
ln -s /usr/share/winetools/findwine $PKG/usr/bin/findwine
rm -f $PKG/usr/share/winetools/Xdialog
ln -s /usr/share/winetools/Xdialog.builtin $PKG/usr/share/winetools/Xdialog
cd $PKG/usr/share/winetools
sed -i "s|/usr/local/share/locale|/usr/share/locale|g" wt0.9jo
sed -i 's|BASEDIR="/usr/local/winetools"|BASEDIR="/usr/share/winetools"|g' wt0.9jo
sed -i "s|/usr/local/winetools|/usr/share/winetools|g" install
sed -i "s|/usr/local/share|/usr/share/|g" install
sed -i "s|/usr/local/bin|/usr/bin|g" install
sed -i "s|/usr/local/winetools|/usr/share/winetools|g" findwine
sed -i "s|/usr/local/share/locale|/usr/share/locale|g" findwine

#Le prossime 6 righe sono state copiate da install.sh originale
cd "$PKG/usr/share/winetools/po"
for i in $( ls  *.po|cut -f1 -d.); do
	mkdir -p $DIR/locale/$i/LC_MESSAGES
	msgfmt $i.po -o $DIR/locale/$i/LC_MESSAGES/wt2.mo
  echo "Installed translations for $i to $DIR/locale/$i/LC_MESSAGES/wt2.mo"
done

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cat <<eof > $PKG/install/doinst.sh
( echo )
( echo )
( echo ================================================ )
( echo )
( echo Start WineTools as *normal* user with \"wt2\". Don\'t use as root!)
( echo )
( echo ================================================ )
( echo )

eof
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION
chown -R root.root $PKG/usr/doc/$NAME-$VERSION
cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$NAME-0.9jo-III
 rm -rf $PKG
fi
