|
#!/bin/bash |
|
|
|
# Check if the correct number of arguments is provided |
|
if [ "$#" -ne 4 ]; then |
|
echo "Usage: $0 <env_name> <destination_path> <rsync://host:port/share/path> <remote_username@remote_address>" |
|
exit 1 |
|
fi |
|
|
|
# Assign arguments to variables for better readability |
|
env_name=$1 |
|
destination_path=$2 |
|
rsync_server=$3 || "rsync://localhost:873/share/path" |
|
remote=$4 # Format: username@remote_address |
|
tar_file_name="${env_name}_env.tar.gz" |
|
|
|
# Step 1: Install conda-pack |
|
source activate base || conda activate base || conda deactivate |
|
# If conda-pack is not installed, install it |
|
if [ -z "$(conda env list | grep conda-pack)" ]; then |
|
echo "Conda-pack is not installed. Installing conda-pack..." |
|
conda install -c conda-forge conda-pack || pip install conda-pack |
|
else |
|
# conda-pack is installed |
|
echo "Conda-pack is installed." |
|
fi |
|
|
|
# Step 2: Activate the environment |
|
echo "Activating the Conda environment..." |
|
source activate $env_name || conda activate $env_name |
|
|
|
# Step 3: Pack the environment |
|
echo "Packing the environment..." |
|
condapack -n $env_name -o $tar_file_name |
|
|
|
# Step 4: Transfer the tar file to the new directory |
|
echo "Transferring the tar file..." |
|
rsync -axz --zc=zstd --info=progress2 --info=name0 $tar_file_name $rsync_server/$tar_file_name |
|
|
|
# Step 5: Unpack the environment via SSH on the remote machine |
|
echo "Unpacking the environment on the remote machine..." |
|
ssh $remote "mkdir -p $destination_path && \ |
|
tar -xzf $tar_file_name -C $destination_path && \ |
|
rm $tar_file_name && \ |
|
chmod -R 755 $destination_path" |
|
|
|
# Step 6: Update the .zshrc or file |
|
echo "Updating the .zshrc file..." |
|
echo "export PATH=$destination_path/bin:$PATH" >> ~/.zshrc |
|
|
|
# Set permissions |
|
chmod -R 755 $destination_path |
|
|
|
# Step 7: Reload the shell |
|
echo "Reloading the shell..." |
|
zsh |
|
|
|
echo "Process completed successfully." |