/usr/share/sagemath/bin/sage-dist-helpers is in sagemath-common 8.1-7ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | # Shell functions for making spkg-install scripts a little easier to write,
# eliminating duplication. All Sage helper functions begin with sdh_ (for
# Sage-distribution helper). Consult the below documentation for the list of
# available helper functions:
#
# - sdh_die MESSAGE
#
# Exit the build script with the error code of the last command if it was
# non-zero, or with 1 otherwise, and print an error message.
# Typically used like:
#
# command || sdh_die "Command failed"
#
# This function can also (if not given any arguments) read the error message
# from stdin. In particular this is useful in conjunction with a heredoc to
# write multi-line error messages:
#
# command || sdh_die << _EOF_
# Command failed.
# Reason given.
# _EOF_
#
# - sdh_check_vars [VARIABLE ...]
#
# Check that one or more variables are defined and non-empty, and exit with
# an error if any are undefined or empty. Variable names should be given
# without the '$' to prevent unwanted expansion.
#
# - sdh_guard
#
# Wrapper for `sdh_check_vars` that checks some common variables without
# which many/most packages won't build correctly (SAGE_ROOT, SAGE_LOCAL,
# SAGE_SHARE). This is important to prevent installation to unintended
# locations.
#
# - sdh_configure [...]
#
# Runs `./configure --prefix="$SAGE_LOCAL"`. Additional arguments to
# `./configure` may be given as arguments.
#
# - sdh_make [...]
#
# Runs `$MAKE` with the default target. Additional arguments to `make` may
# be given as arguments.
#
# - sdh_make_install [...]
#
# Runs `$SAGE_SUDO $MAKE install`. Additional arguments to `make` may be
# given as arguments.
#
# - sdh_pip_install [...]
#
# Runs `pip install` with the given arguments, as well as additional
# default arguments used for installing packages into Sage with pip.
# Currently this is just a wrapper around the `sage-pip-install` command.
set -o allexport
# Utility function to get the terminal width in columns
# Returns 80 by default if nothing else works
_sdh_cols() {
local cols="${COLUMNS:-$(tput cols 2>/dev/null)}"
if [ "$?" -ne 0 -o -z "$cols" ]; then
# If we can't get the terminal width any other way just default to 80
cols=80
fi
echo $cols
}
# Utility function to print a terminal-width horizonal rule using the given
# character (or '-' by default)
_sdh_hr() {
local char="${1:--}"
printf '%*s\n' $(_sdh_cols) '' | tr ' ' "${char}"
}
sdh_die() {
local ret=$?
local msg
if [ $ret -eq 0 ]; then
# Always return non-zero, but if the last command run returned non-zero
# then return its exact error code
ret=1
fi
if [ $# -gt 0 ]; then
msg="$*"
else
msg="$(cat -)"
fi
_sdh_hr >&2 '*'
echo "$msg" | fmt -s -w $(_sdh_cols) >&2
_sdh_hr >&2 '*'
exit $ret
}
sdh_check_vars() {
while [ -n "$1" ]; do
[ -n "$(eval "echo "\${${1}+isset}"")" ] || sdh_die << _EOF_
${1} undefined ... exiting
Maybe run 'sage --sh'?
_EOF_
shift
done
}
sdh_guard() {
sdh_check_vars SAGE_ROOT SAGE_LOCAL SAGE_SHARE
}
sdh_configure() {
echo "Configuring $PKG_NAME"
./configure --prefix="$SAGE_LOCAL" "$@" || \
sdh_die "Error configuring $PKG_NAME"
}
sdh_make() {
echo "Building $PKG_NAME"
${MAKE:-make} "$@" || sdh_die "Error building $PKG_NAME"
}
sdh_make_install() {
echo "Installing $PKG_NAME"
$SAGE_SUDO ${MAKE:-make} install "$@" || \
sdh_die "Error installing $PKG_NAME"
}
sdh_pip_install() {
echo "Installing $PKG_NAME"
$SAGE_SUDO sage-pip-install "$@" || \
sdh_die "Error installing $PKG_NAME"
}
set +o allexport
|