54 lines
1.6 KiB
Bash
Executable File
54 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Check if an environment file was provided
|
|
if [ "$#" -ne 1 ]; then
|
|
echo "Usage: $0 environment.tar.gz"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Extracting the environment name from the provided archive..."
|
|
|
|
extract_filename() {
|
|
local fullpath="$1"
|
|
local filename="${fullpath##*/}" # Remove the path, retain the filename
|
|
local name="${filename%%.*}" # Remove the extension
|
|
echo "$name"
|
|
}
|
|
|
|
# Set environment variables based on the provided archive path.
|
|
export ENV_ARCHIVE=$1
|
|
export ENV_NAME=$(extract_filename $ENV_ARCHIVE) # The name of the environment, derived from the archive file name.
|
|
|
|
echo "Environment name extracted: $ENV_NAME"
|
|
|
|
# Define the path where Conda environments are stored and the specific path for the new environment.
|
|
export CONDA_ENVS="$HOME/.conda/envs"
|
|
export ENV_PATH="$CONDA_ENVS/$ENV_NAME"
|
|
|
|
echo "Designated path for the new environment: $ENV_PATH"
|
|
|
|
# Create the directory structure for the new environment.
|
|
mkdir -p $ENV_PATH
|
|
|
|
echo "Unpacking the provided environment archive into the designated environment path..."
|
|
|
|
# Unpack the provided environment archive into the designated environment path.
|
|
tar -xzf $ENV_ARCHIVE -C $ENV_PATH
|
|
|
|
echo "Changing into the environment directory..."
|
|
|
|
# Change into the environment directory.
|
|
cd $ENV_PATH
|
|
|
|
module load bigdata/conda
|
|
|
|
echo "Unpacking Conda environment..."
|
|
./bin/conda-unpack
|
|
|
|
# Check if the environment was deployed successfully by verifying the existence of the conda-meta directory.
|
|
if [ -d "$ENV_PATH/conda-meta" ]; then
|
|
echo "Environment setup completed successfully."
|
|
else
|
|
echo "Failed to deploy the Conda environment properly. Please check the archive and try again."
|
|
fi
|