From 373caa4776d2111a823b2cf4f2b7f79bc5e1c66c Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Fri, 14 Sep 2018 14:47:05 +0800 Subject: Add scripts/heasoft.sh to help avoid library conflicts --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++ scripts/heasoft.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100755 scripts/heasoft.sh diff --git a/README.md b/README.md index 26740e3..88c97fb 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Installation $ make install ``` + Settings -------- Add the following settings to your shell's initialization file @@ -90,6 +91,56 @@ alias calclxfx="${CHANDRA_ACIS_BIN}/calc_lxfx_wrapper.sh" alias getlxfx="${CHANDRA_ACIS_BIN}/get_lxfx_data.sh" ``` +HEASoft Setup +------------- +To avoid the conflicts between HEASoft and system libraries, +a [wrapper script](scripts/heasoft.sh) is provided. + +```sh +$ mkdir ~/.heasoft +$ cp scripts/heasoft.sh ~/.heasoft + +# Assume that your HEASoft is installed at '~/local/heasoft/heasoft-x.xx/' +$ cd ~/local/heasoft +$ ln -s heasoft-x.xx default +$ cd default +$ ln -s x86_64-unknown-linux-gnu-libc* PORTAL +``` + +Then add the following `heainit()` shell function: +```sh +heainit() { + local ld_lib_bak i tool + local wrapper="${HOME}/.heasoft/heasoft.sh" + local wrapper_dir=$(dirname ${wrapper}) + local wrapper_name=$(basename ${wrapper}) + if [ -z "${HEADAS}" ]; then + ld_lib_bak=${LD_LIBRARY_PATH} + export HEADAS="${HOME}/local/heasoft/default/PORTAL" + source ${HEADAS}/headas-init.sh + export LD_LIBRARY_PATH=${ld_lib_bak} + export PATH="${wrapper_dir}:${PATH}" + + if [ ! -f "${wrapper}" ]; then + echo "ERROR: wrapper '${wrapper}' not found!" + return + fi + chmod u=rwx ${wrapper} + + echo "Initializing HEASoft from ${HEADAS} ..." + for i in ${HEADAS}/bin/*; do + tool=$(basename $i) + ln -sf ${wrapper_name} ${wrapper_dir}/${tool} + done + rehash + + echo "HEASoft initialized." + else + echo "HEASoft already initialized from: ${HEADAS}" + fi +} +``` + Usage ----- diff --git a/scripts/heasoft.sh b/scripts/heasoft.sh new file mode 100755 index 0000000..54e295b --- /dev/null +++ b/scripts/heasoft.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# +# A wrapper script for the HEASoft tools, to avoid the annoying +# conflicts between system libraries and the HEASoft bundled +# libraries due to the '$LD_LIBRARY_PATH' settings. +# +# This wrapper is inspired by CIAO. +# +# Weitian LI +# Created: 2013-05-18 +# Updated: 2018-05-16 +# +# +# Setup: +# ------------------------------------------------------------------------ +# 1. Copy this wrapper to '~/.heasoft/heasoft.sh'. +# 2. Add the following shell function to your shell config file. +# NOTE: edit 'HEADAS' to match your case. +# +# Shell configuration: +# ------------------------------------------------------------------------ +# heainit() { +# local ld_lib_bak i tool +# local wrapper="${HOME}/.heasoft/heasoft.sh" +# local wrapper_dir=$(dirname ${wrapper}) +# local wrapper_name=$(basename ${wrapper}) +# if [ -z "${HEADAS}" ]; then +# ld_lib_bak=${LD_LIBRARY_PATH} +# export HEADAS="${HOME}/local/heasoft/default/PORTAL" +# source ${HEADAS}/headas-init.sh +# export LD_LIBRARY_PATH=${ld_lib_bak} +# export PATH="${wrapper_dir}:${PATH}" +# +# if [ ! -f "${wrapper}" ]; then +# echo "ERROR: wrapper '${wrapper}' not found!" +# return +# fi +# chmod u=rwx ${wrapper} +# +# echo "Initializing HEASoft from ${HEADAS} ..." +# for i in ${HEADAS}/bin/*; do +# tool=$(basename $i) +# ln -sf ${wrapper_name} ${wrapper_dir}/${tool} +# done +# rehash +# +# echo "HEASoft initialized." +# else +# echo "HEASoft already initialized from: ${HEADAS}" +# fi +# } +# ------------------------------------------------------------------------ + +TOOL="${0##*/}" +BIN_PATH="${HEADAS}/bin" +LD_LIBRARY_PATH="${HEADAS}/lib" + +if [ -z "${HEADAS}" ]; then + echo "ERROR: environment variable 'HEADAS' not set!" >&2 + exit 1 +elif [ -x "${BIN_PATH}/${TOOL}" ]; then + export LD_LIBRARY_PATH + exec ${BIN_PATH}/${TOOL} "$@" +else + echo "ERROR: tool '${TOOL}' not found in ${BIN_PATH}!" >&2 + exit 2 +fi + -- cgit v1.2.2