#! /bin/bash DEBUG=${DEBUG:-0} VERBOSE=${VERBOSE:-0} devel=${devel:-0} envfile="/etc/esg.env" [ -e "${envfile}" ] && source ${envfile} && ((VERBOSE)) && printf "sourcing environment from: ${envfile} \n" runshell() { printf "Welcome, $(whoami) to the ESGF Shell... v0.0.1 - by Gavin M. Bell (gavin@llnl.gov)" local color_capable=$(sed -n -e '/[0-9]/p' <<< $(tput colors)) if [[ ${color_capable} ]]; then printf " \033[01;31m __ _ ___ ___ __ _ / _| ___ | |__ \033[0m \033[01;33m / _ \/ __| / _ || |_ _____ / __|| _ \ | __/\__ \| (_| || _||_____|\__ \| | | |\033[0m \033[01;32m \___||___/ \__, ||_| |___/|_| |_| |___/ \033[0m " else printf " __ _ ___ ___ __ _ / _| ___ | |__ / _ \/ __| / _ || |_ _____ / __|| _ \ | __/\__ \| (_| || _||_____|\__ \| | | | \___||___/ \__, ||_| |___/|_| |_| |___/ " fi local my_classpath=$(build_jarpath ${devel}) debug_print "java -cp ${my_classpath} esg.common.shell.ESGFShell $@" java -cp ${my_classpath} esg.common.shell.ESGFShell $@ echo "Goodbye :-)" } build_jarpath() { local devel=${1:-0} local paths if ((devel)); then paths[0]="$HOME/projects/esgf-node-manager/lib" paths[1]="$HOME/projects/esgf-idp/lib" paths[2]="$HOME/projects/esg-search/lib" else paths[0]=${CATALINA_HOME:-/usr/local/tomcat}/webapps/esgf-node-manager/WEB-INF/lib paths[1]=${CATALINA_HOME:-/usr/local/tomcat}/webapps/esgf-idp/WEB-INF/lib paths[2]=${CATALINA_HOME:-/usr/local/tomcat}/webapps/esg-search/WEB-INF/lib fi local IFS=" :" local i=0 local f for libdir in ${paths[@]}; do unset IFS for jar in $(find $libdir | grep .jar | grep -v sources | grep -v javadoc | grep -v .md5); do f+=$(printf "${jar##*/}:$i:$jar ") done ((i++)) done f=$(echo ${f} | awk 'BEGIN {RS = " "; FS = ":"} !($1 in a) {a[$1];print $3}' | xargs | sed -n 's/ /:/gp') echo ${paths[0]%/*}/$( ((devel == 1)) && echo "build" || echo "classes"):${paths[1]%/*}/$( ((devel == 1)) && echo "build" || echo "classes"):$f } ############################################ # Check for server update... ############################################ get_latest() { esg_dist_url=http://198.128.245.140/dist$( ((devel == 1)) && echo "/devel" || echo "") script_install_dir=${install_prefix}/bin mkdir -p ${script_install_dir} pushd $script_install_dir >& /dev/null #Get files local fetch_file=esg-node local ret verbose_print "Checking...." checked_get ${esg_dist_url}/esgf-installer/${fetch_file} ret=$? ((ret == 1)) && echo "ESGF Node Shell script (${fetch_file}) already up-to-date" ((ret == 0)) && echo "Updated ESGF Node Shell script from PCMDI's ESGF distribution site at LLNL" (( ret > 1 )) && popd >& /dev/null && return 1 chmod 755 ${fetch_file} popd >& /dev/null } check_for_update() { local local_file local remote_file if (( $# == 1 )); then remote_file=${1} local_file=$(readlink -f ${1##*/}) elif (( $# == 2 )); then local_file=${1} remote_file=${2} else echo "function \"checked_get\": Called with incorrect number of args! (fatal)" exit 1 fi [ ! -e ${local_file} ] && echo " WARNING: Could not find local file ${local_file}" && return 0 [ ! -x ${local_file} ] && echo " WARNING: local file ${local_file} not executible" && chmod 755 ${local_file} diff <(md5sum ${local_file} | tr -s " " | cut -d " " -f 1) <(curl -s ${remote_file}.md5 | tr -s " " | cut -d " " -f 1) >& /dev/null (( $? != 0 )) && echo " Update Available @ ${remote_file}" && return 0 return 1 } checked_get() { check_for_update $@ [ $? != 0 ] && return 1 local local_file local remote_file if (( $# == 1 )); then remote_file=${1} local_file=${1##*/} elif (( $# == 2 )); then local_file=${1} remote_file=${2} else echo "function \"checked_get\": Called with incorrect number of args! (fatal)" exit 1 fi if [ -e ${local_file} ]; then cp -v ${local_file} ${local_file}.bak chmod 600 ${local_file}.bak fi wget -O ${local_file} ${remote_file} [ $? != 0 ] && echo " ERROR: Problem pulling down [${remote_file##*/}] from esg distribution site" && return 2 diff <(md5sum ${local_file} | tr -s " " | cut -d " " -f 1) <(curl -s ${remote_file}.md5 | tr -s " " | cut -d " " -f 1) >& /dev/null [ $? != 0 ] && echo " WARNING: Could not verify this file!" && return 3 verbose_print "[VERIFIED]" return 0 } self_verify() { md5sum /dev/null >& /dev/null [ $? != 0 ] && echo "Could not find program \"md5sum\". Please find program and put it in your path and try again, Sorry :-(" && exit 1 #echo "diff <(md5sum ${0} | tr -s " " | cut -d " " -f 1) <(curl ${esg_dist_url}/esgf-installer/${0##*/}.md5 | tr -s " " | cut -d " " -f 1) >& /dev/null " diff <(md5sum ${0} | tr -s " " | cut -d " " -f 1) <(curl -s ${esg_dist_url}/esgf-node-manager/${0##*/}.md5 | tr -s " " | cut -d " " -f 1) >& /dev/null [ $? != 0 ] && return 3 verbose_print "[VERIFIED]" return 0 } ############################################ # Utils ############################################ verbose_print() { ((VERBOSE)) && echo $@; return 0; } debug_print() { ((DEBUG)) && echo $@; return 0; } usage() { printf " usage: ${0} [--help] \n" exit 1 } ############################################ # Main ############################################ while [ -n "$1" ]; do case $1 in -v | --version) echo "Earth Systems Grid Federation (http://esgf.org)" echo "ESGF Node Shell (esgf-sh)" echo "" exit 0 ;; --verbose) VERBOSE=1; ;; --debug) DEBUG=1; ;; --devel) devel=1; ;; *) echo "unknown switch [$1]" exit 1 ;; esac shift done #self_verify #(( $? > 0 )) && printf "WARNING: $0 could not be verified!! \n(This file, $(readlink -f ${0}), may have been tampered with or there is a newer version posted at the distribution server.\nPlease re-fetch this script.)\n\n" && exit 1 #echo "checking for updates for the ESGF Node Shell" if (($# == 1)) && [ "$1" = "--help" ]; then usage else #get_latest runshell $@ fi #don't source me money grip... exit 0