From a712a7c40b65f71def34d0d8e3b86ad0c98f7049 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Tue, 26 Mar 2024 13:35:38 -0500 Subject: [PATCH] Fix bash script sourcing with symbolic links --- swbundle/add_coastlines.sh | 4 +-- swbundle/add_colormap.sh | 4 +-- swbundle/convert_grids_conf_to_yaml.sh | 4 +-- swbundle/download_pyspectral_data.sh | 4 +-- swbundle/env.sh | 11 +------- swbundle/geo2grid.sh | 4 +-- swbundle/gtiff2kmz.sh | 4 +-- swbundle/gtiff2mp4.sh | 4 +-- swbundle/hdf5_backend.sh | 39 -------------------------- swbundle/overlay.sh | 4 +-- swbundle/p2g_compare.sh | 4 +-- swbundle/p2g_grid_helper.sh | 2 +- swbundle/polar2grid.sh | 4 +-- swbundle/reproject_goes.sh | 4 +-- 14 files changed, 13 insertions(+), 83 deletions(-) delete mode 100755 swbundle/hdf5_backend.sh diff --git a/swbundle/add_coastlines.sh b/swbundle/add_coastlines.sh index 38e1c66c..1759350b 100755 --- a/swbundle/add_coastlines.sh +++ b/swbundle/add_coastlines.sh @@ -28,9 +28,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/add_colormap.sh b/swbundle/add_colormap.sh index d2588db1..e29987ce 100755 --- a/swbundle/add_colormap.sh +++ b/swbundle/add_colormap.sh @@ -28,9 +28,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/convert_grids_conf_to_yaml.sh b/swbundle/convert_grids_conf_to_yaml.sh index a38fa150..40cb1b3c 100755 --- a/swbundle/convert_grids_conf_to_yaml.sh +++ b/swbundle/convert_grids_conf_to_yaml.sh @@ -21,9 +21,7 @@ # input into another program. # Documentation: http://www.ssec.wisc.edu/software/polar2grid/ -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/download_pyspectral_data.sh b/swbundle/download_pyspectral_data.sh index 5e882431..1fe5f697 100755 --- a/swbundle/download_pyspectral_data.sh +++ b/swbundle/download_pyspectral_data.sh @@ -28,9 +28,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/env.sh b/swbundle/env.sh index 3d9e4b0d..67bbd6a5 100644 --- a/swbundle/env.sh +++ b/swbundle/env.sh @@ -30,16 +30,7 @@ # david.hoese@ssec.wisc.edu # where are we? -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ]; do - NEWSRC="$(readlink "$SOURCE")" - if [ ! -e "$NEWSRC" ]; then - # probably a relative link - NEWSRC="$(cd $(dirname "$SOURCE"); pwd)/$NEWSRC" - fi - SOURCE=$NEWSRC -done -THIS_SCRIPT_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +THIS_SCRIPT_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" P2G_CONDA_BASE="${THIS_SCRIPT_HOME}/libexec/python_runtime" P2G_METADATA="${P2G_CONDA_BASE}/lib/python*/site-packages/polar2grid-*.dist-info/METADATA" METADATA_CHECKSUM=$(${P2G_CONDA_BASE}/bin/openssl sha256 $P2G_METADATA) diff --git a/swbundle/geo2grid.sh b/swbundle/geo2grid.sh index 18609f52..dda408b0 100755 --- a/swbundle/geo2grid.sh +++ b/swbundle/geo2grid.sh @@ -28,9 +28,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/gtiff2kmz.sh b/swbundle/gtiff2kmz.sh index ec2db013..15c4e4ec 100755 --- a/swbundle/gtiff2kmz.sh +++ b/swbundle/gtiff2kmz.sh @@ -29,9 +29,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/gtiff2mp4.sh b/swbundle/gtiff2mp4.sh index e072718a..cc194bbf 100755 --- a/swbundle/gtiff2mp4.sh +++ b/swbundle/gtiff2mp4.sh @@ -29,9 +29,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/hdf5_backend.sh b/swbundle/hdf5_backend.sh deleted file mode 100755 index cd2cc11c..00000000 --- a/swbundle/hdf5_backend.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# encoding: utf-8 -# Copyright (C) 2014 Space Science and Engineering Center (SSEC), -# University of Wisconsin-Madison. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# This file is part of the polar2grid software package. Polar2grid takes -# satellite observation data, remaps it, and writes it to a file format for -# input into another program. -# Documentation: http://www.ssec.wisc.edu/software/polar2grid/ -# -# Written by David Hoese December 2014 -# University of Wisconsin-Madison -# Space Science and Engineering Center -# 1225 West Dayton Street -# Madison, WI 53706 -# david.hoese@ssec.wisc.edu - -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" - -# Setup necessary environments -# __SWBUNDLE_ENVIRONMENT_INJECTION__ - -# Call the python module to do the processing, passing all arguments -${P2G_SHELLB3_DIR}/bin/python -m polar2grid.hdf5_backend -vv $@ diff --git a/swbundle/overlay.sh b/swbundle/overlay.sh index 954dd649..039a3fd3 100755 --- a/swbundle/overlay.sh +++ b/swbundle/overlay.sh @@ -28,9 +28,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/p2g_compare.sh b/swbundle/p2g_compare.sh index d5af025e..d260fa1f 100755 --- a/swbundle/p2g_compare.sh +++ b/swbundle/p2g_compare.sh @@ -22,9 +22,7 @@ # input into another program. # Documentation: http://www.ssec.wisc.edu/software/polar2grid/ -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/p2g_grid_helper.sh b/swbundle/p2g_grid_helper.sh index 36d6d53a..d38d72d4 100755 --- a/swbundle/p2g_grid_helper.sh +++ b/swbundle/p2g_grid_helper.sh @@ -31,7 +31,7 @@ # david.hoese@ssec.wisc.edu if [ -z "$POLAR2GRID_HOME" ]; then - export POLAR2GRID_HOME="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" + export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" fi # Setup necessary environments diff --git a/swbundle/polar2grid.sh b/swbundle/polar2grid.sh index 7f84d044..25c5a778 100755 --- a/swbundle/polar2grid.sh +++ b/swbundle/polar2grid.sh @@ -28,9 +28,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__ diff --git a/swbundle/reproject_goes.sh b/swbundle/reproject_goes.sh index 00690707..b30efd9b 100755 --- a/swbundle/reproject_goes.sh +++ b/swbundle/reproject_goes.sh @@ -29,9 +29,7 @@ # Madison, WI 53706 # david.hoese@ssec.wisc.edu -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -export POLAR2GRID_HOME="$( cd -P "$( dirname "$SOURCE" )" && cd .. && pwd )" +export POLAR2GRID_HOME="$( cd -P "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" && cd .. && pwd )" # Setup necessary environments # __SWBUNDLE_ENVIRONMENT_INJECTION__