Ticket #6888: sage-env.patch

File sage-env.patch, 2.5 KB (added by sbarthelemy, 4 years ago)
  • sage-env

    old new  
    2222#  
    2323########################################################################## 
    2424 
    25  
     25# GUESS SAGE_ROOT from pwd 
    2626SAVEDIR="`pwd`" 
    27  
    28 if [ "$SAGE_ROOT" = "" ]; then 
    29     if [ -f sage -a -d spkg ]; then 
    30        SAGE_ROOT="`pwd`" 
    31        export SAGE_ROOT 
     27if [ -f sage -a -d spkg ]; then 
     28    GUESSED_SAGE_ROOT="`pwd`" 
     29else  
     30    if [ -f ../../sage -a -d ../../spkg ]; then 
     31        cd ../../ 
     32        GUESSED_SAGE_ROOT="`pwd`" 
    3233    else 
    33        if [ -f ../../sage -a -d ../../spkg ]; then 
    34            cd ../../ 
    35            SAGE_ROOT="`pwd`" 
    36            export SAGE_ROOT 
    37        else 
    38            echo "You must set the SAGE_ROOT environment variable or" 
    39            echo "run this script from the SAGE_ROOT or " 
    40            echo "SAGE_ROOT/local/bin/ directory." 
    41         fi 
     34        GUESSED_SAGE_ROOT="" 
    4235    fi 
    43 else 
    44     if [ -f sage -a -d spkg ]; then 
    45        if [ "$SAGE_ROOT" != "`pwd`" ]; then 
    46            echo "Warning: Attempted to overwrite SAGE_ROOT enviroment variable"              
    47        fi 
    48     else 
    49        if [ -f ../../sage -a -d ../../spkg ]; then 
    50            cd ../../ 
    51            if [ "$SAGE_ROOT" != "`pwd`" ]; then 
    52               echo "Warning: Attempted to overwrite SAGE_ROOT enviroment variable"              
    53            fi 
    54        else 
    55            echo "You must set the SAGE_ROOT environment variable or" 
    56            echo "run this script from the SAGE_ROOT or " 
    57            echo "SAGE_ROOT/local/bin/ directory."   
    58        fi 
    59     fi   
    6036fi 
    6137cd "$SAVEDIR" 
    6238 
     39 
    6340if [ "$SAGE_ROOT" = "" ]; then 
    64     echo "SAGE_ROOT must be set" 
    65     exit 1 
     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        exit 1 
     46    else 
     47        SAGE_ROOT="$GUESSED_SAGE_ROOT" 
     48        export SAGE_ROOT 
     49    fi 
     50else 
     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        exit 1 
     62    fi 
    6663fi