Ticket #5852: 5852_scripts.patch

File 5852_scripts.patch, 3.7 KB (added by jdemeyer, 10 years ago)

Patch for local/bin/sage-env, SCRIPTS repository

  • sage-env

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1314106385 -7200
    # Node ID 1969980f86d56e0c96a31b74e07a7866c9a99dd8
    # Parent  828672a64b0d8a16e36525dd309a4c8a6d18753f
    Clean up SAGE_ROOT detecting code, resolve symbolic links
    
    diff --git a/sage-env b/sage-env
    a b  
    2222#
    2323##########################################################################
    2424
    25 # GUESS SAGE_ROOT from pwd
    26 SAVEDIR="`pwd`"
    27 if [ -f sage -a -d spkg ]; then
    28     GUESSED_SAGE_ROOT="`pwd`"
    29 else
    30     if [ -f ../../sage -a -d ../../spkg ]; then
    31         cd ../../
    32         GUESSED_SAGE_ROOT="`pwd`"
    33     else
    34         GUESSED_SAGE_ROOT=""
    35     fi
     25
     26# New value for SAGE_ROOT: either SAGE_ROOT (if given)
     27# or a guessed value based on pwd.
     28if [ -n "$SAGE_ROOT" ]; then
     29    NEW_SAGE_ROOT="$SAGE_ROOT"
     30elif [ -f sage -a -d spkg ]; then
     31    NEW_SAGE_ROOT="."
     32elif [ -f ../../sage -a -d ../../spkg ]; then
     33    NEW_SAGE_ROOT="../.."
     34else
     35    # No idea what SAGE_ROOT should be...
     36    echo >&2 "Error: You must set the SAGE_ROOT environment variable or run this"
     37    echo >&2 "script from the SAGE_ROOT or SAGE_ROOT/local/bin/ directory."
     38    return 1
    3639fi
    37 cd "$SAVEDIR"
    3840
     41# Make NEW_SAGE_ROOT absolute
     42NEW_SAGE_ROOT=`cd "$NEW_SAGE_ROOT" && pwd -P`
    3943
    40 if [ "$SAGE_ROOT" = "" ]; then
    41     if [ "$GUESSED_SAGE_ROOT" = "" ]; then
    42         echo "Error: You must set the SAGE_ROOT environment"
    43         echo "variable or run this script from the SAGE_ROOT or "
    44         echo "SAGE_ROOT/local/bin/ directory."
    45         return 1
    46     else
    47         SAGE_ROOT="$GUESSED_SAGE_ROOT"
    48         EXPORT_SAGE_ROOT="yes"
    49     fi
     44# Sanity check NEW_SAGE_ROOT
     45if [ -f "$NEW_SAGE_ROOT/sage" -a -d "$NEW_SAGE_ROOT/spkg" ]; then
     46    :
    5047else
    51     if [ -f "$SAGE_ROOT"/sage -a -d "$SAGE_ROOT"/spkg ]; then
    52         # SAGE_ROOT points to a sage installation as expected
    53         if [ "$SAGE_ROOT" != "$GUESSED_SAGE_ROOT" ]; then
    54             echo "Warning: Attempted to overwrite SAGE_ROOT environment variable"
    55         fi
    56     else
    57         echo "Error: The SAGE_ROOT environment variable is set to"
    58         echo "a bad value. You must correct it or erase it and"
    59         echo "run this script from the SAGE_ROOT or"
    60         echo "SAGE_ROOT/local/bin/ directory." 
    61         return 1
    62     fi
     48    echo >&2 "Error: SAGE_ROOT is set to a bad value:"
     49    echo >&2 "SAGE_ROOT=$SAGE_ROOT"
     50    echo >&2 "You must correct it or erase it and run this script from the SAGE_ROOT"
     51    echo >&2 "or SAGE_ROOT/local/bin/ directory."
     52    return 1
     53fi
     54
     55# Warn if NEW_SAGE_ROOT does not equal the old SAGE_ROOT
     56if [ "$SAGE_ROOT" != "$NEW_SAGE_ROOT" -a -n "$SAGE_ROOT" ]; then
     57    echo >&2 "Warning: overwriting SAGE_ROOT environment variable:"
     58    echo >&2 "Old SAGE_ROOT=$SAGE_ROOT"
     59    echo >&2 "New SAGE_ROOT=$NEW_SAGE_ROOT"
    6360fi
    6461
    6562# Don't execute the commands more than once.  Check this after
     
    7269    return 0
    7370fi
    7471
    75 if [ "$EXPORT_SAGE_ROOT" = "yes" ]; then
    76     export SAGE_ROOT
    77 fi
     72SAGE_ROOT="$NEW_SAGE_ROOT"
     73export SAGE_ROOT
     74
    7875
    7976# Call with: contains_spaces X${VAR}X
    8077# i.e., WITHOUT quotes but some character(s) around the environment variable to test.
     
    216213if [ -f "$MPLINITFILE" ]; then
    217214    MPLVERSION=`sed -n "/^__version__[ ]*=/s/[^']*'\([^']*\)'.*$/\1/p" "$MPLINITFILE"`
    218215    if [ "$MPLVERSION" != "" ]; then
    219         MPLCONFIGDIR="$DOT_SAGE/matplotlib-$MPLVERSION"
     216        MPLCONFIGDIR="$DOT_SAGE/matplotlib-$MPLVERSION"
    220217    else
    221         # MPLVERSION is empty, so no version found.
    222         MPLCONFIGDIR="$DOT_SAGE/matplotlib"
     218        # MPLVERSION is empty, so no version found.
     219        MPLCONFIGDIR="$DOT_SAGE/matplotlib"
    223220    fi
    224221    export MPLCONFIGDIR
    225222    # Create the directory, because matplotlib doesn't seem to be happy otherwise.