From 04e28a10bf28fef098ebae3ba6d9cff2e2237576 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:30:13 -0800 Subject: [PATCH 01/19] Update install-conda-packages.sh --- scripts/install-conda-packages.sh | 87 ++++++++++++++++++------------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/scripts/install-conda-packages.sh b/scripts/install-conda-packages.sh index e373f5b..b4b73a0 100644 --- a/scripts/install-conda-packages.sh +++ b/scripts/install-conda-packages.sh @@ -1,44 +1,57 @@ #!/bin/bash # Required User: NB_USER +# Main script execution as 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 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 + +# Check if a filename argument is provided +if [ -z "$1" ]; then + echo " Error: This script requires a file name (either conda-lock.yml or environment.yml)." >&2 + echo " Usage: RUN /pyrocket_scripts/install-conda-packages.sh " >&2 + exit 1 +fi + +# 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 " >&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 From 71a46c5e66ab7671ecd4d8b23e099a88f8fe3f7d Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:31:26 -0800 Subject: [PATCH 02/19] Update install-conda-packages.sh --- scripts/install-conda-packages.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install-conda-packages.sh b/scripts/install-conda-packages.sh index b4b73a0..87419c1 100644 --- a/scripts/install-conda-packages.sh +++ b/scripts/install-conda-packages.sh @@ -1,15 +1,15 @@ #!/bin/bash # Required User: NB_USER -# Main script execution as NB_USER -echo "Running install-conda-packages.sh" - # 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" + 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" + # Check if a filename argument is provided if [ -z "$1" ]; then echo " Error: This script requires a file name (either conda-lock.yml or environment.yml)." >&2 From 411cece2e037b65c45fa6912007c25b692e8576d Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:40:33 -0800 Subject: [PATCH 03/19] Update install-apt-packages.sh --- scripts/install-apt-packages.sh | 71 +++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/scripts/install-apt-packages.sh b/scripts/install-apt-packages.sh index f788301..1c129b4 100644 --- a/scripts/install-apt-packages.sh +++ b/scripts/install-apt-packages.sh @@ -2,29 +2,50 @@ # Required User: root echo "Running install-apt-packages.sh" -echo " Checking for ${REPO_DIR}/childimage/..." -if [ -d "${REPO_DIR}/childimage/" ]; then - cd "${REPO_DIR}/childimage/" || exit 1 - - echo " Checking for apt.txt in ${REPO_DIR}/childimage/..." - if test -f "apt.txt"; then - # Check if the script is run as root - if [[ $(id -u) -ne 0 ]]; then - echo " Error: This script must be run as root." >&2 # Output error message to standard error - exit 1 # Exit with a non-zero status to indicate failure - fi - - echo " Running install-apt-packages.sh as root. Proceeding with installation..." - - package_list=$(grep -v '^\s*#' apt.txt | grep -v '^\s*$' | sed 's/\r//g; s/#.*//; s/^[[:space:]]*//; s/[[:space:]]*$//' | awk '{$1=$1};1') - apt-get update --fix-missing > /dev/null - apt-get install --yes --no-install-recommends $package_list - apt-get autoremove --purge - apt-get clean - rm -rf /var/lib/apt/lists/* - else - echo " No apt.txt found. Skipping package installation." - fi -else - echo " Directory ${REPO_DIR}/childimage/ does not exist. Skipping script." + +# Check that a file name is provided +if [ -z "$1" ]; then + echo " Error: No file provided. Usage: RUN /pyrocket_scripts/install-apt-packages.sh " + exit 1 +fi + +# Set variable for the provided file +apt_file="$1" +echo " Using packages file: ${apt_file}" + +# Check if the specified file exists +if [ ! -f "${apt_file}" ]; then + echo " Error: File '${apt_file}' not found. Ensure the file exists and try again." + exit 1 fi + +# Check if the script is run as root +if [[ $(id -u) -ne 0 ]]; then + echo " Error: This script must be run as root. Please use 'USER root' in your Dockerfile before running this script." + echo " Remember to switch back to the non-root user with 'USER ${NB_USER}' after running this script." + exit 1 +fi + +echo " Running install-apt-packages.sh as root. Proceeding with installation..." + +# Update package list and handle errors +echo " Updating package list..." +if ! apt-get update --fix-missing; then + echo " Error: Failed to update package list. Exiting." + exit 1 +fi + +# Install packages and handle errors +echo " Installing packages from ${apt_file}..." +package_list=$(grep -v '^\s*#' "${apt_file}" | grep -v '^\s*$' | sed 's/\r//g; s/#.*//; s/^[[:space:]]*//; s/[[:space:]]*$//' | awk '{$1=$1};1') +if ! apt-get install --yes --no-install-recommends $package_list; then + echo " Error: Installation of packages failed. Please check the package names and try again." + exit 1 +fi + +# Clean up +apt-get autoremove --purge +apt-get clean +rm -rf /var/lib/apt/lists/* + +echo " Success! install-apt-packages.sh" From 21a23d92ddfa685a0493d37a1c760e7940ed0a2b Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:40:58 -0800 Subject: [PATCH 04/19] Update install-conda-packages.sh --- scripts/install-conda-packages.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install-conda-packages.sh b/scripts/install-conda-packages.sh index 87419c1..9406fa7 100644 --- a/scripts/install-conda-packages.sh +++ b/scripts/install-conda-packages.sh @@ -55,3 +55,5 @@ if [ "$INSTALLATION_HAPPENED" = true ]; 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" From 2f308ad5a3f134fb2ba46a91bfba61dc14545579 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:44:10 -0800 Subject: [PATCH 05/19] Update install-pip-packages.sh --- scripts/install-pip-packages.sh | 50 ++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/scripts/install-pip-packages.sh b/scripts/install-pip-packages.sh index 5b48e6c..b8aed88 100644 --- a/scripts/install-pip-packages.sh +++ b/scripts/install-pip-packages.sh @@ -3,23 +3,35 @@ 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 that a file name is provided +if [ -z "$1" ]; then + echo "Error: No file provided. Usage: RUN /pyrocket_scripts/install-pip-packages.sh " + exit 1 fi + +# 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 + +# Check if the script is run as the expected user +if [[ $(id -u) -ne $(id -u "${NB_USER}") ]]; then + echo "Error: This script must be run as ${NB_USER}. Please use USER ${NB_USER} in your Dockerfile before running this script." + 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 " Pip packages installed successfully." + From 7e67a037bb78bb4e254d75b80581fe91241f5e97 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:48:16 -0800 Subject: [PATCH 06/19] Update install-pip-packages.sh --- scripts/install-pip-packages.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/scripts/install-pip-packages.sh b/scripts/install-pip-packages.sh index b8aed88..e83e6d0 100644 --- a/scripts/install-pip-packages.sh +++ b/scripts/install-pip-packages.sh @@ -1,27 +1,29 @@ #!/bin/bash # Required User: NB_USER -echo "Running install-pip-packages.sh" +# 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}" -# Check that a file name is provided +# Check if a filename argument is provided if [ -z "$1" ]; then - echo "Error: No file provided. Usage: RUN /pyrocket_scripts/install-pip-packages.sh " + echo " Error: This script requires a requirements.txt file." >&2 + echo " Usage: RUN /pyrocket_scripts/install-pip-packages.sh " >&2 exit 1 fi # Set variable for the provided file requirements_file="$1" -echo "Using packages file: ${requirements_file}" +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 - -# Check if the script is run as the expected user -if [[ $(id -u) -ne $(id -u "${NB_USER}") ]]; then - echo "Error: This script must be run as ${NB_USER}. Please use USER ${NB_USER} in your Dockerfile before running this script." + echo " Error: File '${requirements_file}' not found. Ensure the file exists and try again." exit 1 fi @@ -29,9 +31,9 @@ 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." + echo " Error: Installation of packages from '${requirements_file}' failed. Please check the package names and try again." exit 1 fi -echo " Pip packages installed successfully." +echo " Success! install-pip-packages.sh" From a1d5f507789afea7406a3fd085248bc377937a99 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:52:31 -0800 Subject: [PATCH 07/19] Update install-r-package.sh --- scripts/install-r-package.sh | 51 ++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/scripts/install-r-package.sh b/scripts/install-r-package.sh index d78da84..197982a 100644 --- a/scripts/install-r-package.sh +++ b/scripts/install-r-package.sh @@ -1,25 +1,38 @@ #!/bin/bash # Required User: NB_USER +# 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" -echo " Checking for ${REPO_DIR}/childimage/..." -if [ -d "${REPO_DIR}/childimage/" ]; then - cd "${REPO_DIR}/childimage/" || exit 1 - - echo " Checking for install.R in ${REPO_DIR}/childimage/..." - if test -f "install.R"; then - # Switch to NB_USER only if install.R exists - 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" # Switches to NB_USER and reruns the script - fi - - echo " Using install.R to install R packages as ${NB_USER}..." - Rscript install.R - else - echo " No install.R found. Skipping R package 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: This script requires a file name (install.R)." >&2 + echo " Usage: RUN /pyrocket_scripts/install-r-packages.sh " >&2 + exit 1 +fi + +# 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 " >&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" From 1cd046b5111983d9353d4f067ac7803ee5b4deab Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:52:46 -0800 Subject: [PATCH 08/19] Rename install-r-package.sh to install-r-packages.sh --- scripts/{install-r-package.sh => install-r-packages.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{install-r-package.sh => install-r-packages.sh} (100%) diff --git a/scripts/install-r-package.sh b/scripts/install-r-packages.sh similarity index 100% rename from scripts/install-r-package.sh rename to scripts/install-r-packages.sh From f1c68df277fba95dad10e282eb8225f374c4459e Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:53:34 -0800 Subject: [PATCH 09/19] Rename setup-desktop.sh to install-desktop.sh --- scripts/{setup-desktop.sh => install-desktop.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{setup-desktop.sh => install-desktop.sh} (100%) diff --git a/scripts/setup-desktop.sh b/scripts/install-desktop.sh similarity index 100% rename from scripts/setup-desktop.sh rename to scripts/install-desktop.sh From 77d0479899a19ed1924584563643225e9699aa52 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 07:59:12 -0800 Subject: [PATCH 10/19] Update install-desktop.sh --- scripts/install-desktop.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/install-desktop.sh b/scripts/install-desktop.sh index 820c6f0..5652ff6 100644 --- a/scripts/install-desktop.sh +++ b/scripts/install-desktop.sh @@ -3,19 +3,26 @@ echo "Running setup-desktop.sh" +# Check if the script is run as root +if [[ $(id -u) -ne 0 ]]; then + echo " Error: This script must be run as root. Please use 'USER root' in your Dockerfile before running this script." + echo " Remember to switch back to the non-root user with 'USER ${NB_USER}' after running this script." + exit 1 +fi + +# Check if a filename argument is provided +if [ -n "$1" ]; then + echo " Warning: Passed-in file '$1' is ignored. Looking for Desktop files in the 'Desktop' directory in your repository." >&2 +fi + echo " Checking for ${REPO_DIR}/childimage/..." if [ -d "${REPO_DIR}/childimage/" ]; then cd "${REPO_DIR}/childimage/" || exit 1 echo " Checking for Desktop directory..." if test -d "${REPO_DIR}/childimage/Desktop"; then - # Check if the script is run as root - if [[ $(id -u) -ne 0 ]]; then - echo " Error: This script must be run as root." >&2 # Output error message to standard error - exit 1 # Exit with a non-zero status to indicate failure - fi - echo " Running setup-desktop.sh as root. Proceeding with installation..." + echo " ${REPO_DIR}/childimage/Desktop directory found. Proceeding with installation..." mkdir -p "${REPO_DIR}/Desktop" cp -r ${REPO_DIR}/childimage/Desktop/* "${REPO_DIR}/Desktop/" 2>/dev/null @@ -34,3 +41,5 @@ if [ -d "${REPO_DIR}/childimage/" ]; then else echo " Directory ${REPO_DIR}/childimage/ does not exist. Skipping script." fi + +echo " Success! install-desktop.sh" From 3cb6c6a8e7f8cd34aa3fc99c1baf3c16b02d2311 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:00:17 -0800 Subject: [PATCH 11/19] Update install-conda-packages.sh --- scripts/install-conda-packages.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install-conda-packages.sh b/scripts/install-conda-packages.sh index 9406fa7..d53e831 100644 --- a/scripts/install-conda-packages.sh +++ b/scripts/install-conda-packages.sh @@ -8,7 +8,7 @@ if [[ $(id -u) -eq 0 ]]; then fi # Main script execution as NB_USER -echo "Running install-conda-packages.sh" +echo "Running install-conda-packages.sh as ${NB_USER}" # Check if a filename argument is provided if [ -z "$1" ]; then From c955cfad0cc7f1bb5f36504f114e3ac35def4d8d Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:02:59 -0800 Subject: [PATCH 12/19] Update setup-start.sh --- scripts/setup-start.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/setup-start.sh b/scripts/setup-start.sh index 5068531..ae84f03 100644 --- a/scripts/setup-start.sh +++ b/scripts/setup-start.sh @@ -1,7 +1,13 @@ #!/bin/bash # Required User: NB_USER -echo "Running setup-start.sh" +# 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 start.sh" + exec su "${NB_USER}" -c "/bin/bash $0" # Switches to NB_USER and reruns the script +fi + +echo "Running setup-start.sh as ${NB_USER}" echo " Checking for ${REPO_DIR}/childimage/..." if [ -d "${REPO_DIR}/childimage/" ]; then From be6a5200c8d29dc75a181ac094b99e12c81c9450 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:04:51 -0800 Subject: [PATCH 13/19] Update setup-start.sh --- scripts/setup-start.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/setup-start.sh b/scripts/setup-start.sh index ae84f03..9badd2e 100644 --- a/scripts/setup-start.sh +++ b/scripts/setup-start.sh @@ -9,6 +9,11 @@ fi echo "Running setup-start.sh as ${NB_USER}" +# Check if a filename argument is provided +if [ -n "$1" ]; then + echo " Warning: Passed-in file '$1' is ignored. Looking for a file named 'start' in your repository." >&2 +fi + echo " Checking for ${REPO_DIR}/childimage/..." if [ -d "${REPO_DIR}/childimage/" ]; then cd "${REPO_DIR}/childimage/" || exit 1 @@ -16,11 +21,6 @@ if [ -d "${REPO_DIR}/childimage/" ]; then echo " Checking for start in ${REPO_DIR}/childimage/..." if test -f "start"; then echo " start found in ${REPO_DIR}/childimage/." - # Switch to NB_USER only if the start file exists - if [[ $(id -u) -eq 0 ]]; then - echo " Switching to ${NB_USER} to run setup-start.sh" - exec su "${NB_USER}" -c "/bin/bash $0" # Switches to NB_USER and reruns the script - fi chmod +x start else echo " No start file found in ${REPO_DIR}/childimage/. Skipping." @@ -28,3 +28,5 @@ if [ -d "${REPO_DIR}/childimage/" ]; then else echo " Directory ${REPO_DIR}/childimage/ does not exist. Skipping." fi + +echo " Success! setup-start.sh" From 21341081cc3d172fef3ae31fe31c6f409e133451 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:09:52 -0800 Subject: [PATCH 14/19] Update install-conda-packages.sh --- scripts/install-conda-packages.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/install-conda-packages.sh b/scripts/install-conda-packages.sh index d53e831..937420f 100644 --- a/scripts/install-conda-packages.sh +++ b/scripts/install-conda-packages.sh @@ -1,6 +1,13 @@ #!/bin/bash # Required User: NB_USER +# 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 " >&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" @@ -10,13 +17,6 @@ fi # Main script execution as NB_USER echo "Running install-conda-packages.sh as ${NB_USER}" -# Check if a filename argument is provided -if [ -z "$1" ]; then - echo " Error: This script requires a file name (either conda-lock.yml or environment.yml)." >&2 - echo " Usage: RUN /pyrocket_scripts/install-conda-packages.sh " >&2 - exit 1 -fi - # Set the file variable to the provided argument ENV_FILE="$1" From 5a8d7fe66615004b87d0dd2516fba516ff37caef Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:13:10 -0800 Subject: [PATCH 15/19] Update install-apt-packages.sh --- scripts/install-apt-packages.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/install-apt-packages.sh b/scripts/install-apt-packages.sh index 1c129b4..135eb60 100644 --- a/scripts/install-apt-packages.sh +++ b/scripts/install-apt-packages.sh @@ -5,10 +5,20 @@ echo "Running install-apt-packages.sh" # Check that a file name is provided if [ -z "$1" ]; then - echo " Error: No file provided. Usage: RUN /pyrocket_scripts/install-apt-packages.sh " + echo "Error: install-apt-packages.sh requires a file name (a list of apt packages and typically called apt.txt)." >&2 + echo "Usage: RUN /pyrocket_scripts/install-apt-packages.sh " >&2 exit 1 fi +# Check if the script is run as root +if [[ $(id -u) -ne 0 ]]; then + echo "Error: install-apt-packages.sh must be run as root. Please use 'USER root' in your Dockerfile before running this script." + echo "Remember to switch back to the non-root user with 'USER ${NB_USER}' after running this script." + exit 1 +fi + +echo "Running install-apt-packages.sh as root..." + # Set variable for the provided file apt_file="$1" echo " Using packages file: ${apt_file}" @@ -19,15 +29,6 @@ if [ ! -f "${apt_file}" ]; then exit 1 fi -# Check if the script is run as root -if [[ $(id -u) -ne 0 ]]; then - echo " Error: This script must be run as root. Please use 'USER root' in your Dockerfile before running this script." - echo " Remember to switch back to the non-root user with 'USER ${NB_USER}' after running this script." - exit 1 -fi - -echo " Running install-apt-packages.sh as root. Proceeding with installation..." - # Update package list and handle errors echo " Updating package list..." if ! apt-get update --fix-missing; then From 98566eec95e5fb8ad43cebe56392c742be5864c1 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:15:13 -0800 Subject: [PATCH 16/19] Update install-pip-packages.sh --- scripts/install-pip-packages.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/install-pip-packages.sh b/scripts/install-pip-packages.sh index e83e6d0..406da46 100644 --- a/scripts/install-pip-packages.sh +++ b/scripts/install-pip-packages.sh @@ -1,6 +1,13 @@ #!/bin/bash # Required User: NB_USER +# 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 " >&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" @@ -10,12 +17,6 @@ fi # Main script execution as NB_USER echo "Running install-pip-packages.sh as ${NB_USER}" -# Check if a filename argument is provided -if [ -z "$1" ]; then - echo " Error: This script requires a requirements.txt file." >&2 - echo " Usage: RUN /pyrocket_scripts/install-pip-packages.sh " >&2 - exit 1 -fi # Set variable for the provided file requirements_file="$1" From e5d90ee50e5b63e21ef7a26a96b49824c8e770c7 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:17:16 -0800 Subject: [PATCH 17/19] Update install-r-packages.sh --- scripts/install-r-packages.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/install-r-packages.sh b/scripts/install-r-packages.sh index 197982a..f02de4b 100644 --- a/scripts/install-r-packages.sh +++ b/scripts/install-r-packages.sh @@ -1,6 +1,13 @@ #!/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 " >&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" @@ -8,14 +15,7 @@ if [[ $(id -u) -eq 0 ]]; then fi # Main script execution as NB_USER -echo "Running install-r-packages.sh" - -# Check if a filename argument is provided -if [ -z "$1" ]; then - echo " Error: This script requires a file name (install.R)." >&2 - echo " Usage: RUN /pyrocket_scripts/install-r-packages.sh " >&2 - exit 1 -fi +echo "Running install-r-packages.sh as ${NB_USER}" # Set the file variable to the provided argument INSTALL_FILE="$1" @@ -23,7 +23,7 @@ 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 " >&2 + echo " Usage: RUN /pyrocket_scripts/install-r-packages.sh " >&2 exit 1 fi From cc5af1cccfba03e075c79bcecddfc221bf674803 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:20:31 -0800 Subject: [PATCH 18/19] Update setup-start.sh --- scripts/setup-start.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/setup-start.sh b/scripts/setup-start.sh index 9badd2e..15d1ec5 100644 --- a/scripts/setup-start.sh +++ b/scripts/setup-start.sh @@ -1,6 +1,11 @@ #!/bin/bash # Required User: NB_USER +# Check if a filename argument is provided +if [ -n "$1" ]; then + echo "Warning: Passed-in file '$1' to setup-start.sh is ignored. Looking for a file named 'start' in your repository." >&2 +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 start.sh" @@ -9,11 +14,6 @@ fi echo "Running setup-start.sh as ${NB_USER}" -# Check if a filename argument is provided -if [ -n "$1" ]; then - echo " Warning: Passed-in file '$1' is ignored. Looking for a file named 'start' in your repository." >&2 -fi - echo " Checking for ${REPO_DIR}/childimage/..." if [ -d "${REPO_DIR}/childimage/" ]; then cd "${REPO_DIR}/childimage/" || exit 1 From bd6be091ac1536c92a34f6dd449101d8d886bcb0 Mon Sep 17 00:00:00 2001 From: Eli Holmes - NOAA Date: Tue, 5 Nov 2024 08:22:53 -0800 Subject: [PATCH 19/19] Update run-postbuild.sh --- scripts/run-postbuild.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/run-postbuild.sh b/scripts/run-postbuild.sh index b93fcaf..dbd63f2 100644 --- a/scripts/run-postbuild.sh +++ b/scripts/run-postbuild.sh @@ -2,6 +2,11 @@ echo "Running run-postbuild.sh" +# Check if a filename argument is provided +if [ -n "$1" ]; then + echo " Warning: Passed-in file '$1' to run-postbuild.sh is ignored. Looking for a file named 'postBuild' in your repository." >&2 +fi + echo " Checking for ${REPO_DIR}/childimage/..." if [ -d "${REPO_DIR}/childimage/" ]; then cd "${REPO_DIR}/childimage/" || exit 1