#!/bin/bash
#
# VI editor settings
# set shiftwidth=4
# set tabstop=4
# ==========================================================
# Title: Create fast MATLAB installer
# Author: Mike Gore
# Date: 8 Jan 2016 
# Tested with 14.04lts
# Notes:
#   Matlab can be installed simply by copying the directory of a working version
#   from an existing system along with its /usr/local/bin symlinks
#   We can save this into a TAR gzipped file and store it on ASIMOV using
#   this utility. This makes for a very fast install process.
# =======================================================================

if [ $# -eq 2 ]
then
	MATLAB_PATH=$1
	RELEASE=$2
else
	echo Usage: $0 MATLAB_PATH RELEASE 
	echo    MATLAB_PATH is the full path to your MATLAB release
	echo    RELEASE is the MATLAB release version like R2012a
	echo
	echo Example: $0 /usr/local/MATLAB/R2012a R012a
	exit 1
fi

if [ ! -d $MATLAB_PATH ]
then
	echo $0 $MATLAB_PATH not found
	exit 1
fi

ARCH=`arch`
TARFILE=/tmp/matlab-$RELEASE-$ARCH.tar.gz

echo MATLAB_PATH: $MATLAB_PATH
echo RELEASE:     $RELEASE
echo ARCH:        $ARCH
echo TAR File:    $TARFILE

echo Creating $TARFILE

tar czf $TARFILE \
	$MATLAB_PATH \
	/usr/local/bin/matlab \
	/usr/local/bin/mbuild \
	/usr/local/bin/mcc \
	/usr/local/bin/mex

echo Do you want to upload this to ASIMOV [Y/N] ?
A=`line`
if [ "$A" = "Y"  -o "$A" = "y" ]
then
	echo You will be prompted for the cscf-adm password
	echo rsync -a $TARFILE cscf-adm@asimov:/coregroup/images/packages
	rsync -a $TARFILE cscf-adm@asimov:/coregroup/images/packages
else
	echo Your tar file is saved in $TARFILE
fi