#!/bin/bash

# determine platform architecture
ARCH=`uname -m`

## prerequisites

# get Arduino package, depending on JRE, JDK and RXTX library
apt-get -y install arduino

# download and unpack software for Sanguino as Arduino variant
wget http://sanguino.googlecode.com/files/Sanguino-0018r2_1_4.zip
unzip Sanguino-0018r2_1_4.zip Sanguino/* -d /usr/share/arduino/hardware

# get 64-bit Java3D JNI library, if relevant
if [ $ARCH="x86_64" ]; then
	sudo apt-get -y install libjava3d-jni
fi

## download and unpack architecture relevant RepRap bundle; adjust it
if [ $ARCH="x86_64" ]; then
	wget --content-disposition http://sourceforge.net/projects/reprap64bit/files/reprap%2064bit-mendel-20100719.zip/download
	unzip reprap\ 64bit-mendel-20100719.zip -d /usr/local
	cd /usr/local/Reprap
	chmod +x reprap
	ln -sf /usr/lib/jni/libj3dcore-ogl.so .
	ln -sf /usr/lib/jni/librxtxParallel.so .
	ln -sf /usr/lib/jni/librxtxSerial.so .
else
	wget --content-disposition http://sourceforge.net/projects/reprap/files/reprap-mendel-20100806.zip/download
	unzip reprap-mendel-20100806.zip -d /usr/local
	mv /usr/local/reprap-mendel-20100806 /usr/local/reprap
fi

## create startup script
echo -e '#!/bin/sh'\n"cd /usr/local/reprap\n./reprap &" > /usr/local/bin/reprap && chmod +x /usr/local/bin/reprap
