Friday, April 19, 2013

[ Level 3 ] The script for setup the Ubuntu for Juniper VPN.

There is an paper told us how to setup Ubuntu 12.04 for Juniper VPN.
Then I follow the guide and also write a script for installation/setup.
The steps as the following:
1. Download ans install ia32-libs to support 32 bit libraries.
2. Download and install x64 JRE, jre-7u21-linux-x64.tar.gz.
3. Create plugin link for firefox/google chromium.
4. Update alternative Java.
5. Download and install i586 JRE, jre-7u21-linux-i586.tar.gz.

After that, you could login to your VPN.

#!/bin/bash
## url link for 64 bit JRE.
jre_x64_source_url=http://javadl.sun.com/webapps/download/AutoDL?BundleId=76853
## url link for 32 bit JRE
jre_i586_source_url=http://javadl.sun.com/webapps/download/AutoDL?BundleId=76851

die() {
  echo "$1"
  exit ${2:-1}
}

checkRootID() {
  uid=`id | cut -d'(' -f1 | cut -d'=' -f2`
  [ $uid -ne 0 ] && die "Need root to execute this command, exit!"
}
checkRootID
 
pek2c() {
  bDebug && read -p "Press enter key to continue..." x
}

syncFS() {
  sync;sync;sync
  sleep 3
}

changeOwner() {
  chown -R root:root $java_dir
}

installJREx64() {
  ## install jre x64
  jre_x64_filename=jre_x64.tar.gz
  rm -f $exec_at_dir/${jre_x64_source_url##*/}
  cd $exec_at_dir
  wget $jre_x64_source_url
  mv $exec_at_dir/${jre_x64_source_url##*/} $java_dir/$jre_x64_filename
  cd $java_dir
  tar zxf $java_dir/$jre_x64_filename
  jre_x64_version=`tar ztvf $java_dir/$jre_x64_filename | head -1 | awk '{print($NF)}' | sed -e s'|/$||'`
  syncFS
  pek2c
  update-alternatives --install /usr/bin/java java /usr/java/$jre_x64_version/bin/java 1 
  update-alternatives --set java /usr/java/$jre_x64_version/bin/java
  pek2c
  cd /usr/lib/mozilla/plugins && rm -f ./libnpjp2.so ./libjavaplugin.so ./libjavaplugin_oji.so && ln -sf /usr/java/$jre_x64_version/lib/amd64/libnpjp2.so ./
  cd /usr/lib/chromium-browser/plugins && ln -sf /usr/java/$jre_x64_version/lib/amd64/libnpjp2.so ./
  pek2c
  rm $java_dir/$jre_x64_filename
}

installJREi586() {
  ## install jre i586
  jre_i586_filename=jre_i586.tar.gz
  rm -f $exec_at_dir/${jre_i586_source_url##*/}
  cd $exec_at_dir
  wget $jre_i586_source_url
  mv $exec_at_dir/${jre_i586_source_url##*/} $java_dir/$jre_i586_filename
  cd $java_dir
  tar zxf $java_dir/$jre_i586_filename
  syncFS
  pek2c
  rm $java_dir/$jre_i586_filename
}

######## main ########

[ "$1" == "-d" ] && set -vx && bDebug=true

## global vars, prepare environment
exec_at_dir="`pwd`" ## where to execute this command.
cd $exec_at_dir/./`dirname $0`
run_at_dir="`pwd`" ## where should this script run at.
java_dir="/usr/java"
mkdir -p $java_dir
apt-get install -y ia32-libs

## install JRE x86 first
installJREx64

## install JRE x586 second
installJREi586

## change owner
changeOwner




Wish this helps.

regards,
Stanley Huang