#!/bin/bash ##### # esg-compute-languages: ESGF Node Application Stack - Compute Languages # description: Computation languages installer for the ESGF Node application # stack # #**************************************************************************** #* * #* Organization: Lawrence Livermore National Lab (LLNL) * #* Directorate: Computation * #* Department: Computing Applications and Research * #* Division: S&T Global Security * #* Matrix: Atmospheric, Earth and Energy Division * #* Program: PCMDI * #* Project: Earth Systems Grid Fed (ESGF) Node Software Stack * #* First Author: Eugenia Gabrielova (gabrielov1@llnl.gov) * #* * #**************************************************************************** #* * #* Copyright (c) 2009, Lawrence Livermore National Security, LLC. * #* Produced at the Lawrence Livermore National Laboratory * #* Written by: Gavin M. Bell (gavin@llnl.gov) * #* Eugenia Gabrielova (gabrielov1@llnl.gov) * #* LLNL-CODE-420962 * #* * #* All rights reserved. This file is part of the: * #* Earth System Grid Fed (ESGF) Node Software Stack, Version 1.0 * #* * #* For details, see http://esgf.org/ * #* Please also read this link * #* http://esgf.org/LICENSE * #* * #* * Redistribution and use in source and binary forms, with or * #* without modification, are permitted provided that the following * #* conditions are met: * #* * #* * Redistributions of source code must retain the above copyright * #* notice, this list of conditions and the disclaimer below. * #* * #* * Redistributions in binary form must reproduce the above copyright * #* notice, this list of conditions and the disclaimer (as noted below) * #* in the documentation and/or other materials provided with the * #* distribution. * #* * #* Neither the name of the LLNS/LLNL nor the names of its contributors * #* may be used to endorse or promote products derived from this * #* software without specific prior written permission. * #* * #* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * #* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * #* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * #* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE * #* LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR * #* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * #* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * #* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * #* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * #* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * #* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * #* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * #* SUCH DAMAGE. * #* * #**************************************************************************** ##### ##### # Description: Installer for ESG Computation Languages # Authors: gabrielov1@llnl.gov ##### ##### # uses: unzip, wget ##### #-------------- # User Defined / Settable (public) #-------------- install_prefix=${install_prefix:-"/usr/local"} esg_root_dir=${esg_root_dir:-${ESGF_HOME:-"/esg"}} DEBUG=${DEBUG:-0} VERBOSE=${VERBOSE:-0} devel=${devel:-0} compress_extensions=".tar.gz|.tar.bz2|.tgz|.bz2|.tar|.zip" envfile="/etc/esg.env" esg_functions_file=./esg-functions install_manifest=${install_manifest:-"${esg_root_dir}/esgf-install-manifest"} #-------------------------------- # External programs' versions #-------------------------------- clojure_version=${clojure_version:="1.4.0"} clojure_min_version=${clojure_min_version:="1.4.0"} scala_version=${scala_version:="2.9.2"} scala_min_version=${scala_min_version:="2.9.1"} # 2.9.1 is the minimum version supported by Spark. scala_max_version=${scala_max_version:="2.9.2"} #-------------------------------- # External programs' script variables #-------------------------------- clojure_install_dir=${CLOJURE_HOME:-${install_prefix}/clojure} clojure_dist_url="http://repo1.maven.org/maven2/org/clojure/clojure/${clojure_version}/clojure-${clojure_version}.zip" scala_install_dir=${SCALA_HOME:-${install_prefix}/scala} scala_dist_url="http://www.scala-lang.org/downloads/distrib/files/scala-${scala_version}.tgz" #-------------------------------- # Internal Script Variables #-------------------------------- date_format="+%Y_%m_%d_%H%M%S" [ -e "${envfile}" ] && source ${envfile} && ((VERBOSE)) && printf "sourcing environment from: ${envfile} \n" [ -e ${esg_functions_file} ] && source ${esg_functions_file} && ((VERBOSE)) && printf "sourcing from: ${esg_functions_file} \n" || \ (echo "ERROR: Cannot locate functions file ${esg_functions_file}" && exit 1) ##### # Clojure (a powerful dialect of Lisp that supports multicore computing on the JVM and a number # of other powerful computing facilities) ##### setup_clojure() { echo echo -n "Checking for clojure >= ${clojure_min_version}" if [ -e ${clojure_install_dir} ]; then local clojure_current_version=`java -jar ${clojure_install_dir}/clojure.jar --eval 'println (str (get *clojure-version* :major)"."(get *clojure-version* :minor)"."(get *clojure-version* :incremental))' |xargs | awk '{print $3}'` check_version_helper $clojure_current_version ${clojure_min_version} [ $? == 0 ] && (( ! force_install )) && echo " [OK]" && return 0 else echo echo "No Clojure installation detected" echo echo "*****************************" echo "Setting up Clojure ${clojure_version}" echo "*****************************" echo fi # TODO Check for empty file size in distributed file # Retrieve Clojure Distribution File local clojure_dist_file=${clojure_dist_url##*/} local clojure_dist_dir=$(echo ${clojure_dist_file} | awk 'gsub(/('$compress_extensions')/,"")') if [ ! -e ${clojure_install_dir} ]; then echo "Don't see Clojure distribution directory ${clojure_install_dir}" wget -O "${install_prefix}/${clojure_dist_file}" ${clojure_dist_url} #[ $? != 0 ] && echo " ERROR: Could not download Clojure: ${clojure_dist_file}" && popd && checked_done 1 echo "Unpacking ${clojure_dist_file}..." unzip -q "${install_prefix}/${clojure_dist_file}" -d ${install_prefix} mv "${install_prefix}/${clojure_dist_dir}" ${clojure_install_dir} chmod 755 ${clojure_install_dir} #[ $? != 0 ] && echo " ERROR: Could not extract Clojure: ${clojure_dist_file}" && popd && checked_done 1 cd ${clojure_install_dir} ant fi # Add Clojure home to environment and install manifest write_clojure_env write_clojure_install_log_entry # Remove Clojure Distribution File if [ -e "${install_prefix}/${clojure_dist_file}" ]; then rm "${install_prefix}/${clojure_dist_file}" fi } write_clojure_env() { echo "export CLOJURE_HOME=${clojure_install_dir}" >> ${envfile} dedup ${envfile} && source ${envfile} return 0 } write_clojure_install_log_entry() { local entry="$(date ${date_format}) esg-compute-languages:clojure=${clojure_version} ${clojure_install_dir}" echo ${entry} >> ${install_manifest} dedup ${install_manifest} return 0 } clean_clojure() { doit="N" if [ -e ${clojure_install_dir} ]; then read -e -p "remove compute language Clojure? (${clojure_install_dir}) [y/N]: " doit if [ "doit" = "Y" ] || [ "$doit" = "y" ]; then echo "removing ${clojure_install_dir}" rm -rf ${clojure_install_dir} [ $? != 0 ] && echo "ERROR: Unable to remove ${clojure_install_dir}" remove_env CLOJURE_HOME remove_install_log_entry clojure fi fi } ##### # Scala (both functional and object-oriented, Scala integrates well with Java and provides support # for concurrency and scalability) ##### setup_scala() { echo echo -n "Checking for scala >= ${scala_min_version}" if [ -e ${scala_install_dir} ]; then local scala_current_version=$(${SCALA_HOME}/bin/scala -version | awk '{print $5}') check_version_helper $scala_current_version ${scala_min_version} [ $? == 0 ] && (( ! force_install )) && echo " [OK]" && return 0 else echo echo "No Scala installation detected" fi echo echo "*****************************" echo "Setting up Scala ${scala_version}" echo "*****************************" echo # TODO Check for existing Scala installation, ask if backup desired # TODO Check for empty file size when downloaded # Retrieve Scala local scala_dist_file=${scala_dist_url##*/} # strip off .tar.gz at the end local scala_dist_dir=$(echo ${scala_dist_file} | awk 'gsub(/('$compress_extensions')/,"")') if [ ! -e ${scala_install_dir} ]; then echo "Don't see Scala distribution directory ${scala_dist_dir}" if [ ! -e "${install_prefix}/${scala_dist_file}" ]; then echo "Don't see Scala distribution file ${scala_dist_file} either" echo "Downloading Scala from ${scala_dist_url}" wget -O ${scala_dist_file} ${scala_dist_url} #[ $? != 0 ] && echo " ERROR: Could not download Scala:${scala_dist_file}" && popd && checked_done 1 echo "Unpacking ${scala_dist_file}..." tar xzf ${scala_dist_file} -C "${install_prefix}/" mv "${install_prefix}/${scala_dist_dir}" ${scala_install_dir} #[ $? != 0 ] && echo " ERROR: Could not extract OpenSSL: ${openssl_dist_file}" && popd && checked_done 1 fi fi # If directory does not exist but distribution archive does, unpack and continue if [ -e "${install_prefix}/${scala_dist_file}" ] && [ ! -e ${scala_install_dir} ]; then echo "unpacking ${scala_dist_file}..." tar xzf ${scala_dist_file} -C "${install_prefix}/" mv "${install_prefix}/${scala_dist_dir}" ${scala_install_dir} fi # Add Scala home to environment and install manifest write_scala_env write_scala_install_log_entry # The Scala distribution we are obtaining contains scala as an executable in its bin/ # subdirectory. No further action is needed if the file is unpacked correctly, though # some error-checking will be added here in case there are other issues. if [ -e ${scala_dist_file} ]; then rm ${scala_dist_file} fi } write_scala_env() { echo "export SCALA_HOME=${scala_install_dir}" >> ${envfile} # TODO Add prefix_to_path to esg-functions # prefix_to_path PATH ${scala_install_dir}/bin >> ${envfile} dedup ${envfile} && source ${envfile} return 0 } write_scala_install_log_entry() { local entry="$(date ${date_format}) esg-compute-languages:scala=${scala_version} ${scala_install_dir}" echo ${entry} >> ${install_manifest} dedup ${install_manifest} return 0 } clean_scala() { doit="N" if [ -e ${scala_install_dir}/bin/scala ]; then read -e -p "remove compute language Scala? (${scala_install_dir}) [y/N]: " doit if [ "doit" = "Y" ] || [ "$doit" = "y" ]; then echo "removing ${scala_install_dir}" rm -rf ${scala_install_dir} [ $? != 0 ] && echo "ERROR: Unable to remove ${scala_install_dir}" remove_env SCALA_HOME remove_install_log_entry scala fi fi } ##### # Core Compute Language Methods - Call all setup methods, or uninstall all ##### setup_compute_languages() { echo echo "-------------------------------------------" echo "Installation of ESGF Node Compute Languages" echo "-------------------------------------------" echo # Install Scala setup_scala # Install Clojure setup_clojure } clean_compute_languages() { echo echo "-----------------------------------" echo "Uninstalling ESGF Compute Languages" echo "-----------------------------------" echo # Uninstalling Scala clean_scala # Uninstalling Clojure clean_clojure } if [[ "$BASH_SOURCE" == "$0" ]] then echo echo "----- Setting Up Compute Languages -----" setup_compute_languages fi