#!/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
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
mkdir -p $PREFIX/src
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
cd $PREFIX/src
#wget -Nc $(w3c "http://alltheweb.com/?avkw=fogg&cat=ftp&cs=utf-8&q=rp8_linux20_libc6_i386_cs2_rpm&_sb_lang=pref" | grep ftp | grep "rp8_linux20_libc6_i386_cs2_rpm$" | awk {'print $2;'} | sort -u)
wget -O rp8_linux20_libc6_i386_cs2_rpm -Nc http://www.linux-video.net/Video.Players/rp8_linux20_libc6_i386_cs2.rpm 
wget -Nc http://docs.real.com/docs/playerpatch/unix/rv9_libc6_i386_cs2.tgz
case "$DEST" in
 local)
  rm -rf rpm/
  mkdir -p rpm/
  cd rpm/
  rpm2cpio ../rp8_linux20_libc6_i386_cs2_rpm|cpio -di usr/lib/RealPlayer8/*
  cd ..
  cp -fa rpm/usr/* ../
  rm -rf rpm/
  rm -rf rv9/
  tar zxf rv9_libc6_i386_cs2.tgz
  cd rv9/
  cp codecs/drv4.so.6.0 ../../lib/RealPlayer8/Codecs/
  cp codecs/rv40.so.6.0 ../../lib/RealPlayer8/Codecs/
  cd ..
  rm -rf rv9/      
  cd ..
  mkdir -p bin/
  ln -sf ../lib/RealPlayer8/realplay bin/realplay
  mkdir -p ~/.mozilla/plugins/
  ln -sf $PREFIX/lib/RealPlayer8/rpnp.so ~/.mozilla/plugins/
  ln -sf $PREFIX/lib/RealPlayer8/raclass.zip ~/.mozilla/plugins/
  mkdir -p ~/.netscape/plugins/
  ln -sf $PREFIX/lib/RealPlayer8/rpnp.so ~/.netscape/plugins/
  ln -sf $PREFIX/lib/RealPlayer8/raclass.zip ~/.netscape/plugins/
  nspluginscan &>/dev/null 
  echo ERegistered=1 >~/.RealNetworks_RealPlayer_60
  ;;
 global)
  ln -sf rp8_linux20_libc6_i386_cs2_rpm rp8.linux20.libc6.i386.cs2.rpm
  alien rp8.linux20.libc6.i386.cs2.rpm
  dpkg -i realplayer_8.0-2_i386.deb
  ln -sf /usr/lib/RealPlayer8/realplay /usr/bin/realplay
  mkdir -p /usr/lib/mozilla/plugins/
  ln -sf /usr/lib/RealPlayer8/rpnp.so /usr/lib/mozilla/plugins/ 
  ln -sf /usr/lib/RealPlayer8/raclass.zip /usr/lib/mozilla/plugins/
  if [ -d /usr/lib/mozilla-firebird/plugins ]; then
   ln -sf /usr/lib/RealPlayer8/rpnp.so /usr/lib/mozilla-firebird/plugins/
   ln -sf /usr/lib/RealPlayer8/raclass.zip /usr/lib/mozilla-firebird/plugins/
  fi
  if [ -d /usr/lib/mozilla-firefox/plugins ]; then
   ln -sf /usr/lib/RealPlayer8/rpnp.so /usr/lib/mozilla-firefox/plugins/
   ln -sf /usr/lib/RealPlayer8/raclass.zip /usr/lib/mozilla-firefox/plugins/
  fi
  rm -rf rv9/
  tar zxf rv9_libc6_i386_cs2.tgz
  cd rv9/
  cp codecs/drv4.so.6.0 /usr/lib/RealPlayer8/Codecs/
  cp codecs/rv40.so.6.0 /usr/lib/RealPlayer8/Codecs/
  cd ..
  rm -rf rv9/
  ;;
esac
cat <<EOF

to start open a new console, then: realplay
to use the realplayer plugin start mozilla from console.
EOF
