ERR=false do_install() { mkdir tracker_working cd tracker_working wget --no-check-certificate https://content.ilabsolutions.com/wp-content/uploads/2013/01/ilab_tracker_linux.tar.gz tar xvzf ilab_tracker_linux.tar.gz wget --no-check-certificate https://content.ilabsolutions.com/wp-content/uploads/2012/06/tracker_linux.tar.gz tar xvzf tracker_linux.tar.gz mv start-tracker /usr/bin mv usagetracker.desktop /etc/xdg/autostart cp ../tracker.conf ./UsageTracker mkdir /opt/iLab chmod augo+rwx /opt/iLab mv UsageTracker/ /opt/iLab/ dos2unix /opt/iLab/UsageTracker/UsageTracker.sh touch /opt/iLab/UsageTracker/usage_tracker.log touch /opt/iLab/UsageTracker/error_trace.log find /opt/iLab -type d -exec chmod augo+rwx {} + find /opt/iLab -type f -exec chmod augo+rw {} + chmod a+x /opt/iLab/UsageTracker/UsageTracker.sh cd .. rm -rf tracker_working } check_error() { if [ "$ERR" = true ]; then error_and_exit fi } error_and_exit() { echo "===============================================================" echo "ABORTING! " echo "An error was encountered while trying to install the usage tracker." echo "Please correct the errors above before proceeding" echo "Please contact support@ilabsolutions.com for help if needed." echo "===============================================================" exit 1 } installation_completed() { echo "===============================================================" echo "SUCCESS! " echo "Installation of the iLab usage tracker was successful." echo "You must restart the computer for the changes to take effect." read -p "Do you want to restart now? (y/n)?" choice echo case "$choice" in y|Y ) shutdown -r now;; n|N ) echo "continuing without restart";; * ) echo "invalid input. continuing without restart";; esac echo "===============================================================" } preamble() { echo "===============================================================" echo "Welcome to the iLab usage tracker installation! " echo "You will now attempt to install the usage tracker client on the current computer." read -p "Do you want to continue? (y/n)?" cont echo case "$cont" in y|Y ) echo "proceeding with installation";; n|N ) echo "Aborting..."; exit 1;; * ) echo "invalid input. Aborting..."; exit 1;; esac echo "===============================================================" } check_java_version() { JAVA_VER=$(java -version 2>&1 | sed 's/java version "\(.*\)\.\(.*\)\..*"/\1\2/; 1q') if [ "$JAVA_VER" -ge 16 ]; then echo "OK: java is 1.6 or newer" else echo "ERROR: java version is too old. Please install java version 6 or better" ERR=true fi } check_if_root() { if [ "$(whoami)" != "root" ]; then echo "ERROR: Sorry, you are not root. Try sudo." ERR=true fi } check_if_tracker_file_exists() { if [ ! -f ./tracker.conf ]; then echo "ERROR: Configuration file not found! " echo "Please download a config file from iLab and rerun the command from the folder which contains the file." ERR=true } check_required_commands() { command -v wget >/dev/null 2>&1 || { echo >&2 "ERROR: wget command not found. Installer needs 'wget' to be installed."; ERR=true; } command -v dos2unix >/dev/null 2>&1 || { echo >&2 "ERROR: dos2unix command not found. Installer needs 'dos2unix' to be installed."; ERR=true; } } preamble check_java_version check_if_root check_if_tracker_file_exists check_required_commands check_error do_install check_error installation_completed