Work on install script

This commit is contained in:
Sylvain Tricot 2019-11-18 17:33:32 +01:00
parent 9222f5c9d2
commit 51afffd97b
3 changed files with 332 additions and 4 deletions

View File

@ -22,8 +22,27 @@ purge: clean
selfex: purge selfex: purge
@echo "Creating the self-extractible setup program... " @echo "Creating the self-extractible setup program... "
# update the version
@cp ./src/msspec/version.py ./src/msspec/version.py.bak @cp ./src/msspec/version.py ./src/msspec/version.py.bak
@echo "__version__ = \"$(VERSION)\"" > ./src/msspec/version.py @echo "__version__ = \"$(VERSION)\"" > ./src/msspec/version.py
$(MAKESELF) --license ./license.txt --notemp ./src $(SETUPFILE) "Python MsSpec" ./install.sh # create the *.lsm file
@mv ./src/msspec/version.py.bak ./src/msspec/version.py @echo "Begin4" > pymsspec.lsm
@echo "Title: Python MsSpec" >> pymsspec.lsm
@echo "Version: $(VERSION)" >> pymsspec.lsm
@echo "Entered-date: `date +%Y-%m-%d`" >> pymsspec.lsm
@echo "Description: A multiple scattering package for spectroscopies using electrons to probe materials" >> pymsspec.lsm
@echo "Keywords: " >> pymsspec.lsm
@echo "Author: sylvain.tricot@univ-rennes1.fr (Sylvain Tricot), didier.sebilleau@univ-rennes1.fr (Didier Sébilleau)" >> pymsspec.lsm
@echo "Maintained-by: sylvain.tricot@univ-rennes1.fr (Sylvain Tricot)" >> pymsspec.lsm
@echo "Primary-site: https://msspec.cnrs.fr" >> pymsspec.lsm
@echo "Alternate-site:" >> pymsspec.lsm
@echo "Original-site:" >> pymsspec.lsm
@echo "Platforms:" >> pymsspec.lsm
@echo "Copying-policy: Gnu Library General Public License (GLPL) 2.0" >> pymsspec.lsm
@echo "End" >> pymsspec.lsm
$(MAKESELF) --license ./license.txt --lsm ./pymsspec.lsm --notemp ./src $(SETUPFILE) "Python MsSpec" ./install.sh
@mv ./src/msspec/version.py.bak ./src/msspec/version.py
@rm ./pymsspec.lsm

View File

@ -1,3 +1,304 @@
#!/bin/bash #!/bin/bash
make install PYTHON_VERSION=python3
VERSION=$(cat ./msspec/version.py|cut -d\" -f2)
DEFAULT_DEST="${HOME}/.local/share"
DEFAULT_BIN="${HOME}/.local/bin"
BYPASS="n"
DEBUG="n"
TIMEOUT=5
ECHO="/bin/echo -e"
DATE=$(date +%Y%m%d_%H%M%S)
LOGFILE="${HOME}/msspec_install_${DATE}.log"
GETOUTFILE=$(mktemp)
LOCALBIN=$HOME/.local/bin
LINUX_OS="other_linux"
trap "abort_install" 2
trap "error_exit" 1 3 4 6
init_install () {
${ECHO} "Installation started on $(date)" > ${LOGFILE}
${ECHO} "0" > ${GETOUTFILE}
get_os
}
abort_install () {
${ECHO} "Installation aborted by the user" >> ${LOGFILE}
error_exit
}
log_message () {
${ECHO} "================================================================================" >> ${LOGFILE}
${ECHO} "$1" >> ${LOGFILE}
${ECHO} "================================================================================" >> ${LOGFILE}
}
cleanup () {
stty echo
rm -rf ${GETOUTFILE}
}
error_exit () {
# An error occured
${ECHO} ""
${ECHO} " /!\ An error occured during the installation process."
${ECHO} " Please see the $(basename ${LOGFILE}) file in your HOME folder"
${ECHO} " for more informations. "
${ECHO} " Below is an excerpt of the last 10 lines: "
${ECHO} ""
tail -v -n 10 "${LOGFILE}"
rm -rf ${DEST_FOLDER} 2>/dev/null
cleanup && exit 1
}
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
}
read_yes_no () {
PROMPT="$1"
DEFAULT="$2"
BYPASS="$3"
ANSWER=""
RESPONSE=""
VALID=1
while test $VALID -ne 0; do
test "$BYPASS" = "y" || read -p "${PROMPT} (y/n) [${DEFAULT}]? " "RESPONSE"
ANSWER="${RESPONSE:-${DEFAULT}}"
case "${ANSWER}" in
y|n) VALID=0 ;;
*) echo "Invalid choice, please answer \"y\" or \"n\"."; VALID=1 ;;
esac
done
}
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) ${ECHO} "Installation aborted by the user" >>${LOGFILE} && return $ERR_ABORT ;;
esac
fi
if ! test -w "${FOLDER}" ; then
${ECHO} "You do not have permission to write into \"${FOLDER}\"." >>${LOGFILE}
return $ERR_PERMS
fi
}
common_install () {
case $LINUX_OS in
ubuntu) # raise privileges
#sudo ${ECHO} "" || exit ;
wrap "ubuntu_prerequistes" "Installing Ubuntu specific packages" ;
;;
mageia) stty -echo; printf "Please enter root password: "; read PASSWORD; stty echo; printf "\n";
wrap "mageia_prerequistes" "Installing Mageia specific packages" ;
;;
*) # message for other linux distrib
${ECHO} "Please make sure BEFORE going on with the install program"
${ECHO} "that you do have already installed on your computer the"
${ECHO} "following list of softwares or libraries:"
${ECHO} ""
cat ./distro-requirements
${ECHO} ""
if test "$BYPASS" = "n"; then
read -p "Type y to go on, or type n to quit: " "ANSWER"
case $ANSWER in
y) ;;
*) exit 1 ;;
esac
fi
;;
esac
}
wrap () {
log_message "$2"
if [ "$DEBUG" = "y" ]; then
eval "($1) 2>&1" | tee -a ${LOGFILE}
echo ${PIPESTATUS[0]} >${GETOUTFILE}
rc=$(cat $GETOUTFILE)
if [ $rc != 0 ]; then
error_exit
fi
else
eval "($1) 2>>${LOGFILE} 1>>${LOGFILE}" || echo $? >${GETOUTFILE} &
patience "$2"
fi
}
local_install () {
init_install
if [ "$BYPASS" = "n" ]; then
${ECHO} "Thanks for choosing MsSpec"
${ECHO} ""
${ECHO} "This program will install the MsSpec distribution on your computer"
${ECHO} -n "Press C^c to cancel now... "
for i in $(seq -s" " 0 $TIMEOUT); do
${ECHO} -n "\b";
${ECHO} -n $(( $TIMEOUT-i ));
sleep 1;
done
${ECHO} ""
fi
# Create the destination folder
ANSWER=""
test "$BYPASS" = "y" || read -p "Please, type in the base installation folder ["${DEFAULT_DEST}"]: " "ANSWER"
DEST_FOLDER="${ANSWER:-$DEFAULT_DEST}/MsSpec-${VERSION}"
create_folder "${DEST_FOLDER}" || error_exit
export DEST_FOLDER
ANSWER=""
test "$BYPASS" = "y" || read -p "Please, type in the folder where to place the binary ["${DEFAULT_BIN}"]: " "ANSWER"
BIN_FOLDER="${ANSWER:-$DEFAULT_BIN}"
create_folder "${BIN_FOLDER}" || error_exit
export BIN_FOLDER
# create a virtualenv
# check if we are in a virtualenv and exit if so
if [ x"$VIRTUAL_ENV" != x ]; then
${ECHO} "Installation from a previous virtualenv is not yet supported. Please deactivate it and restart the setup program." >>${LOGFILE}
error_exit
fi
wrap "virtualenv -v --python=${PYTHON_VERSION} --system-site-packages --prompt=\"(msspec-${VERSION}) \" ${DEST_FOLDER}/venv" \
"Create a Python virtual environment"
. ${DEST_FOLDER}/venv/bin/activate
# install pymsspec
wrap "make install" \
"Installing pymsspec python package and its dependencies"
# deactivate the virtualenv
deactivate
#
## 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"
#
# installation was a succes so move the logfile to the DEST directory
wrap "cp ${LOGFILE} ${DEST_FOLDER}/msspec_install.log" "Moving the logfile"
# self-explanatory
success_message
}
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
}
success_message () {
${ECHO} "========================================================"
${ECHO} "MsSpec was successfully installed."
${ECHO} "========================================================"
}
patience () {
MSG=$1
PID=$!
i=0
${ECHO} -n "$MSG... "
while ps -p $PID > /dev/null
do
sleep 0.1
case $i in
0) ${ECHO} -n "\b\b- " ;;
1) ${ECHO} -n "\b\b\\ " ;;
2) ${ECHO} -n "\b\b| " ;;
3) ${ECHO} -n "\b\b/ "; i=-1 ;;
esac
i=$((i+1))
done
if test $(cat ${GETOUTFILE}) -ne 0; then
${ECHO} "\b\b Aborted!"
error_exit
fi
${ECHO} "\b\b Done."
}
#create_dest_folder
#echo $DEST_FOLDER
#exit
while getopts "p:b:yd" option
do
case $option in
p) export DEFAULT_DEST="$OPTARG"
;;
b) export DEFAULT_BIN="$OPTARG"
;;
y) export BYPASS="y"
;;
d) export DEBUG="y"
;;
esac
done
local_install

View File

@ -7,4 +7,12 @@ import msspec
setup(name='msspec', setup(name='msspec',
version=msspec.__version__, version=msspec.__version__,
include_package_data=True, include_package_data=True,
packages=find_packages(include='msspec.*')) packages=find_packages(include='msspec.*'),
install_requires=[
'ase',
'h5py',
'lxml',
'pint',
'terminaltables',
'pycairo',
])