#!/bin/bash
# D3 7.5.1 Download, unzip, patch and installation
# Author: Andrew Reis, MCTS
# Copyright 2010, DBMS Inc.
#Create the D3 temp directory

CREDENTIALS=d3mvftp:Rocketd3mv
SERVER=ftp://$CREDENTIALS@ftp.rocketsoftware.com;
DIR="pub/Linux/7.5.1";
D3MONVER=7.5.20;
D3SQLVER=7.5.8;
D3INSTALLVER=7.5.4;
D3FLASHVER=7.5.18;
D3ABSVER=638675xa120;

function downloadD3(){
  curl "$SERVER/$DIR/Releases/D3.tar" -o /tmp/D3751.tar --globoff;
}

clear;
#Create D3 temp directory
if [ ! -d /tmp/D3 ];
  then mkdir /tmp/D3;
fi;

#Change to the D3 temp directory
cd /tmp/D3/;

#Fetch D3 7.5.1 Tarball
if [ -f /tmp/D3.tar ] || [ -f /tmp/D3751.tar ];
  then rm /tmp/D3*.tar;
fi;

#Extract D3.tar to temp directory
if [ ! -f /tmp/D3751.tar ];
then downloadD3;
else
  tar -xvf /tmp/D3751.tar -C /tmp/D3;
fi;

#Remove Old Files
rm /tmp/D3/D3_sql* -f;
rm /tmp/D3/D3_flash* -f;
rm /tmp/D3/D3_install* -f;
rm /tmp/D3/D3_monitor* -f;

#Fetch Patches
curl "$SERVER/$DIR/Patches/D3_sql-lx-$D3SQLVER-.Z" -o "/tmp/D3/D3_sql-lx-$D3SQLVER-.Z" --globoff;
curl "$SERVER/$DIR/Patches/D3_install-lx-$D3INSTALLVER-.Z" -o "/tmp/D3/D3_install-lx-$D3INSTALLVER-.Z" --globoff;
curl "$SERVER/$DIR/Patches/D3_flash-lx-$D3FLASHVER-.Z" -o "/tmp/D3/D3_flash-lx-$D3FLASHVER-.Z" --globoff;
curl "$SERVER/$DIR/Patches/D3_monitor-lx-$D3MONVER-.Z" -o "/tmp/D3/D3_monitor-lx-$D3MONVER-.Z" --globoff;
curl "$SERVER/$DIR/Patches/$D3ABSVER" -o "/tmp/D3/$D3ABSVER" --globoff;

#Start the D3 setup
sudo /tmp/D3/D3_setup;