From 0aebb13088c486c5b2db314c9f4b9d7ac2da4a19 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Thu, 26 May 2016 14:09:40 -0700 Subject: [PATCH] fits scripts should resolve symlinks before loading relative paths --- fits-env.sh | 18 ++++++++++++++++-- fits.sh | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/fits-env.sh b/fits-env.sh index 3d686e05..a5caf246 100755 --- a/fits-env.sh +++ b/fits-env.sh @@ -3,8 +3,22 @@ # Sets up the environment for launching a FITS instance via # either the fits.sh launcher, or the fits-ngserver.sh Nailgun server -#FITS_HOME=`dirname "$0"` -FITS_HOME=`echo "$0" | sed 's,/[^/]*$,,'` +FITS_ENV_SCRIPT="$0" + +# Resolve symlinks to this script +while [ -h "$FITS_ENV_SCRIPT" ] ; do + ls=`ls -ld "$FITS_ENV_SCRIPT"` + # Drop everything prior to -> + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + FITS_ENV_SCRIPT="$link" + else + FITS_ENV_SCRIPT=`dirname "$FITS_ENV_SCRIPT"`/"$link" + fi +done + +FITS_HOME=`dirname $FITS_ENV_SCRIPT` + export FITS_HOME # Uncomment the following line if you want "file utility" to dereference and follow symlinks. diff --git a/fits.sh b/fits.sh index 09127810..7e22cec0 100755 --- a/fits.sh +++ b/fits.sh @@ -1,6 +1,20 @@ -#!/bin/bash +#!/usr/bin/env bash -. "$(dirname $BASH_SOURCE)/fits-env.sh" +FITS_SCRIPT="$0" + +# Resolve symlinks to this script +while [ -h "$FITS_SCRIPT" ] ; do + ls=`ls -ld "$FITS_SCRIPT"` + # Drop everything prior to -> + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + FITS_SCRIPT="$link" + else + FITS_SCRIPT=`dirname "$FITS_SCRIPT"`/"$link" + fi +done + +. "$(dirname $FITS_SCRIPT)/fits-env.sh" cmd="java -classpath \"$APPCLASSPATH\" edu.harvard.hul.ois.fits.Fits $args"