#!/bin/sh
# check if Knoppix cd is used - probing for directory /KNOPPIX
# when using as root standard install option is global under /usr
# use "-local" as parameter to force local install for root
# for global installation "apt-get update" MUST be executed before and apt-get MUST work
if test -d /KNOPPIX; then
 DEST=local
elif test $(id -u) == 0; then
 if test "$1" = "-local"; then
  DEST=local
 else
  DEST=global
 fi
else
 DEST=local
fi 
if test "$DEST" = "local"; then
 PREFIX=$HOME/dist
 GREP_RESULT=`grep $PREFIX/bin $HOME/.bashrc`
 if test -z "$GREP_RESULT"; then
  echo "export PATH=$PREFIX/bin:$PATH" >> $HOME/.bashrc
 fi
 GREP_RESULT=`grep $PREFIX/lib $HOME/.bashrc`
 if test -z "$GREP_RESULT"; then
  echo "export LD_LIBRARY_PATH=$PREFIX/lib" >> $HOME/.bashrc
 fi
else
 PREFIX=/usr
fi
mkdir -p $PREFIX/src
cd $PREFIX/src
VER=0.6.12
wget -Nc http://www.zebra.fh-weingarten.de/~transcode/pre/transcode-$VER.tar.gz
rm -rf transcode-$VER
rm -rf transcode-$VER.orig
tar zxf transcode-$VER.tar.gz &>/dev/null || (
 rm -f transcode-$VER.tar.gz
 echo transcode-$VER.tar.gz could not be extracted
 echo and has been deleted. Please restart this script.
 exit 1
) || exit $?
cd transcode-$VER
if test "$DEST" = "local"; then
 ./configure --prefix=$PREFIX --enable-mp3lame
 make
 make install
else
 echo|dh_make -s -c gpl
 perl -pi -e 's/.*[hH][tT][mM][lL].*\n//' debian/transcode.doc-base.EX
 perl -pi -e 's/(CFLAGS=)(\$\(CFLAGS\))/\1"\2"/' debian/rules
 fakeroot debian/rules binary 
 dpkg -i ../transcode_$VER-1_$(dpkg-architecture -qDEB_BUILD_ARCH).deb
fi
cd ..
rm -rf transcode-$VER.orig
rm -rf transcode-$VER
