Last active
January 9, 2025 23:58
-
-
Save mherkazandjian/cce01cf3e15c0b41c1c4321245a99096 to your computer and use it in GitHub Desktop.
miniconda batch/slient web installation wrapper that can be executed also without downloading/saving it to disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
################################################## | |
# usage: | |
# $ ./install_miniconda.sh ~/apps/miniconda | |
# $ ./install_miniconda.sh ~/apps/miniconda --mamba | |
# $ ./install_miniconda.sh ~/apps/miniconda --installer latest | |
# $ ./install_miniconda.sh ~/apps/miniconda --upgrade --mamba | |
# $ ./install_miniconda.sh ~/apps/miniconda --installer latest --upgrade --mamba | |
# $ ./install_miniconda.sh ~/apps/miniconda --installer Miniconda3-py310_23.5.1-0-Linux-x86_64.sh --upgrade --mamba | |
# execute the script without saving it to disk: | |
# $ curl -s https://gist.githubusercontent.com/mherkazandjian/cce01cf3e15c0b41c1c4321245a99096/raw/d6709fdbb9b06fe16c48fd4e6a9008236122b9ff/miniconda_installer.sh | bash -s -- ~/miniconda --mamba | |
################################################## | |
#!/bin/bash | |
function usage() { | |
local script_name=$(basename "$0") | |
echo "Usage: $script_name /path/to/prefix/ [-u|--upgrade] [-i|--installer <installer_name>]" | |
echo " /path/to/prefix/ the installation root directory of miniconda (e.g /opt/conda)" | |
echo " -i|--installer the miniconda installer name (e.g Miniconda3-latest-Linux-x86_64.sh)" | |
echo " others can be specified from https://repo.anaconda.com/miniconda/" | |
echo " -m|--mamba install mamba in the base environment" | |
echo " -u|--upgrade upgrade miniconda packages" | |
echo " -h|--help show this help text" | |
exit 0 | |
} | |
# the installation root directory of miniconda (e.g /opt/conda) | |
INSTALL_PREFIX=$1 | |
shift | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-i|--installer) | |
[ -n "$2" ] && INSTALLER=$2 || usage | |
shift | |
;; | |
-m|--mamba) | |
[ -n "$1" ] && MAMBA=1 || usage | |
;; | |
-u|--upgrade) | |
[ -n "$1" ] && UPGRADE=1 || usage | |
;; | |
-h|--help) | |
usage | |
;; | |
*) | |
usage | |
;; | |
esac | |
shift | |
done | |
shift $((OPTIND - 1)) | |
# ---------------- process the cmd line args ---------------- | |
## if the installer is latest use the latest online installed | |
if [ "${INSTALLER}" == "latest" ]; then | |
INSTALLER="Miniconda3-latest-Linux-x86_64.sh" | |
fi | |
# ----------------------------------------------------------- | |
# set the defaults and the values based on what has been passed from the | |
# command line | |
INSTALLER=${INSTALLER:-Miniconda3-py312_24.11.1-0-Linux-x86_64.sh} | |
UPGRADE=${UPGRADE:-0} | |
MAMBA=${MAMBA:-0} | |
# --------------------------------- | |
# the absolute path of the miniconda installer (e.g Miniconda3-latest-Linux-x86_64.sh | |
# after it is downloaded. This is where curl will try to put it | |
INSTALLER_PATH=/tmp/${INSTALLER} | |
function _install_miniconda() { | |
echo "Installing miniconda to ${INSTALL_PREFIX}" | |
echo "Installer: ${INSTALLER}" | |
echo "Mamba: ${MAMBA}" | |
echo "Upgrade: ${UPGRADE}" | |
curl -s -L https://repo.anaconda.com/miniconda/${INSTALLER} -o ${INSTALLER_PATH} | |
chmod +x ${INSTALLER_PATH} | |
${INSTALLER_PATH} -b -p ${INSTALL_PREFIX} | |
rm ${INSTALLER_PATH} | |
${INSTALL_PREFIX}/bin/conda upgrade -y --all | |
${INSTALL_PREFIX}/bin/conda clean -ya | |
${INSTALL_PREFIX}/bin/conda install -y conda-build conda-verify | |
if [ $UPGRADE -eq 1 ]; then | |
${INSTALL_PREFIX}/bin/conda upgrade -y --all | |
${INSTALL_PREFIX}/bin/conda clean -ya | |
${INSTALL_PREFIX}/bin/conda install -y conda-build conda-verify | |
fi | |
if [ $MAMBA -eq 1 ]; then | |
${INSTALL_PREFIX}/bin/conda install -y mamba -n base -c conda-forge | |
fi | |
} | |
_install_miniconda |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment