This commit is contained in:
Sylvain Tricot 2019-11-28 18:43:33 +01:00
commit ad52398853
2 changed files with 465 additions and 278 deletions

View File

@ -60,7 +60,12 @@ error_exit () {
printf " for more informations.\n"
printf " Below is an excerpt of the last 10 lines:\n"
printf "\n"
<<<<<<< HEAD
tail "${LOGFILE}"
=======
# tail -v -n 10 "${LOGFILE}"
tail -n 10 "${LOGFILE}"
>>>>>>> 1e676167338c9fe5ee07a649dea05da2a18eebbd
# uninstall if needed
pip uninstall -y msspec
@ -68,6 +73,23 @@ error_exit () {
cleanup && exit 1
}
<<<<<<< HEAD
=======
get_os () {
for os in "ubuntu" "mageia" "archlinux"; do
cat /etc/*release /etc/*version /etc/*issue 2>/dev/null | grep -i "$os" 2>/dev/null 1>/dev/null
if test $? -eq 0; then
LINUX_OS="$os"
break
fi
done
}
>>>>>>> 1e676167338c9fe5ee07a649dea05da2a18eebbd
read_yes_no () {
DEFAULT="$2"
PROMPT="$1 (y/n) [${DEFAULT}]? "
@ -77,9 +99,15 @@ read_yes_no () {
VALID=1
while test $VALID -ne 0; do
<<<<<<< HEAD
printf "%s" "${PROMPT}"
if [ x"$BYPASS" = xn ]; then
read -r "INPUT"
=======
printf "${PROMPT}"
if [ x"$BYPASS" = "xn" ]; then
read "RESPONSE"
>>>>>>> 1e676167338c9fe5ee07a649dea05da2a18eebbd
else
printf "\n"
fi
@ -93,13 +121,66 @@ read_yes_no () {
log_message "ANSWER : $ANSWER"
}
<<<<<<< HEAD
=======
read_folder () {
DEFAULT="$2"
PROMPT="$1 [${DEFAULT}]: "
ANSWER=""
unset FOLDER
printf "${PROMPT}"
if [ x"$BYPASS" = "xn" ]; then
read "ANSWER"
else
printf "\n"
fi
export FOLDER="${ANSWER:-$DEFAULT}"
log_message "QUESTION: $PROMPT"
log_message "ANSWER : $FOLDER"
}
create_folder () {
FOLDER="$1"
ERR_MKDIR=1
ERR_ABORT=2
ERR_PERMS=3
if ! test -d "${FOLDER}" ; then
read_yes_no "The folder \"${FOLDER}\" does not exist. Should I create it" "y" #"$BYPASS"
case "${ANSWER}" in
y) mkdir -p "${FOLDER}" 2>>${LOGFILE} 1>>${LOGFILE} || return $ERR_MKDIR;;
n) log_message2 "Installation aborted by the user" && return $ERR_ABORT ;;
esac
fi
if ! test -w "${FOLDER}" ; then
log_message2 "You do not have permission to write into \"${FOLDER}\"."
return $ERR_PERMS
fi
}
>>>>>>> 1e676167338c9fe5ee07a649dea05da2a18eebbd
wrap () {
log_message "================================================================================"
log_message "$2"
log_message "================================================================================"
<<<<<<< HEAD
if [ "$DEBUG" = y ]; then
printf "%s...\n" "$2"
(eval "$1" || echo $? >"${GETOUTFILE}") | tee -a "${LOGFILE}"
=======
if [ "$DEBUG" = "y" ]; then
eval "($1) 2>&1" | tee -a ${LOGFILE}
echo ${PIPESTATUS[0]} >${GETOUTFILE}
>>>>>>> 1e676167338c9fe5ee07a649dea05da2a18eebbd
rc=$(cat $GETOUTFILE)
if [ $rc != 0 ]; then
error_exit
@ -110,6 +191,26 @@ wrap () {
fi
}
<<<<<<< HEAD
=======
update_path () {
# check if the shell path contains $BIN_FOLDER
SHELLRC="$HOME/.$(basename $SHELL)rc"
${ECHO} "$PATH" | grep "${BIN_FOLDER}" 2>/dev/null 1>/dev/null
if test $? -ne 0; then
${ECHO} "" >> $SHELLRC
${ECHO} "# Add the user's local binary folder" >> $SHELLRC
${ECHO} "export PATH=${BIN_FOLDER}:\$PATH" >> $SHELLRC
${ECHO} "Your PATH variable has been updated, the folder"
${ECHO} "${BIN_FOLDER} has been added to it."
${ECHO} ""
${ECHO} "Please source again your shell configuration file by typing:"
${ECHO} "source $SHELLRC"
fi
}
>>>>>>> 1e676167338c9fe5ee07a649dea05da2a18eebbd
success_message () {
log_message "========================================================"
log_message "MsSpec was successfully installed."
@ -139,7 +240,7 @@ patience () {
printf "\b\b Done.\n"
}
show_help () {
show_help () {
echo "Usage: $SCRIPT_NAME [OPTIONS]"
echo "List of possible options:"
echo " -y Accept all default choices."
@ -159,7 +260,8 @@ check_dependencies () {
gcc_ver_min=7
log_message "Checking if gfortran >= $gcc_ver_min is installed..."
command -V gfortran || return 1
gcc_ver=$(gcc -dumpversion)
# gcc_ver=$(gcc -dumpversion)
gcc_ver=$(echo $(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"
@ -183,10 +285,17 @@ check_dependencies () {
log_message "Ok\n"
# we need virtualenv
<<<<<<< HEAD
#log_message "Checking if virtualenv is installed..."
#command -V virtualenv || return 1
#log_message "Ok\n"
=======
log_message "Checking if virtualenv is installed..."
#command -V virtualenv || return 1
log_message "Ok\n"
>>>>>>> 1e676167338c9fe5ee07a649dea05da2a18eebbd
}
local_install () {
@ -196,6 +305,7 @@ local_install () {
# check dependencies
wrap "check_dependencies" "Checking dependencies"
<<<<<<< HEAD
# build the Fortran code
wrap "make pybinding VERBOSE=1" "Building Phagen and Spec Python dynamic library"
@ -205,6 +315,82 @@ local_install () {
# install the package
wrap "make install VERBOSE=1" "Installing the msspec package"
=======
# ask for a place to put the binary
#read_folder "Please, type in the folder where to place the binary" "${DEFAULT_BIN}"
#BIN_FOLDER=${FOLDER}
#create_folder "${BIN_FOLDER}" || error_exit
#export BIN_FOLDER
# If in a virtualenv, ask if we should install inside
if [ x"$VIRTUAL_ENV" != x ]; then
read_yes_no "You are running a Python virtual environment. Do you wish to install msspec inside ?" "y"
case ${ANSWER} in
y) # get the python version of this venv...
v=$(python -V 2>&1 | cut -d" " -f2 | cut -d. -f1)
# and stops if < 3
if [ $v -lt 3 ]; then
log_message "The Python version of this venv is < 3"
error_exit
fi
;;
n) # The user decided to stop there
log_message "Please deactivate your virtual environment and restart the setup program."
error_exit
;;
esac
# Else, we are not in a virtualenv
else
pip_opt=""
# so ask if we should create one
read_yes_no "Do you wish to create a virtual environment to install MsSpec inside" "y"
case ${ANSWER} in
y) # Create the destination folder
read_folder "Please, type in the base installation folder" "${DEFAULT_DEST}"
DEST_FOLDER=${FOLDER}/MsSpec-${VERSION}
if [ -d $DEST_FOLDER ]; then
export DEST_ALREADY_EXISTS="y" # to avoid cleaning the existing DEST_FOLDER in case of any problem
read_yes_no "The folder $DEST_FOLDER already exists. Overwrite" "y"
case ${ANSWER} in
y) # overwrite
create_folder "${DEST_FOLDER}" || error_exit
;;
n) # stop here otherwise
error_exit
;;
esac
fi
export DEST_FOLDER
wrap "virtualenv -vvv --python=${PYTHON} --system-site-packages --prompt=\"(msspec-${VERSION}) \" ${DEST_FOLDER}/venv" \
"Create a Python virtual environment"
. ${DEST_FOLDER}/venv/bin/activate
;;
n) # install in the user $HOME
pip_opt="--user"
;;
esac
fi
# build and run setuptools to create a source distribution
wrap "make sdist" \
"Building MsSpec python package"
# install the package with pip
wrap "pip install $pip_opt dist/msspec-*.tar.gz" \
"Installing pymsspec python package and its dependencies"
#
## move the frontend to the binary folder
##wrap "mkdir -p ${LOCALBIN} && \
## cp ./msspec ${LOCALBIN} && chmod u+x ${LOCALBIN}/msspec && \
## ${ECHO} \"msspec installed in ${LOCALBIN}\"" \
## "Installing the msspec frontend"
# "cp ./msspec ${BIN_FOLDER} && chmod ugo+rx ${BIN_FOLDER}/msspec" "Installing the msspec frontend"
#
## move the uninstal script
#wrap "cp ./uninstall.sh ${DEST}" "Moving the uninstall script"
#
>>>>>>> 1e676167338c9fe5ee07a649dea05da2a18eebbd
# Run unit tests ?
read_yes_no "Do you wish to run unit tests" "y"
if [ x"${ANSWER}" = xy ]; then
@ -216,7 +402,7 @@ local_install () {
if [ x"${ANSWER}" = xn ]; then
rm -f "${LOGFILE}"
fi
# self-explanatory
success_message
}

File diff suppressed because it is too large Load Diff