summaryrefslogtreecommitdiff
path: root/resources
diff options
context:
space:
mode:
Diffstat (limited to 'resources')
-rw-r--r--resources/edu/stsci/include/compat.sh25
-rw-r--r--resources/edu/stsci/include/die.sh6
-rw-r--r--resources/edu/stsci/lib/conda.sh77
-rw-r--r--resources/edu/stsci/lib/workspace.sh18
4 files changed, 103 insertions, 23 deletions
diff --git a/resources/edu/stsci/include/compat.sh b/resources/edu/stsci/include/compat.sh
index a8b46a0..10614b8 100644
--- a/resources/edu/stsci/include/compat.sh
+++ b/resources/edu/stsci/include/compat.sh
@@ -36,3 +36,28 @@ shutil_compat_replace() {
mv ${tmp} ${args[0]}
}
+shutil_compat_fetch() {
+ local url supported supported_args
+ supported=(
+ curl
+ wget
+ )
+ supported_args=(
+ '-L -O'
+ '-O'
+ )
+
+ url="${1}"
+ if [[ -z ${url} ]]; then
+ echo "shutil_compat_fetch: url required" >&2
+ exit 1
+ fi
+
+ for i in $(seq 0 "${#supported[@]}")
+ do
+ if [[ $(which ${supported[$i]} 2>/dev/null) ]]; then
+ ${supported[$i]} ${supported_args[$i]} "${url}"
+ break
+ fi
+ done
+}
diff --git a/resources/edu/stsci/include/die.sh b/resources/edu/stsci/include/die.sh
new file mode 100644
index 0000000..323792d
--- /dev/null
+++ b/resources/edu/stsci/include/die.sh
@@ -0,0 +1,6 @@
+[[ -n ${_shutil_die_header} ]] && return || readonly _shutil_die_header=1
+
+shutil_die() {
+ echo "shutil_die: ${1-no_error_specified_by_caller}" >&2
+ exit 1
+}
diff --git a/resources/edu/stsci/lib/conda.sh b/resources/edu/stsci/lib/conda.sh
index e304a57..befd307 100644
--- a/resources/edu/stsci/lib/conda.sh
+++ b/resources/edu/stsci/lib/conda.sh
@@ -1,12 +1,9 @@
#!/bin/bash
+source ${EDU_STSCI_SHUTIL_INCLUDE}/die.sh
+source ${EDU_STSCI_SHUTIL_INCLUDE}/compat.sh
source ${EDU_STSCI_SHUTIL_INCLUDE}/conda.sh
-shutil_conda_die() {
- echo "shutil_conda_die: ${1-no_error_specified_by_caller}"
- exit 1
-}
-
shutil_conda_exists() {
retval=0
if ! type -p conda ; then
@@ -19,21 +16,59 @@ shutil_conda_exists() {
shutil_conda_infect() {
if [[ $(shutil_conda_exists) != 0 ]]; then
- shutil_conda_die "cannot dump environment key pairs"
+ shutil_die "shutil_conda_infect: cannot dump environment key pairs"
fi
printenv | sort
}
-shutil_conda_install() {
- local version prefix
- #TODO
+shutil_conda_installer() {
+ local arch platform prefix retval script url version
+
+ arch=$(uname -m)
+ platform=$(uname -s)
+
+ case "${arch}" in
+ i[0-9]+)
+ echo "shutil_conda_installer: caution: 32-bit architecture detected. Continue at your peril." >&2
+ arch=x86
+ ;;
+ *)
+ ;;
+ esac
+
+ case "${platform}" in
+ Darwin)
+ platform=MacOSX
+ ;;
+ *)
+ ;;
+ esac
+
+ version="${1}"
+ prefix="${2}"
+ script="Miniconda3-${version}-${platform}-${arch}.sh"
+ url="${_URL_CONTINUUMIO_MINICONDA}/${script}"
+
+ if [[ ! -f ${script} ]]; then
+ shutil_compat_fetch "${url}"
+ fi
+
+ if [[ -d ${prefix} ]]; then
+ echo "shutil_conda_installer: warning: ${prefix} exists, installation skipped." >&2
+ return
+ fi
+ bash ./"${script}" -b -p "${prefix}"
+ retval=$?
+ if [[ ${retval} != 0 ]]; then
+ exit ${retval}
+ fi
}
shutil_conda_withenv() {
if [[ $(shutil_conda_exists) != 0 ]]; then
- shutil_conda_die "unable to execute: conda must be on \$PATH or activated via 'conda' function"
+ shutil_die "shutil_conda_withenv: unable to execute: conda must be on \$PATH or activated via 'conda' function"
fi
local commands environ exe key
environ=base
@@ -65,7 +100,7 @@ shutil_conda_withenv() {
shutil_conda_root() {
if [[ $(shutil_conda_exists) != 0 ]]; then
- shutil_conda_die "cannot get root directory"
+ shutil_die "shutil_conda_root: cannot get root directory"
fi
local version
version=$(shutil_conda_withenv conda --version)
@@ -76,7 +111,7 @@ shutil_conda_root() {
shutil_conda_version() {
if [[ $(shutil_conda_exists) != 0 ]]; then
- shutil_conda_die "cannot get version"
+ shutil_die "shutil_conda_version: cannot get version"
fi
local version
version=$(shutil_conda_withenv conda --version)
@@ -89,7 +124,7 @@ shutil_conda_init_from_prefix() {
local prefix profile target
prefix="${1}"
if [[ ! -d ${prefix}/bin ]]; then
- shutil_conda_die "expected conda root , but got '${prefix}'"
+ shutil_die "shutil_conda_init_from_prefix: expected conda root, but got '${prefix}'"
fi
profile="${prefix}"/etc/profile.d/conda.sh
@@ -105,7 +140,7 @@ shutil_conda_init_from_prefix() {
shutil_conda_env_dump() {
if [[ $(shutil_conda_exists) != 0 ]]; then
- shutil_conda_die "unable to execute: conda must be on \$PATH or activated via 'conda' function"
+ shutil_die "shutil_conda_env_dump: unable to execute: conda must be on \$PATH or activated via 'conda' function"
fi
local commands environ key output use_yaml use_explicit
environ=base
@@ -150,19 +185,21 @@ shutil_conda_env_dump() {
shutil_conda_withenv -n "${environ}" conda list --name "${environ}" --explicit > "${output}".txt "${commands[@]}"
retval=$?
else
- shutil_conda_die "shutil_conda_env_dump: unknown operation: ${commands[@]}"
+ shutil_die "shutil_conda_env_dump: unknown operation: ${commands[@]}"
fi
if [[ ${retval} != 0 ]]; then
- shutil_conda_die "shutil_conda_env_dump: operation failed: ${@}"
+ shutil_die "shutil_conda_env_dump: operation failed: ${@}"
fi
}
set -x
-shutil_conda_init_from_prefix ~/Downloads/miniconda3
-shutil_conda_env_dump --yaml
-shutil_conda_env_dump --explicit
-cat environment.*
+
+shutil_conda_installer latest ~/Downloads/lesigh
+shutil_conda_init_from_prefix ~/Downloads/lesigh
+#shutil_conda_env_dump --yaml
+#shutil_conda_env_dump --explicit
+#cat environment.*
#export PATH=~/Downloads/miniconda3/bin:$PATH
#source ~/Downloads/miniconda3/etc/profile.d/conda.sh
#conda activate
diff --git a/resources/edu/stsci/lib/workspace.sh b/resources/edu/stsci/lib/workspace.sh
index 63f87a2..42749ac 100644
--- a/resources/edu/stsci/lib/workspace.sh
+++ b/resources/edu/stsci/lib/workspace.sh
@@ -3,10 +3,11 @@ shutil_ws_path() {
}
shutil_ws_search() {
- local pattern
+ local ftype pattern
+ ftype="${ftype-f}"
pattern="${1-*}"
- for f in $(find $(shutil_ws_path) -type f -name "${pattern}" | xargs)
+ for f in $(find $(shutil_ws_path) -type "${ftype}" -name "${pattern}" | xargs)
do
echo "${f}"
done
@@ -16,7 +17,7 @@ shutil_ws_file_exists() {
local filename
filename="${1}"
if [[ -z ${filename} ]]; then
- echo "exists_in_ws() missing argument: filename" >&2
+ echo "shutil_ws_file_exists: missing argument: filename" >&2
echo 0
return
fi
@@ -24,3 +25,14 @@ shutil_ws_file_exists() {
([[ -n $(shutil_ws_search "${filename}") ]] && echo 1) || echo 0
}
+shutil_ws_dir_exists() {
+ local filename
+ filename="${1}"
+ if [[ -z ${filename} ]]; then
+ echo "shutil_ws_dir_exists: missing argument: filename" >&2
+ echo 0
+ return
+ fi
+
+ ([[ -n $(shutil_ws_search "${filename}") ]] && echo 1) || echo 0
+}