2## @brief Miniconda control functions
4## @section miniconda_example Example
5## @include miniconda_setup.sh
7(( $EC2PINIT_MINICONDA_INCLUDED )) &&
return
8EC2PINIT_MINICONDA_INCLUDED=1
11# URL to a site providing miniconda installers
12mc_url=
"https://repo.anaconda.com/miniconda"
14# Name of miniconda installation script
15mc_installer=
"miniconda3_install.sh"
20## @brief Get the default bash rc script for the user account
24## # rc=/home/example/.bash_profile
28## # rc=/home/example/.bashrc
30## @retval 1 if ``home`` does not exist
32 local scripts=(.bashrc .bashrc_profile .profile)
33 local home=
"$(sys_user_home ${1:-$USER})"
34 if [ -z
"$home" ] || [ ! -d
"$home" ]; then
38 for x in
"${scripts[@]}";
do
39 local filename=
"$home/$x"
40 [ ! -f
"$filename" ] &&
continue
48## @brief Download Miniconda3
49## @details Installation script destination is set by global $mc_installer
50## @param version Miniconda3 release version...
52## @param version "latest" if empty
55 local version=
"${1:-latest}"
56 local dest=
"$ec2pinit_tempdir"
57 local platform=
"$(sys_platform)"
58 local arch=
"$(sys_arch)"
59 local name=
"Miniconda3-$version-$platform-$arch.sh"
61 if [ -f
"$dest/$mc_installer" ]; then
62 io_warn "mc_get: $dest/$mc_installer exists"
65 io_info "mc_get: Downloading $mc_url/$name"
66 io_info "mc_get: Destination: $dest/$mc_installer"
68 curl -L -o
"$dest/$mc_installer" "$mc_url/$name"
69 # Is this a bug or what?
70 # curl exits zero on success but causes "if mc_get" to fail
71 # as if it exited non-zero. I'm forcing the conditions I need
73 (( $? != 0 )) &&
return 1
78## @fn mc_configure_defaults()
79## @brief Sets global defaults for conda and pip
81 if [ -z
"$CONDA_EXE" ]; then
82 # Not initialized correctly
83 io_error "mc_configure_defaults: conda is not initialized"
86 io_info "mc_configure_defaults: Configuring conda options"
87 conda config --system --set auto_update_conda
false
88 conda config --system --set always_yes
true
89 conda config --system --set report_errors
false
91 # Some skeletons default to .bashrc instead of .bash_profile.
93 io_info "mc_configure_defaults: Enabling verbose output from pip"
94 if ! grep -E
'[^#](export)?[\t\ ]+PIP_VERBOSE=' "$rc" &>/dev/null; then
95 echo export PIP_VERBOSE=1 >>
"$rc"
96 io_info "mc_configure_defaults: $rc modified"
98 io_info "mc_configure_defaults: $rc not modified"
103## @fn mc_initialize()
104## @brief Configures user account to load conda at login
105## @param dest path to miniconda installation root
108 if [[ $- =~ v ]]; then
112 if [[ $- =~ x ]]; then
117 io_info "mc_initialize: Using conda: $dest"
119 # Configure the user's shell
120 if (( ! $EUID )); then
121 if ! grep -E
'#.*>>>.*conda initialize.*>>>$' $(
_get_rc) &>/dev/null; then
122 sudo -u $USER dest=$dest -i bash -c
'source "$dest"/etc/profile.d/conda.sh ; conda init'
126 # Give current context access to the miniconda installation
127 source
"$dest"/etc/profile.d/conda.sh
133## @brief Installs Miniconda3
134## @param version of the Miniconda3 installer (i.e., py39_4.11.0)
135## @param dest path to install Miniconda3 (~/miniconda3)
136## @retval 1 if any argument is invalid
137## @retval 1 if destination exists
138## @retval 1 if download fails
139## @retval 1 if installation fails (implicit)
143 local cmd=
"bash "$ec2pinit_tempdir/$mc_installer
" -b -p $dest"
145 if [ -z
"$version" ]; then
146 io_error "mc_install: miniconda version required" >&2
150 if [ -z
"$dest" ]; then
151 io_error "mc_install: miniconda destination directory required" >&2
153 elif [ -d
"$dest" ]; then
154 io_error "mc_install: miniconda destination directory exists" >&2
158 if mc_get "$version"; then
159 io_error "mc_install: unable to obtain miniconda from server" >&2
163 io_info "mc_install: Installing conda: $dest"
169## @brief Remove unused tarballs, caches, indexes, etc
170## @retval 1 if miniconda is not initialized
172 if [ -z
"$CONDA_EXE" ]; then
173 # Not initialized correctly
174 io_error "mc_clean: conda is not initialized"
io_warn(...)
Print a warning message.
io_info(...)
Print a message.
io_error(...)
Print an error message.
mc_initialize(dest)
Configures user account to load conda at login.
mc_configure_defaults()
Sets global defaults for conda and pip.
mc_get(version, version)
Download Miniconda3.
mc_install(version, dest)
Installs Miniconda3.
_get_rc()
Get the default bash rc script for the user account.
mc_clean()
Remove unused tarballs, caches, indexes, etc.