Ticket #12479: 12479_clean_sage_spkg.patch

File 12479_clean_sage_spkg.patch, 22.1 KB (added by jdemeyer, 9 years ago)
  • spkg/bin/sage

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1330468085 -3600
    # Node ID f923f09355e3dd07f00eb5b208e9f716fcf28235
    # Parent  a0bd50ccc9c02362f88d13656dd0b19523d9002e
    Clean up sage-spkg
    
    diff --git a/spkg/bin/sage b/spkg/bin/sage
    a b  
    766766fi
    767767
    768768install() {
    769    cd "$SAGE_ROOT/spkg"
    770    if [ $# -lt 2 ]; then
    771        sage-spkg
    772        exit $?
    773    fi
    774    OPT="$1"
    775    shift
    776    if [ "$1" = '-m' -o "$1" = '-s' ]; then
    777        OPT=$OPT" "$1
    778        shift
    779    fi
    780    SAGE_LOGS="$SAGE_ROOT/spkg/logs"
    781    if [ ! -d "$SAGE_LOGS" ]; then
    782        mkdir -p "$SAGE_LOGS"
    783    fi
    784    for PKG in "$@"
    785    do
    786         echo "Calling sage-spkg on '$PKG'"
    787         PKG_NAME=`echo "$PKG" | sed -e "s/\.spkg$//"`
    788         PKG_NAME=`basename "$PKG_NAME"`
    789         case "$PKG" in
    790             /*) PKG_PATH="$PKG";;
    791             *) PKG_PATH="$CUR/$PKG";;
    792         esac
    793         # Could use ./pipestatus here, but using an absolute path is safer:
    794         # (We'll have to change it anyway in case 'pipestatus' one day moves.)
    795         "$SAGE_ROOT"/spkg/pipestatus \
    796             "sage-spkg $OPT '$PKG_PATH' 2>&1" \
    797             "(trap '' SIGINT; tee -a '$SAGE_ROOT'/install.log '$SAGE_LOGS/$PKG_NAME'.log)"
    798         # Do not try to install further packages (if any) if one failed:
    799         if [[ $? -ne 0 ]]; then
    800             echo >&2 "Error: Failed to install package '$PKG_NAME'."
    801             exit 1
    802         fi
    803         shift
    804    done
    805    exit $?
     769    cd "$SAGE_ROOT/spkg"
     770    SAGE_LOGS="$SAGE_ROOT/spkg/logs"
     771    mkdir -p "$SAGE_LOGS"
     772    for PKG in "$@"
     773    do
     774        # Check for options
     775        case "$PKG" in
     776            -f) OPTF="-f"
     777                continue;;
     778            -m) OPTS="-s"
     779                echo >&2 "Warning: the -m option is deprecated since Sage 5.0.  Use -s instead."
     780                continue;;
     781            -s) OPTS="-s"
     782                continue;;
     783        esac
     784
     785        echo "Calling sage-spkg on '$PKG'"
     786        PKG_NAME=`echo "$PKG" | sed -e "s/\.spkg$//"`
     787        PKG_NAME=`basename "$PKG_NAME"`
     788        case "$PKG" in
     789            /*) PKG_PATH="$PKG";;
     790            *) PKG_PATH="$CUR/$PKG";;
     791        esac
     792        # Could use ./pipestatus here, but using an absolute path is safer:
     793        # (We'll have to change it anyway in case 'pipestatus' one day moves.)
     794        "$SAGE_ROOT"/spkg/pipestatus \
     795            "sage-spkg $OPTF $OPTS '$PKG_PATH' 2>&1" \
     796            "(trap '' SIGINT; tee -a '$SAGE_ROOT'/install.log '$SAGE_LOGS/$PKG_NAME'.log)"
     797        # Do not try to install further packages (if any) if one failed:
     798        if [ $? -ne 0 ]; then
     799            echo >&2 "Error: Failed to install package '$PKG_NAME'."
     800            exit 1
     801        fi
     802        shift
     803    done
     804    exit $?
    806805}
    807806
    808807if [ "$1" = '-optional' -o "$1" = "--optional" ]; then
     
    821820fi
    822821
    823822if [ "$1" = '-i' ]; then
    824    shift
    825    echo "Installing $@"
    826    install " " "$@"
     823    shift
     824    # If there are no further arguments, simply list all installed
     825    # packages.
     826    if [ $# -eq 0 ]; then
     827        exec sage-spkg
     828    fi
     829    install "$@"
    827830fi
    828831
    829832if [ "$1" = '-f' ]; then
    830    shift
    831    echo "Force installing $@"
    832    install -f "$@"
     833    shift
     834    # If there are no further arguments, simply list all installed
     835    # packages.
     836    if [ $# -eq 0 ]; then
     837        exec sage-spkg
     838    fi
     839    install -f "$@"
    833840fi
    834841
    835842if [ "$1" = '-pkg' -o "$1" = '-spkg' -o "$1" = "--pkg" -o "$1" = "--spkg" ]; then
  • spkg/bin/sage-spkg

    diff --git a/spkg/bin/sage-spkg b/spkg/bin/sage-spkg
    a b  
    11#!/usr/bin/env bash
    2 
    3 # William Stein, 2005-12-20 -- removed "m" option from tar,
    4 # which was seriously confusing the build process on some
    5 # (too fast?) machines, especially for mpfr.
    6 
    7 #######################################################
    8 #  Install a Sage package.  This script is
    9 #  typically invoked by giving the command
    10 #      sage -i <package name>
    112#
    12 #  A package may assume that the following environment
     3#  sage-spkg: install a Sage package
     4#
     5#  This script is typically invoked by giving the command
     6#      sage -i <options> <package name>...
     7#
     8#  Options can be:
     9#   -f: install a package even if the same version is already installed
     10#   -s: do not delete temporary build directory
     11#
     12#  A package may assume that the following environment
    1313#  variables are defined:
    1414#
    15 #      SAGE_ROOT   -- root directory of sage install
    16 #      SAGE_LOCAL  -- $SAGE_ROOT/local
    17 #      SAGE_DATA   -- $SAGE_ROOT/data
     15#      SAGE_ROOT     -- root directory of sage install
     16#      SAGE_PACKAGES -- $SAGE_ROOT/spkg
     17#      SAGE_LOCAL    -- $SAGE_ROOT/local
     18#      SAGE_DATA     -- $SAGE_ROOT/data
    1819#      LIBRARY_PATH, PYTHONPATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH
    1920#      CC, CXX, CFLAGS, CXXFLAGS, LDFLAGS, MAKE
    2021#
     
    2829#      3. Run the script in the package called spkg-install
    2930#      4. Return error 1 if anything goes wrong.
    3031#
    31 #######################################################
     32# AUTHORS:
     33#
     34# - Jeroen Demeyer (2012-02-27): #12479: big reorganization.
     35#
     36# - Volker Braun, Jeroen Demeyer (2012-01-18): #11073: remove the
     37#   spkg/base repository, move this file from local/bin/sage-spkg to
     38#   spkg/bin/sage-spkg.
     39#
     40# - William Stein, John Palmieri and others (Sage 4.8 and earlier).
     41#
     42#*****************************************************************************
     43#  Distributed under the terms of the GNU General Public License (GPL)
     44#  as published by the Free Software Foundation; either version 2 of
     45#  the License, or (at your option) any later version.
     46#                  http://www.gnu.org/licenses/
     47#*****************************************************************************
    3248
    33 no_version()
    34 {
    35     if [ -z "`echo "$1" | grep -`" ]; then
    36         echo "no version"
    37     fi
    38 }
    3949
    4050# error_msg(header, command)
    4151# This is for printing an error message if something went wrong.
     
    7282    fi
    7383fi
    7484
     85##################################################################
     86# Set environment variables
     87##################################################################
     88
    7589# The following sets environment variables for building packages.
    7690# Since this is sourced, it returns a non-zero value on errors rather
    7791# than exiting.  Using dot suggested by W. Cheung.
    7892. "$SAGE_ROOT/spkg/bin/sage-env"
    79  
     93
    8094if [ $? -ne 0 ]; then
    81     echo "Error setting environment variables by sourcing '$SAGE_ROOT/spkg/bin/sage-env';"
    82     echo "possibly contact sage-devel (see http://groups.google.com/group/sage-devel)."
     95    echo >&2 "Error setting environment variables by sourcing '$SAGE_ROOT/spkg/bin/sage-env';"
     96    echo >&2 "possibly contact sage-devel (see http://groups.google.com/group/sage-devel)."
    8397    exit 1
    8498fi
    8599
     100if [ -z "$SAGE_BUILD_DIR" ]; then
     101    export SAGE_BUILD_DIR="$SAGE_PACKAGES/build"
     102fi
     103
     104INSTALLED="$SAGE_PACKAGES/installed"
     105mkdir -p "$INSTALLED"
     106if [ $? -ne 0 ]; then
     107    echo >&2 "Error creating directory $INSTALLED."
     108    exit 1
     109fi
     110
     111
     112# Remove '.' from PYTHONPATH, which may also come from SAGE_PATH, to avoid
     113# trouble with setuptools / easy_install (cf. #10192, #10176):
     114if [ -n "$PYTHONPATH" ]; then
     115    # We also collapse multiple slashs into a single one (first substitution),
     116    # remove leading './'s and trailing '/.'s (second and third), and
     117    # remove leading, trailing and redundant ':'s (last three substitutions):
     118    new_pp=`echo ":$PYTHONPATH:" \
     119        | sed \
     120        -e 's|//*|/|g' \
     121        -e 's|:\(\./\)\{1,\}|:|g' \
     122        -e 's|\(/\.\)\{1,\}:|:|g' \
     123        -e 's|\(:\.\)\{1,\}:|:|g' \
     124        -e 's|::*|:|g' -e 's|^::*||' -e 's|::*$||'`
     125
     126    if [ "$PYTHONPATH" != "$new_pp" ]; then
     127        echo "Cleaning up PYTHONPATH:"
     128        echo "  Old: \"$PYTHONPATH\""
     129        echo "  New: \"$new_pp\""
     130        PYTHONPATH=$new_pp
     131        export PYTHONPATH # maybe redundant, but in any case safe
     132    fi
     133fi
     134
     135##################################################################
     136# Handle special command-line options
     137##################################################################
    86138if [ $# -eq 0 ]; then
    87139    echo "Currently installed packages:"
    88     ls -1 "$SAGE_PACKAGES/installed/"
     140    ls -1 "$INSTALLED"
    89141    exit 0
    90142fi
    91143
    92 # the following two options are mutually exclusive -- i.e., you
    93 # can give only one.
    94 
     144# Options have to come in a specific order,
     145# this is ensured by spkg/bin/sage.
    95146INFO=0
    96 if [ $1 = '-info' ]; then
     147if [ $1 = '--info' ]; then
    97148    INFO=1
    98149    shift
    99150fi
     
    103154    FORCE=1
    104155    shift
    105156fi
    106 export FORCE
    107157
    108158DELETE_TMP=1
    109 if [ $1 = '-s' -o $1 = '-m' ]; then
     159if [ $1 = '-s' ]; then
    110160    DELETE_TMP=0
    111161    shift
    112162fi
     
    115165    DELETE_TMP=0
    116166fi
    117167
    118 INSTALLED="$SAGE_PACKAGES/installed/"
    119 PKG_NAME=`echo "$1" | sed -e "s/\.spkg$//"`
    120 PKG_NAME=`basename "$PKG_NAME"`
     168##################################################################
     169# Figure out the package filename, download it if needed.
     170##################################################################
     171PKG_NAME=`basename "$1" | sed -e "s/\.spkg$//"`
    121172PKG_SRC="$1"
    122173PKG_BASE=`echo "$PKG_NAME" | sed -e "s/-.*//"`
    123174
    124 # check if noclobber is set and warn about it
    125 if [ $PKG_SRC == "noclobber" ]; then
    126     echo "***********************************************************"
    127     echo "* WARNING WARNING WARNING WARNING WARNING WARNING WARNING *"
    128     echo "*                                                         *"
    129     echo "* noclobber is set in .bashrc and/or .bash_profile - you  *"
    130     echo "* should consider disabling it. The Sage install should   *"
    131     echo "* continue to work, so don't worry about it too much.     *"
    132     echo "*                                                         *"
    133     echo "* WARNING WARNING WARNING WARNING WARNING WARNING WARNING *"
    134     echo "***********************************************************"
    135     exit 0
    136 fi
    137 
    138175if [ ! -f "$PKG_SRC" ]; then
    139176    if [ -f "$SAGE_PACKAGES/standard/$PKG_NAME.spkg" ]; then
    140177        PKG_SRC="$SAGE_PACKAGES/standard/$PKG_NAME.spkg"
     
    158195fi
    159196
    160197# Don't verbosely extract files from spkgs by default (#10040):
    161 
    162198if [ "$SAGE_SPKG_LIST_FILES" = "yes" ]; then
    163199    UNTAR_VERBOSE=v
    164200else
     
    167203
    168204if [ $INFO -ne 0 ]; then
    169205    if [ ! -f "$PKG_SRC" ]; then
    170         echo "Package $PKG_NAME not found"
     206        echo >&2 "Package $PKG_NAME not found"
    171207    fi
    172     bunzip2 -c "$PKG_SRC" 2>/dev/null | tar Ofx${UNTAR_VERBOSE} - $PKG_NAME/SAGE.txt 2>/dev/null
     208    bunzip2 -c "$PKG_SRC" 2>/dev/null | tar Ofx${UNTAR_VERBOSE} - $PKG_NAME/SPKG.txt 2>/dev/null
    173209    if [ $? -ne 0 ]; then
    174         tar Ofx${UNTAR_VERBOSE} "$PKG_SRC" "$PKG_NAME/SAGE.txt" 2>/dev/null
     210        tar Ofx${UNTAR_VERBOSE} "$PKG_SRC" "$PKG_NAME/SPKG.txt" 2>/dev/null
    175211    fi
    176212    echo ""
    177213    if [ $? -ne 0 ]; then
    178         echo "No file SAGE.txt in $PKG_NAME"
     214        echo >&2 "No file SPKG.txt in $PKG_NAME"
    179215        exit 1
    180216    fi
    181217    exit 0
    182218fi
    183219
    184220echo "$PKG_NAME"
    185 
    186 echo "Machine:"
    187 uname -a
     221echo "===================================================="
    188222
    189223if [ -f "$INSTALLED/$PKG_NAME" -a $FORCE -eq 0 ]; then
    190     echo "sage: $1 is already installed"
     224    echo "Package $PKG_NAME is already installed."
     225    echo "Use 'sage -f $PKG_SRC' to force a reinstallation."
     226    # Touch installed file such that "make" considers it up-to-date.
    191227    touch "$INSTALLED/$PKG_NAME"
    192228    exit 0
    193229fi
    194230
    195 if [ ! -n "$SAGE_BUILD_DIR" ]; then
    196     SAGE_BUILD_DIR="$SAGE_PACKAGES/build"
    197 fi
    198 
    199 mkdir -p "$SAGE_PACKAGES/installed"
    200 if [ $? -ne 0 ]; then
    201     echo >&2 "Error creating directory $SAGE_PACKAGES/installed."
    202     exit 1
    203 fi
     231# Make absolutely sure that we are in the build directory before doing
     232# a scary "rm -rf" below.
    204233mkdir -p "$SAGE_BUILD_DIR"
    205234if [ $? -ne 0 ]; then
    206235    echo >&2 "Error creating directory $SAGE_BUILD_DIR."
    207236    exit 1
    208237fi
    209 
    210 # Make absolutely sure that we are in the build directory before doing
    211 # a scary "rm -rf" below.
    212238cd "$SAGE_BUILD_DIR"
    213239if [ $? -ne 0 ]; then
    214240    echo >&2 "Unable to find build directory."
     
    216242fi
    217243
    218244if [ $DELETE_TMP -eq 1 ]; then
    219     echo "Deleting directories from past builds of previous/current versions of $PKG_NAME"
    220245    rm -rf "$PKG_BASE-"*
    221246else
    222247    for dir in "$PKG_BASE-"*
     
    235260fi
    236261
    237262if [ ! -f "$PKG_SRC" ]; then
    238     echo "$0: file $PKG_NAME does not exist" 
     263    echo "$0: file $PKG_NAME does not exist"
    239264    echo "Attempting to download it."
    240265    CUR=`pwd`
    241266    mkdir -p "$SAGE_PACKAGES/optional"
    242267    cd "$SAGE_PACKAGES/optional"
    243268   
    244269    FOUND_VERSION=''
    245     if [ -n "`no_version "$PKG_NAME"`" ]; then
     270    if ! echo "$PKG_NAME" | grep - >/dev/null; then
     271        # No version number found
    246272        echo "Searching for latest version of $PKG_NAME"
    247273        PKG_NAME=`sage-latest-online-package "$PKG_NAME"`
    248274        if [ $? -eq 0 ]; then
     
    278304    else
    279305        sage-download_package "$PKG_NAME"
    280306    fi
    281     if [ ! -f "$PKG_NAME.spkg" ]; then 
     307    if [ ! -f "$PKG_NAME.spkg" ]; then
    282308        echo "sage: Failed to download package $PKG_NAME from $SAGE_SERVER"
    283309        exit 1
    284310    fi
     
    286312    cd "$CUR"
    287313fi
    288314
    289 # * The -i option below to ignore checksum errors, since
    290 #   I've had problems with this on Solaris.
    291 # * The m option avoids clock skew problems.   
    292 
    293315echo "Extracting package $PKG_SRC ..."
    294316ls -l "$PKG_SRC"
    295317
     
    305327echo "Finished extraction"
    306328
    307329if [ ! -d "$PKG_NAME" ]; then
    308     echo "sage: After decompressing the directory $PKG_NAME does not exist"
    309     echo "This means that the corresponding .spkg needs to be downloaded"
    310     echo "again."
    311     if [ -n "`no_version "$PKG_NAME"`" ]; then
     330    echo >&2 "sage: After decompressing the directory $PKG_NAME does not exist"
     331    echo >&2 "This means that the corresponding .spkg needs to be downloaded"
     332    echo >&2 "again."
     333    if ! echo "$PKG_NAME" | grep - >/dev/null; then
     334        # No version number found
    312335        echo "Searching for latest version of $PKG_NAME"
    313336        PKG_NAME=`sage-latest-online-package "$PKG_NAME"`
    314337        if [ $? -eq 0 ]; then
     
    320343    fi
    321344    sage-download_package "$PKG_NAME"
    322345    echo `pwd`
    323     bunzip2 -c "$PKG_NAME.spkg"  | tar fx${UNTAR_VERBOSE} - 
     346    bunzip2 -c "$PKG_NAME.spkg"  | tar fx${UNTAR_VERBOSE} -
    324347    if [ ! -d "$PKG_NAME.spkg" ]; then
    325348        tar fx${UNTAR_VERBOSE} "$PKG_NAME.spkg"
    326349    fi
     
    330353    fi
    331354fi
    332355
     356##################################################################
     357# The package has been extracted, prepare for installation
     358##################################################################
     359
    333360cd "$PKG_NAME"
     361
     362# When there is no spkg-install, assume the "spkg" is a tarball not
     363# specifically made for Sage.  Since we want it to be as easy as
     364# possible to install such a package, we "guess" spkg-install.
    334365if [ ! -f spkg-install ]; then
    335     echo "#!/usr/bin/env bash" > spkg-install
    336     echo "" >> spkg-install
    337     if [ -f setup.py ]; then
    338         echo "python setup.py install" >> spkg-install
     366    echo '#!/usr/bin/env bash' > spkg-install
     367    if [ -x configure ]; then
     368        echo './configure --prefix="$SAGE_LOCAL" && make && make install' >> spkg-install
     369    elif [ -f setup.py ]; then
     370        echo 'python setup.py install' >> spkg-install
    339371    else
    340         if [ -f configure ]; then
    341             echo "./configure --prefix=\$SAGE_ROOT/local/" >> spkg-install
    342             echo "make" >> spkg-install
    343             echo "make install" >> spkg-install
    344         else
    345             echo "There is no spkg-install script, no setup.py, and no configure script,"
    346             echo "so I do not know how to install $PKG_SRC."
    347             exit 1
    348         fi
     372        echo >&2 "Error: There is no spkg-install script, no setup.py, and no configure"
     373        echo >&2 "script, so I do not know how to install $PKG_SRC."
     374        exit 1
    349375    fi
     376    chmod +x spkg-install
    350377fi
    351378
    352 chmod +x spkg-install
    353 
    354 # Remove '.' from PYTHONPATH, which may also come from SAGE_PATH, to avoid
    355 # trouble with setuptools / easy_install (cf. #10192, #10176):
    356 if [ -n "$PYTHONPATH" ]; then
    357     # We also collapse multiple slashs into a single one (first substitution),
    358     # remove leading './'s and trailing '/.'s (second and third), and
    359     # remove leading, trailing and redundant ':'s (last three substitutions):
    360     new_pp=`echo ":$PYTHONPATH:" \
    361         | sed \
    362         -e 's|//*|/|g' \
    363         -e 's|:\(\./\)\{1,\}|:|g' \
    364         -e 's|\(/\.\)\{1,\}:|:|g' \
    365         -e 's|\(:\.\)\{1,\}:|:|g' \
    366         -e 's|::*|:|g' -e 's|^::*||' -e 's|::*$||'`
    367 
    368     if [ "$PYTHONPATH" != "$new_pp" ]; then
    369         echo "Cleaning up PYTHONPATH:"
    370         echo "  Old: \"$PYTHONPATH\""
    371         echo "  New: \"$new_pp\""
    372         PYTHONPATH=$new_pp
    373         export PYTHONPATH # maybe redundant, but in any case safe
     379# If spkg-install is a Python script (i.e. the first line of the file
     380# contains "python"), verify that Python has already been installed.
     381if head -1 spkg-install | grep python >/dev/null; then
     382    # If there is no Python installed in local/bin, exit with an error.
     383    if [ ! -x "$SAGE_LOCAL"/bin/python ]; then
     384         echo >&2 "Error: The spkg-install script is written in Python, but the Python"
     385         echo >&2 "package is not yet installed in Sage.  This is a bug in the file"
     386         echo >&2 "$SAGE_ROOT/spkg/standard/deps"
     387         exit 1
    374388    fi
    375389fi
    376390
    377391echo "****************************************************"
    378 echo "Host system"
    379 echo "uname -a:"
     392echo "Host system:"
    380393uname -a
    381 if [ $? -ne 0 ]; then
    382     echo "Unable to determine host system information."
    383 fi
     394echo "****************************************************"
     395echo "C compiler: $CC"
     396echo "C compiler version:"
     397$CC -v
    384398echo "****************************************************"
    385399
    386 echo "****************************************************"
    387 echo "CC Version"
    388 echo "$CC -v"
    389 $CC -v
     400##################################################################
     401# Actually install
     402##################################################################
     403if [ ! -x spkg-install ]; then
     404    echo >&2 "WARNING: spkg-install is not executable, making it executable"
     405    chmod +x spkg-install
     406fi
     407time ./spkg-install
     408
    390409if [ $? -ne 0 ]; then
    391     echo "Unable to determine C compiler version."
     410    error_msg "Error installing package $PKG_NAME" "make"
     411    exit 1
    392412fi
    393 echo "****************************************************"
     413
     414echo "Successfully installed $PKG_NAME"
     415
     416if [ "$SAGE_CHECK" = "yes" ]; then
     417    if [ -f spkg-check ]; then
     418        echo "Running the test suite for $PKG_NAME..."
     419        if [ ! -x spkg-check ]; then
     420            echo >&2 "WARNING: spkg-check is not executable, making it executable"
     421            chmod +x spkg-check
     422        fi
     423        time ./spkg-check
     424        if [ $? -ne 0 ]; then
     425            error_msg "Error testing package $PKG_NAME" "make check"
     426            exit 1
     427        fi
     428        TEST_SUITE_RESULT="passed"
     429    else
     430        echo "Package $PKG_NAME has no test suite."
     431        TEST_SUITE_RESULT="not available"
     432    fi
     433fi
     434
     435# Mark that the new package has been installed (and tested, if
     436# applicable).
     437PKG_NAME_INSTALLED="$INSTALLED/$PKG_NAME"
     438echo "PACKAGE NAME: $PKG_NAME" > "$PKG_NAME_INSTALLED"
     439echo "INSTALL DATE: `date`" >> "$PKG_NAME_INSTALLED"
     440echo "UNAME: `uname -a`" >> "$PKG_NAME_INSTALLED"
     441if [ -n "$TEST_SUITE_RESULT" ]; then
     442    echo "TEST SUITE: $TEST_SUITE_RESULT" >> "$PKG_NAME_INSTALLED"
     443fi
     444cat "$SAGE_ROOT/VERSION.txt" >> "$PKG_NAME_INSTALLED"
    394445
    395446
    396447##################################################################
    397 # If spkg-install is a Python script, verify that the Sage Python
    398 # has already been installed.
     448# Delete the temporary build directory if required
    399449##################################################################
    400 # Check the first line of the file for the string "python".
    401 head -1 spkg-install | grep python > /dev/null
    402 if [ $? -eq 0 ]; then   # if it is found, then the exit code will be 0
    403     if [ ! -f "$SAGE_LOCAL"/bin/python ]; then   # now check if the python program is in local/bin/
    404          # if so, exit with an error. 
    405          echo "The spkg-install script depends on the Sage Python package,"
    406          echo "but the Sage Python package is not yet installed.  This may be"
    407          echo "a bug in the Sage build system dependency file.  Please"
    408          echo "update the $SAGE_ROOT/spkg/standard/deps makefile."
    409          exit 1
    410     fi
    411 fi
    412 
    413 BASEDIR=`pwd`
    414 if [ -n "$DEBIAN_RELEASE" ]; then
    415     SAGE_CHECK=''
    416     if [ -e ./spkg-debian ]; then
    417         time ./spkg-debian
    418     else
    419         time sage-build-debian $BASEDIR
    420     fi
     450if [ $DELETE_TMP -eq 1 ]; then
     451    echo "Deleting temporary build directory"
     452    echo "$SAGE_BUILD_DIR/$PKG_NAME"
     453    rm -rf "$SAGE_BUILD_DIR/$PKG_NAME"
    421454else
    422     time ./spkg-install
    423 fi
    424 
    425 if [ $? -eq 0 ]; then
    426     cd "$INSTALLED"
    427     # TURNED OFF: Remove all old packages with the same name up to the first "-":
    428     # rm -f $PKG_BASE-*
    429 
    430     # Mark that the new package has been installed.
    431     # This file will eventually be a certificate like in OS X.
    432     echo "PACKAGE NAME: $PKG_NAME" > "$PKG_NAME"
    433     echo "INSTALL DATE: `date`" >> "$PKG_NAME"
    434     echo "UNAME: `uname -a`" >> "$PKG_NAME"
    435     if [ -f "$SAGE_ROOT"/VERSION.txt ]; then
    436         cat "$SAGE_ROOT"/VERSION.txt >> "$PKG_NAME"
    437     fi
    438     echo "Successfully installed $PKG_NAME"
    439 
    440     cd "$BASEDIR"
    441     if [ "x$SAGE_CHECK" = "xyes" -a -f spkg-check ]; then
    442         echo "Running the test suite."
    443         chmod +x spkg-check
    444         ./spkg-check
    445         if [ $? -ne 0 ]; then
    446             rm -f $SAGE_ROOT/spkg/installed/$PKG_NAME
    447             error_msg "Error testing package $PKG_NAME" "make check"
    448             exit 1
    449         else
    450             echo "TEST SUITE: passed" >> "$INSTALLED/$PKG_NAME"
    451         fi
    452     fi
    453 
    454 
    455     # Delete the temporary build directory if required.
    456     if [ $DELETE_TMP -eq 1 ]; then
    457         echo "Now cleaning up tmp files."
    458         if [ -d "$SAGE_BUILD_DIR/$PKG_NAME" ]; then
    459             # the if is there only to avoid the possibility of a weird bug.
    460             cd "$SAGE_BUILD_DIR/"
    461             rm -rf "$SAGE_BUILD_DIR/$PKG_NAME"
    462         fi
    463     else
    464         echo "You can safely delete the temporary build directory"
    465         echo "$SAGE_BUILD_DIR/$PKG_NAME"
    466     fi
    467 
    468 else
    469     error_msg "Error installing package $PKG_NAME" "make"
    470     exit 1
     455    echo "You can safely delete the temporary build directory"
     456    echo "$SAGE_BUILD_DIR/$PKG_NAME"
    471457fi
    472458
    473459
     
    482468fi
    483469
    484470echo "Finished installing $PKG_NAME.spkg"
    485 
    486 exit 0