-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from nmfs-opensci/eeholmes-patch-1
switch user at start of script
- Loading branch information
Showing
8 changed files
with
209 additions
and
122 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,59 @@ | ||
#!/bin/bash | ||
# Required User: NB_USER | ||
|
||
echo "Running install-conda-packages.sh" | ||
|
||
echo " Checking for ${REPO_DIR}/childimage/..." | ||
if [ -d "${REPO_DIR}/childimage/" ]; then | ||
cd "${REPO_DIR}/childimage/" || exit 1 | ||
|
||
echo " Checking for conda-lock.yml or environment.yml in ${REPO_DIR}/childimage/..." | ||
if test -f "conda-lock.yml" || test -f "environment.yml"; then | ||
# Switch to NB_USER only if the relevant files exist | ||
if [[ $(id -u) -eq 0 ]]; then | ||
echo " Switching to ${NB_USER} to run install-conda-packages.sh" | ||
exec su "${NB_USER}" -c "/bin/bash $0" # Switches to NB_USER and reruns the script | ||
fi | ||
|
||
if test -f "conda-lock.yml"; then | ||
echo " Using conda-lock.yml" | ||
${NB_PYTHON_PREFIX}/bin/conda-lock install --name ${CONDA_ENV} | ||
${NB_PYTHON_PREFIX}/bin/pip install --no-deps jupyter-remote-desktop-proxy | ||
INSTALLATION_HAPPENED=true | ||
elif test -f "environment.yml"; then | ||
echo " Using environment.yml" | ||
${CONDA_DIR}/condabin/mamba env update --name ${CONDA_ENV} -f environment.yml | ||
${NB_PYTHON_PREFIX}/bin/pip install --no-deps jupyter-remote-desktop-proxy | ||
INSTALLATION_HAPPENED=true | ||
fi | ||
|
||
# Only run cleanup if installation occurred | ||
if [ "$INSTALLATION_HAPPENED" = true ]; then | ||
${CONDA_DIR}/condabin/mamba clean -yaf | ||
find ${CONDA_DIR} -follow -type f -name '*.a' -delete | ||
find ${CONDA_DIR} -follow -type f -name '*.js.map' -delete | ||
if ls ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static > /dev/null 2>&1; then | ||
find ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static -follow -type f -name '*.js' ! -name '*.min.js' -delete | ||
fi | ||
fi | ||
else | ||
echo " No conda-lock.yml or environment.yml found. Skipping installation." | ||
fi | ||
# Check if a filename argument is provided | ||
if [ -z "$1" ]; then | ||
echo "Error: install-conda-packages.sh requires a file name (either conda-lock.yml or environment.yml)." >&2 | ||
echo "Usage: RUN /pyrocket_scripts/install-conda-packages.sh <filename.yml>" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Check if running as root and switch to NB_USER if needed | ||
if [[ $(id -u) -eq 0 ]]; then | ||
echo "Switching to ${NB_USER} to run install-conda-packages.sh" | ||
exec su "${NB_USER}" -c "/bin/bash $0 $1" # Pass along the filename argument | ||
fi | ||
|
||
# Main script execution as NB_USER | ||
echo "Running install-conda-packages.sh as ${NB_USER}" | ||
|
||
# Set the file variable to the provided argument | ||
ENV_FILE="$1" | ||
|
||
# Verify the file exists and is readable | ||
if [ ! -f "$ENV_FILE" ]; then | ||
echo " Error: File '$ENV_FILE' not found. Please provide a valid file path." >&2 | ||
echo " Usage: RUN /pyrocket_scripts/install-conda-packages.sh <filename.yml>" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo " Found file: $ENV_FILE" | ||
|
||
# Determine file type based on content | ||
if grep -q "lock_set" "$ENV_FILE"; then | ||
echo " Detected conda-lock.yml file." | ||
${NB_PYTHON_PREFIX}/bin/conda-lock install --name ${CONDA_ENV} -f "$ENV_FILE" | ||
INSTALLATION_HAPPENED=true | ||
elif grep -q "name:" "$ENV_FILE"; then | ||
echo " Detected environment.yml file." | ||
${CONDA_DIR}/condabin/mamba env update --name ${CONDA_ENV} -f "$ENV_FILE" | ||
INSTALLATION_HAPPENED=true | ||
else | ||
echo " Directory ${REPO_DIR}/childimage/ does not exist. Skipping script." | ||
# If neither condition matches, output a helpful error message | ||
echo "Error: Unrecognized file format in '${env_file}'." | ||
echo " - For an environment.yml file, ensure it includes a 'name:' entry. Any name is acceptable." | ||
echo " - For a conda-lock.yml file, ensure it includes a 'lock_set:' entry." | ||
exit 1 | ||
fi | ||
|
||
# Run cleanup if installation occurred | ||
if [ "$INSTALLATION_HAPPENED" = true ]; then | ||
${CONDA_DIR}/condabin/mamba clean -yaf | ||
find ${CONDA_DIR} -follow -type f -name '*.a' -delete | ||
find ${CONDA_DIR} -follow -type f -name '*.js.map' -delete | ||
if ls ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static > /dev/null 2>&1; then | ||
find ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static -follow -type f -name '*.js' ! -name '*.min.js' -delete | ||
fi | ||
fi | ||
|
||
echo " Success! install-conda-packages.sh" |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,40 @@ | ||
#!/bin/bash | ||
# Required User: NB_USER | ||
|
||
echo "Running install-pip-packages.sh" | ||
|
||
echo " Checking for ${REPO_DIR}/childimage/..." | ||
if [ -d "${REPO_DIR}/childimage/" ]; then | ||
cd "${REPO_DIR}/childimage/" || exit 1 | ||
|
||
echo " Checking for requirements.txt in ${REPO_DIR}/childimage/..." | ||
if test -f "requirements.txt"; then | ||
# Switch to NB_USER only if requirements.txt exists | ||
if [[ $(id -u) -eq 0 ]]; then | ||
echo "Switching to ${NB_USER} to run install-pip-packages.sh" | ||
exec su "${NB_USER}" -c "/bin/bash $0" # Switches to NB_USER and reruns the script | ||
fi | ||
|
||
echo " Installing pip packages from requirements.txt as ${NB_USER}..." | ||
${NB_PYTHON_PREFIX}/bin/pip install --no-cache -r requirements.txt | ||
else | ||
echo " No requirements.txt found. Skipping pip installation." | ||
fi | ||
else | ||
echo " Directory ${REPO_DIR}/childimage/ does not exist. Skipping script." | ||
# Check if a filename argument is provided | ||
if [ -z "$1" ]; then | ||
echo "Error: install-pip-packages.sh requires an input file of package names (typically called requirements.txt)." >&2 | ||
echo "Usage: RUN /pyrocket_scripts/install-pip-packages.sh <filename>" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Check if running as root and switch to NB_USER if needed | ||
if [[ $(id -u) -eq 0 ]]; then | ||
echo "Switching to ${NB_USER} to run install-pip-packages.sh" | ||
exec su "${NB_USER}" -c "/bin/bash $0 $1" # Pass along the filename argument | ||
fi | ||
|
||
# Main script execution as NB_USER | ||
echo "Running install-pip-packages.sh as ${NB_USER}" | ||
|
||
|
||
# Set variable for the provided file | ||
requirements_file="$1" | ||
echo " Using packages file: ${requirements_file}" | ||
|
||
# Check if the specified file exists | ||
if [ ! -f "${requirements_file}" ]; then | ||
echo " Error: File '${requirements_file}' not found. Ensure the file exists and try again." | ||
exit 1 | ||
fi | ||
|
||
echo " Installing pip packages from ${requirements_file} as ${NB_USER}..." | ||
|
||
# Install pip packages and handle errors | ||
if ! ${NB_PYTHON_PREFIX}/bin/pip install --no-cache -r "${requirements_file}"; then | ||
echo " Error: Installation of packages from '${requirements_file}' failed. Please check the package names and try again." | ||
exit 1 | ||
fi | ||
|
||
echo " Success! install-pip-packages.sh" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
# Required User: NB_USER | ||
|
||
# Check if a filename argument is provided | ||
if [ -z "$1" ]; then | ||
echo "Error: install-r-packages.sh requires an input file (an R script and typically called install.R)." >&2 | ||
echo "Usage: RUN /pyrocket_scripts/install-r-packages.sh <filename>" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Check if running as root and switch to NB_USER if needed | ||
if [[ $(id -u) -eq 0 ]]; then | ||
echo "Switching to ${NB_USER} to run install-r-packages.sh" | ||
exec su "${NB_USER}" -c "/bin/bash $0 $1" # Pass along the filename argument | ||
fi | ||
|
||
# Main script execution as NB_USER | ||
echo "Running install-r-packages.sh as ${NB_USER}" | ||
|
||
# Set the file variable to the provided argument | ||
INSTALL_FILE="$1" | ||
|
||
# Verify the file exists and is readable | ||
if [ ! -f "$INSTALL_FILE" ]; then | ||
echo " Error: File '$INSTALL_FILE' not found. Please provide a valid R script file." >&2 | ||
echo " Usage: RUN /pyrocket_scripts/install-r-packages.sh <filename>" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo " Found file: $INSTALL_FILE" | ||
|
||
# Install R packages using the provided R script | ||
if ! Rscript "$INSTALL_FILE"; then | ||
echo " Error: Installation of packages from '$INSTALL_FILE' failed. Please check the script for errors." >&2 | ||
exit 1 | ||
fi | ||
|
||
echo " Success! install-r-packages.sh" |
This file contains 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
This file contains 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