Skip to content

Instantly share code, notes, and snippets.

@ryanjulian
Last active February 3, 2019 22:46
Show Gist options
  • Save ryanjulian/8162d97b3ec8ae2808b8588f4d8b4267 to your computer and use it in GitHub Desktop.
Save ryanjulian/8162d97b3ec8ae2808b8588f4d8b4267 to your computer and use it in GitHub Desktop.
conda installation script for louise
#!/usr/bin/env bash
# This script installs conda for CS188 on macOS distributions.
# Exit if any error occurs
# set -e
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
die()
{
local _ret=$2
test -n "$_ret" || _ret=1
test "$_PRINT_HELP" = yes && print_help >&2
echo "$1" >&2
exit ${_ret}
}
begins_with_short_option()
{
local first_option all_short_options
all_short_options='h'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && \
return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_mjkey=
_arg_modify_bashrc="on"
print_help ()
{
printf '%s\n' "Installer of garage for macOS."
printf 'Usage: %s [--mjkey <arg>] [--(no-)modify-bashrc] ' "$0"
printf '[-h|--help]\n'
printf '\t%s\n' "--mjkey: Path of the MuJoCo key (no default)"
printf '\t%s' "--modify-bashrc,--no-modify-bashrc: Set environment "
printf '%s\n' "variables in .bash_profile (off by default)"
printf '\t%s\n' "-h,--help: Prints help"
}
parse_commandline ()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
--mjkey)
test $# -lt 2 && \
die "Missing value for the optional argument '$_key'." 1
_arg_mjkey="$2"
shift
;;
--mjkey=*)
_arg_mjkey="${_key##--mjkey=}"
;;
--no-modify-bashrc|--modify-bashrc)
_arg_modify_bashrc="on"
test "${1:0:5}" = "--no-" && _arg_modify_bashrc="off"
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# Utility functions
script_dir_path() {
SCRIPT_DIR="$(dirname ${0})"
[[ "${SCRIPT_DIR}" = /* ]] && echo "${SCRIPT_DIR}" || \
echo "${PWD}/${SCRIPT_DIR#./}"
}
# red text
print_error() {
echo -e "\033[0;31m${@}\033[0m"
}
# yellow text
print_warning() {
echo -e "\033[0;33m${@}\033[0m"
}
# File where environment variables are stored
BASH_PROF="${HOME}/.bash_profile"
# Install dependencies
echo "Installing conda for Louise..."
# Leave a note in ~/.bash_profile for the added environment variables
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo -e "\n# Added by the conda installer" >> "${BASH_PROF}"
fi
# Set up conda
CONDA_SH="${HOME}/miniconda2/etc/profile.d/conda.sh"
if [[ ! -d "${HOME}/miniconda2" ]]; then
CONDA_INSTALLER="$(mktemp -d)/miniconda.sh"
curl https://repo.continuum.io/miniconda/Miniconda2-latest-MacOSX-x86_64.sh -o "${CONDA_INSTALLER}"
chmod u+x "${CONDA_INSTALLER}"
bash "${CONDA_INSTALLER}" -b -u
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo ". ${CONDA_SH}" >> "${BASH_PROF}"
fi
fi
# Export conda in this script
. "${CONDA_SH}"
conda update -q -y conda
# Create conda environment
{
conda create --name cs188 python=3.6 -y
}
if [[ "${?}" -ne 0 ]]; then
print_error "Error: conda environment could not be created"
fi
if [[ "${_arg_modify_bashrc}" != on ]]; then
echo -e "\nRemember to execute the following commands before working on CS188:"
echo ". ${CONDA_SH}"
echo "You may wish to edit your .bash_profile to prepend these commands."
fi
echo -e "\nconda is installed! To make the changes take effect, work under"
echo -e "a new terminal. Also, make sure to run \`conda activate cs188\`"
echo -e "whenever you open a new terminal and want to run programs under conda."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment