From 10aef674ea81c3610ace78c2596df2afbac3ab42 Mon Sep 17 00:00:00 2001 From: RAHenriksen Date: Tue, 17 Dec 2024 11:14:41 +0100 Subject: [PATCH] new custom install --- custom_install.sh | 84 ++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/custom_install.sh b/custom_install.sh index 741e348..f2a87f1 100644 --- a/custom_install.sh +++ b/custom_install.sh @@ -1,15 +1,17 @@ #!/bin/bash -#Script executes these commands with safeguards in place: -# - Clones the main repository. -# - Installs the main repository package. -# - Updates the `cdiff_fbi` submodule to the latest tag. +#Script executes these commands with some safeguards in place in case it fails: +# git clone https://github.com/ssi-dk/serum_readfilter +# cd serum_readfilter +# pip install . + +#ENV_NAME=$1 GIT_REPO=https://github.com/ssi-dk/serum_readfilter REPO_FOLDER=serum_readfilter SUBMODULE_PATH="bifrost_sp_cdiff/cdiff_fbi" # Path to the submodule SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -cd $SCRIPT_DIR || exit 1 # Avoid small edge case where bashrc sourcing changes your directory +cd $SCRIPT_DIR # avoiding small edge case where bashrc sourcing changes your directory function exit_function() { echo "To rerun use the command:" @@ -28,28 +30,41 @@ source $CONDA_BASE/etc/profile.d/conda.sh # conda activate $ENV_NAME # fi -# Check for git availability -if ! command -v git &>/dev/null; then - echo "git is not installed." - echo "You can try installing git and rerunning the script." - exit_function -fi - -# Clone the main repository if it does not exist -if test -d "$SCRIPT_DIR/$REPO_FOLDER"; then - echo "$SCRIPT_DIR/$REPO_FOLDER already exists. If you want to overwrite, please remove the old repository folder:" +if test -d "$SCRIPT_DIR/$REPO_FOLDER" +then + echo "$SCRIPT_DIR/$REPO_FOLDER already exists, if you want to overwrite, please remove the old repository folder" + echo "You can use:" echo "rm -rf $SCRIPT_DIR/$REPO_FOLDER" exit_function else - echo "################# Cloning repository from $GIT_REPO" - if ! git clone $GIT_REPO; then - echo >&2 "git clone command failed." + git --version + GIT_IS_AVAILABLE=$? + if [ $GIT_IS_AVAILABLE -eq 0 ] + then + echo "#################Cloning repository from $GIT_REPO" + if ! git clone $GIT_REPO + then + echo >&2 "git clone command failed" + exit_function + else + cd $REPO_FOLDER + echo "#################Installing package using pip" + if ! pip install . + then + echo >&2 "pip install command failed" + exit_function + else + echo "Package successfully installed" + fi + fi + else + echo "git is not installed" + echo "You can try installing git and rerunning the script" exit_function fi fi -# Navigate into the main repository -cd $REPO_FOLDER || { echo "Failed to enter repository directory"; exit_function; } +cd $SCRIPT_DIR # Initialize and update submodules echo "################# Initializing and updating submodules..." @@ -58,13 +73,8 @@ if ! git submodule update --init --recursive; then exit_function fi -# Navigate to the submodule directory -if ! test -d "$SUBMODULE_PATH"; then - echo "Submodule path $SUBMODULE_PATH does not exist. Exiting." - exit_function -fi +cd $SUBMODULE_PATH || { echo "Failed to enter submodule cdiff_fbi repository directory"; exit_function; } -cd $SUBMODULE_PATH || { echo "Failed to enter submodule directory $SUBMODULE_PATH"; exit_function; } # Fetch the latest tags echo "################# Fetching the latest tags for the submodule..." @@ -111,16 +121,16 @@ if ! git checkout "$LATEST_TAG_COMMIT"; then exit_function fi -# Navigate back to the main repository directory -cd "$SCRIPT_DIR/$REPO_FOLDER" || exit_function +# Determine the latest tag +#LATEST_TAG=$(git rev-parse HEAD) +#echo "TAG $LATEST_TAG" -# Install the main package using pip -echo "################# Installing package using pip..." -if ! pip install .; then - echo >&2 "pip install command failed." - exit_function -else - echo "Package successfully installed." -fi +# Identify the latest tag +#LATEST_TAG_COMMIT=$(git for-each-ref --sort=-creatordate refs/tags | head -1 | cut -f1 -d ' ') +#LATEST_TAG=$(git for-each-ref --sort=-creatordate refs/tags | head -1 | cut -f3 -d '/') + +#echo "TEST2 $LATEST_TAG: $LATEST_COMMIT" + +cd $SCRIPT_DIR -echo "################# Installation complete." +echo "Installation complete"