Skip to content

Commit

Permalink
new custom install
Browse files Browse the repository at this point in the history
  • Loading branch information
RAHenriksen committed Dec 17, 2024
1 parent 12b2c24 commit 10aef67
Showing 1 changed file with 47 additions and 37 deletions.
84 changes: 47 additions & 37 deletions custom_install.sh
Original file line number Diff line number Diff line change
@@ -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:"
Expand All @@ -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..."
Expand All @@ -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..."
Expand Down Expand Up @@ -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"

0 comments on commit 10aef67

Please sign in to comment.