From 252372d96e8f40f0766ed7623a48d60810c50146 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 2 May 2022 14:02:21 -0700 Subject: [PATCH 1/2] SAGE_ROOT/sage: Unconditionally determine SAGE_ROOT from $0; no longer invite to edit this file --- sage | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sage b/sage index 3fad670c839..1e31cbcb50a 100755 --- a/sage +++ b/sage @@ -17,19 +17,15 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# Set SAGE_ROOT to the location of the sage install, i.e. the directory -# containing this shell script. If unset, we will try to figure it out -# automatically. -#SAGE_ROOT=/path/to/sage-version - # Resolve all symbolic links in a filename. This more or less behaves # like "readlink -f" except that it does not convert the filename to an # absolute path (a relative path remains relative), nor does it treat # "." or ".." specially. # # WARNING: this function is copy/pasted from src/bin/sage-env, and -# deserves to be factored out at some point in the future. In the -# meantime however the two should be kept synchronized. +# would deserve to be factored out if we could -- but we need it here so +# we can actually find other files in SAGE_ROOT! +# The copies should be kept synchronized. resolvelinks() { # $in is what still needs to be converted (normally has no starting slash) in="$1" @@ -104,7 +100,14 @@ resolvelinks() { echo "$out" } -# If SAGE_ROOT is not given, find it out from $0 +# Determine SAGE_ROOT from $0. This is so we can find the src/bin/sage script. +# +# This uses "resolvelinks" to support the use case of symlinking this script +# into a directory that is in PATH, which was longstanding recommended practice. +# +# (The updated README.md and installation manual from Trac #33787 recommend to +# symlink the installed version of the src/bin/sage script instead.) + if [ -z "$SAGE_ROOT" ]; then # Get the path to $0 (this shell script) with all symbolic links # resolved From 01caa38de213af25a1ba6501e5419d35ca711561 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 10 May 2022 16:31:37 -0700 Subject: [PATCH 2/2] SAGE_ROOT/sage: Actually unconditionally determine SAGE_ROOT from $0 --- sage | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sage b/sage index 1e31cbcb50a..10b53023fbe 100755 --- a/sage +++ b/sage @@ -108,15 +108,12 @@ resolvelinks() { # (The updated README.md and installation manual from Trac #33787 recommend to # symlink the installed version of the src/bin/sage script instead.) -if [ -z "$SAGE_ROOT" ]; then - # Get the path to $0 (this shell script) with all symbolic links - # resolved - SAGE_ROOT=`resolvelinks "$0"` || \ +# Get the path to $0 (this shell script) with all symbolic links resolved +SAGE_ROOT=`resolvelinks "$0"` || \ SAGE_ROOT="$0" - # Get the directory component - SAGE_ROOT="${SAGE_ROOT%/*}" -fi +# Get the directory component +SAGE_ROOT="${SAGE_ROOT%/*}" # Make SAGE_ROOT absolute SAGE_ROOT=`cd "$SAGE_ROOT" && pwd -P`