#!/bin/sh

# The purpose of this script is to record the configuration of
# the currently installed opera.  Ideally, you can just re-run this
# script to re-install Opera.

# The script tries to get opera installed into the correct locations,
# and patch the install so that plugins (java) work.

# Please update this variable, if opera updates.
# It should match the substring embedded in the directory name, 
# e.g.: opera-9.10-20061214.1-static-qt.i386-en-521
opera_version=9.10-20061214.1


usage () {
  echo "Usage:"
  echo "\$ cd /mit/opera/distrib/v9.10-linux"
  echo "\$ cd opera-${opera_version=9.10-20061214.1}-static-qt.i386-en-521"
  echo "\$ ../../athena-install.sh"
  echo ""
  echo "Notes:"
  echo "- Please re-check the \$opera_version variable in athena-install.sh."
  echo "- The install.sh script will complain that it cannot write to /etc/. Ignore it."
  exit 1
}

if [ ! -x ./install.sh ] ; then
  usage
fi

prefix=/var/tmp/opera
#prefix=/mit/opera

# say "no" to the question of whether to (try) to install /etc/opera6rc
echo no |       \
./install.sh -v \
--exec_prefix="${prefix}/arch/${ATHENA_SYS}/lib/opera/${opera_version}" \
--wrapperdir="${prefix}/arch/${ATHENA_SYS}/bin"                         \
--docdir="${prefix}/share/doc/opera"                                    \
--sharedir="${prefix}/share/opera"				        \
--plugindir="${prefix}/arch/${ATHENA_SYS}/lib/opera/plugins"            \
--mandir="${prefix}/man"

echo ""

######################################################################
# We patch the opera launch script to fix LD_PRELOAD
#

case "$ATHENA_SYS" in
 i?86*)
  machine=i386
  ;;
 sun*)
  machine=sparc
  ;;
 *)
  echo "Fatal problem, unknown \$ATHENA_SYS (=${ATHENA_SYS})"
  exit 1
  ;;
esac

# The "here-doc" is unquoted, so we interpolate variables ($machine),
#  which also means we need to quote the \$ of ${OPERA_LD_PRELOAD}
patch ${prefix}/arch/${ATHENA_SYS}/bin/opera <<EOF
--- opera~      Fri Jan 19 09:41:31 2007
+++ opera       Fri Jan 19 10:18:25 2007
@@ -9,4 +9,6 @@
 export OPERA_BINARYDIR
 
+OPERA_JAVA_DIR=/afs/athena.mit.edu/software/java/current/jre/lib/$machine
+
 # Parse commandline parameters
 toset=
@@ -160,5 +162,5 @@
 
 # Workarounds for the "preloaded libXt" problem.
-LD_PRELOAD="libjvm.so:libawt.so:\${OPERA_LD_PRELOAD}"
+LD_PRELOAD="libXm.so:libjvm.so:libawt.so:\${OPERA_LD_PRELOAD}"
 export LD_PRELOAD
 # To disable the first workaround, comment the next line.
EOF
