#!/bin/bash
#(c)2010 Robert Reid
#15th Dec 2010
#v1.2

#set the JAVA_HOME environment
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre

#setup the APT Partner repositories only run these once:
#sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
#sudo apt-get update

#Purge Sun Java plugin, uncomment this if you've been messing around
#apt-get purge -qq sun-java6-bin
#rm -R $JAVA_HOME/lib/ext
#rm -R $JAVA_HOME/lib/security

#(re)install Sun Java plugin, set as default
apt-get install -qq sun-java6-bin sun-java6-plugin wine
update-java-alternatives --plugin -s java-6-sun

#download AUSkey windows installer
wget --continue https://www.auskey.abr.gov.au/plugin/AUSkey_software.msi

#install AUSkey into a temporary folder using Wine
mkdir /tmp/AUSkey
WINEPREFIX=/tmp/AUSkey WINEDEBUG=-all wine msiexec /I AUSkey_software.msi
WINEPREFIX=/tmp/AUSkey WINEDEBUG=-all wineserver -w

#copy the AUSkey lib/ext jars, dont overwrite any
cp --no-clobber /tmp/AUSkey/drive_c/Program\ Files/ABR/Plug-In/JRE/lib/ext/* $JAVA_HOME/lib/ext

#copy the required AUSkey jars into lib/security
cp --backup /tmp/AUSkey/drive_c/Program\ Files/ABR/Plug-In/JRE/lib/security/cacerts          $JAVA_HOME/lib/security/cacerts
cp --backup /tmp/AUSkey/drive_c/Program\ Files/ABR/Plug-In/JRE/lib/security/local_policy.jar $JAVA_HOME/lib/security/local_policy.jar

#clean up
rm -R /tmp/AUSkey

echo ""
echo ""
echo "Finished, check for errors in the output above. Ignore any lines with update-java-alternatives."
echo ""
echo "Enjoy, Rob. rob@rrfx.net"
echo ""
