254 lines
6.1 KiB
Bash
Executable File
254 lines
6.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# vim: set ts=4 sw=4 sts noet mouse=a fdm=indent:
|
|
|
|
BYPASS="n"
|
|
DEBUG="n"
|
|
|
|
SCRIPT_NAME=$(basename "$0")
|
|
VERSION=$(cat ./msspec/version.py|cut -d\" -f2)
|
|
DATE=$(date +%Y%m%d_%H%M%S)
|
|
LOGFILE="${HOME}/msspec_install_${DATE}.log"
|
|
GETOUTFILE=$(mktemp)
|
|
|
|
trap "abort_install" INT
|
|
trap "error_exit" HUP QUIT ILL ABRT
|
|
|
|
init_install () {
|
|
printf "Installation started on %s\n" "$(date)" > "${LOGFILE}"
|
|
printf "0" > "${GETOUTFILE}"
|
|
|
|
if [ "$BYPASS" = "n" ]; then
|
|
printf ""
|
|
printf "This program will install the msspec python package on your system.\n"
|
|
printf "It is highly recommended to run this installation process within a\n"
|
|
printf "Python virtual environment. If you want to create and/or activate one,\n"
|
|
printf "you can answer \"n\" now and restart the setup program later.\n"
|
|
|
|
read_yes_no "Do you wish to continue" "y"
|
|
case "${ANSWER}" in
|
|
y) ;;
|
|
n) abort_install ;;
|
|
esac
|
|
fi
|
|
|
|
}
|
|
|
|
abort_install () {
|
|
log_message "Installation aborted by the user"
|
|
error_exit
|
|
}
|
|
|
|
log_message () {
|
|
printf "$1\n" >> ${LOGFILE}
|
|
}
|
|
|
|
log_message2 () {
|
|
# echo to screen and to file
|
|
printf "$1\n"
|
|
log_message "$1\n"
|
|
}
|
|
|
|
cleanup () {
|
|
rm -rf "${GETOUTFILE}"
|
|
}
|
|
|
|
error_exit () {
|
|
# An error occured
|
|
printf "\n"
|
|
printf " /!\ An error occured during the installation process.\n"
|
|
printf " Please see the %s file in your HOME folder\n" "$(basename "${LOGFILE}")"
|
|
printf " for more informations.\n"
|
|
printf " Below is an excerpt of the last 10 lines:\n"
|
|
printf "\n"
|
|
echo ">>> ..."
|
|
tail "${LOGFILE}" | while read line
|
|
do
|
|
echo ">>> $line"
|
|
done
|
|
|
|
# uninstall if needed
|
|
pip uninstall -y msspec
|
|
|
|
cleanup && exit 1
|
|
}
|
|
|
|
read_yes_no () {
|
|
DEFAULT="$2"
|
|
PROMPT="$1 (y/n) [${DEFAULT}]? "
|
|
|
|
ANSWER=""
|
|
INPUT=""
|
|
|
|
VALID=1
|
|
while test $VALID -ne 0; do
|
|
printf "%s" "${PROMPT}"
|
|
if [ x"$BYPASS" = xn ]; then
|
|
read -r "INPUT"
|
|
else
|
|
printf "\n"
|
|
fi
|
|
ANSWER="${INPUT:-${DEFAULT}}"
|
|
case "${ANSWER}" in
|
|
y|n) VALID=0 ;;
|
|
*) printf "Invalid choice, please answer \"y\" or \"n\".\n"; VALID=1 ;;
|
|
esac
|
|
done
|
|
log_message "QUESTION: $PROMPT"
|
|
log_message "ANSWER : $ANSWER"
|
|
}
|
|
|
|
wrap () {
|
|
log_message "================================================================================"
|
|
log_message "$2"
|
|
log_message "================================================================================"
|
|
if [ "$DEBUG" = y ]; then
|
|
printf "%s...\n" "$2"
|
|
(eval "$1" || echo $? >"${GETOUTFILE}") | tee -a "${LOGFILE}"
|
|
rc=$(cat $GETOUTFILE)
|
|
if [ $rc != 0 ]; then
|
|
error_exit
|
|
fi
|
|
else
|
|
eval "($1) 2>>${LOGFILE} 1>>${LOGFILE}" || echo $? >${GETOUTFILE} &
|
|
patience "$2"
|
|
fi
|
|
}
|
|
|
|
success_message () {
|
|
log_message "========================================================"
|
|
log_message "MsSpec was successfully installed."
|
|
log_message "========================================================"
|
|
}
|
|
|
|
patience () {
|
|
MSG="$1"
|
|
PID=$!
|
|
i=0
|
|
printf "%s" "$MSG... "
|
|
while ps -p $PID > /dev/null
|
|
do
|
|
sleep 0.1
|
|
case $i in
|
|
0) printf "\b\b- " ;;
|
|
1) printf "\b\b\\ " ;;
|
|
2) printf "\b\b| " ;;
|
|
3) printf "\b\b/ "; i=-1 ;;
|
|
esac
|
|
i=$(( i+1 ))
|
|
done
|
|
if test "$(cat "${GETOUTFILE}")" -ne 0; then
|
|
printf "\b\b Aborted!"
|
|
error_exit
|
|
fi
|
|
printf "\b\b Done.\n"
|
|
}
|
|
|
|
show_help () {
|
|
echo "Usage: $SCRIPT_NAME [OPTIONS]"
|
|
echo "List of possible options:"
|
|
echo " -y Accept all default choices."
|
|
echo " -d Debug mode."
|
|
echo " -h Show this message."
|
|
exit 0
|
|
}
|
|
|
|
|
|
check_dependencies () {
|
|
# we need make
|
|
log_message "Checking if make is installed..."
|
|
command -V make || return 1
|
|
log_message "Ok\n"
|
|
|
|
# we need gfortran
|
|
gcc_ver_min=6
|
|
log_message "Checking if gfortran >= $gcc_ver_min is installed..."
|
|
command -V gfortran || return 1
|
|
gcc_ver=$(gcc -dumpversion|cut -d. -f1)
|
|
echo "You have gfortran version $gcc_ver installed"
|
|
test "$gcc_ver" -ge "$gcc_ver_min" || return 1
|
|
log_message "Ok\n"
|
|
|
|
# we need libcairo and dev files
|
|
log_message "Checking if libcairo is installed..."
|
|
pkg-config --exists cairo || return 1
|
|
log_message "Ok\n"
|
|
|
|
# we need Python 3
|
|
py_ver_major_min=3
|
|
py_ver_minor_min=0
|
|
log_message "Checking if Python >= ${py_ver_major_min}.${py_ver_minor_min}..."
|
|
command -V python || return 1
|
|
py_ver=$(python --version | cut -d" " -f2)
|
|
echo "You have Python version $py_ver installed"
|
|
py_ver_major=$(echo $py_ver|cut -d. -f1)
|
|
py_ver_minor=$(echo $py_ver|cut -d. -f2)
|
|
test "$py_ver_major" -ge "$py_ver_major_min" || return 1
|
|
test "$py_ver_minor" -ge "$py_ver_minor_min" || return 1
|
|
log_message "Ok\n"
|
|
|
|
# we need wxPython.
|
|
log_message "Checking if wxPython is installed..."
|
|
python -c "import wx"
|
|
if test "$?" -ne 0; then
|
|
log_message "You need wxPython to run MsSpec.\n"
|
|
log_message "Please look at informations at https://wxpython.org/pages/downloads/.\n"
|
|
return 1
|
|
else
|
|
log_message "Ok\n"
|
|
fi
|
|
|
|
# we need virtualenv
|
|
#log_message "Checking if virtualenv is installed..."
|
|
#command -V virtualenv || return 1
|
|
#log_message "Ok\n"
|
|
|
|
}
|
|
|
|
local_install () {
|
|
# Initialize the install process
|
|
init_install
|
|
|
|
# check dependencies
|
|
wrap "check_dependencies" "Checking dependencies"
|
|
|
|
# build the Fortran code
|
|
wrap "make pybinding VERBOSE=1" "Building Phagen and Spec Python dynamic library"
|
|
|
|
# build the source distribution
|
|
wrap "make sdist VERBOSE=1" "Building msspec python package"
|
|
|
|
# install the package
|
|
wrap "make install VERBOSE=1" "Installing the msspec package"
|
|
|
|
# Run unit tests ?
|
|
read_yes_no "Do you wish to run unit tests" "y"
|
|
if [ x"${ANSWER}" = xy ]; then
|
|
wrap "make tests" "Runing test suite"
|
|
fi
|
|
|
|
# installation was a succes so ask if we keep the log file
|
|
read_yes_no "Do you wish to keep the log file (${LOGFILE})" "n"
|
|
if [ x"${ANSWER}" = xn ]; then
|
|
rm -f "${LOGFILE}"
|
|
fi
|
|
|
|
# self-explanatory
|
|
success_message
|
|
}
|
|
|
|
while getopts "p:b:yd" option
|
|
do
|
|
case $option in
|
|
y) export BYPASS="y"
|
|
;;
|
|
d) export DEBUG="y"
|
|
;;
|
|
h) show_help
|
|
;;
|
|
*) show_help
|
|
;;
|
|
esac
|
|
done
|
|
|
|
local_install
|