Advertisement
abraha2d

_utils.sh

Apr 29th, 2023 (edited)
911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.92 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DEPLOY_SCRIPTS=$(dirname "${BASH_SOURCE[0]}")
  4. DEPLOY_ROOT=$(dirname "$DEPLOY_SCRIPTS")
  5.  
  6. source() {
  7.   local f="$1"
  8.   shift
  9.   builtin source "${f}" "${@}"
  10. }
  11.  
  12. cache_download() {
  13.   mkdir -p "$DEPLOY_ROOT/_cache"
  14.   if [[ ! -f "$DEPLOY_ROOT/_cache/$2" ]]; then
  15.     curl -L "$1" -o "$DEPLOY_ROOT/_cache/$2"
  16.   else
  17.     echo "[_cache] Found $2" 1>&2
  18.   fi
  19.   echo "$DEPLOY_ROOT/_cache/$2"
  20. }
  21.  
  22. MF_FILE="Mambaforge-$(uname)-$(uname -m).sh"
  23. MF_URL="https://github.com/conda-forge/miniforge/releases/latest/download/$MF_FILE"
  24.  
  25. get_base_env() {
  26.   base_env="/opt/mf"
  27.   if [ ! -d "$base_env" ]; then
  28.     base_env="$DEPLOY_ROOT/envs/_base"
  29.   fi
  30.  
  31.   if [[ ! -f "$base_env/bin/activate" ]]; then
  32.     echo "Downloading Mambaforge..." 1>&2
  33.     mf_installer=$(cache_download "$MF_URL" "$MF_FILE")
  34.  
  35.     echo "Installing Mambaforge..." 1>&2
  36.     bash "$mf_installer" -bfp "$base_env" 1>&2
  37.   fi
  38.  
  39.   echo "$base_env"
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement