Skip to content

Commit

Permalink
Merge pull request #195 from nmfs-opensci/eeholmes-patch-1
Browse files Browse the repository at this point in the history
export PATH in scripts that switch to NB_USER
  • Loading branch information
eeholmes authored Nov 19, 2024
2 parents 7a0da80 + 815ff5e commit 7d7b285
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions scripts/install-conda-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ENV_NAME="${2:-${CONDA_ENV}}"
# 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"
# Be aware that the next line is resetting PATH to not include conda bins. If this becomes a problem, uncomment the following
# export PATH="$PATH"
exec su "${NB_USER}" -c "/bin/bash $0 $ENV_FILE $ENV_NAME"
fi

Expand Down
16 changes: 8 additions & 8 deletions scripts/install-desktop.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/bin/bash
# Required User: root
# Usage: RUN /pyrocket_scripts/setup-desktop.sh <directory path>"
# Usage: RUN /pyrocket_scripts/install-desktop.sh <directory path>"

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 " Error: This install-desktop.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

# Check if a directory argument is provided
if [ -z "$1" ]; then
echo " Error: No directory provided. Please provide a directory path where the script can find .desktop, .png, and .xml files."
echo " Usage: RUN /pyrocket_scripts/setup-desktop.sh <directory path>"
echo " Usage: RUN /pyrocket_scripts/install-desktop.sh <directory path>"
exit 1
fi

Expand All @@ -40,17 +40,17 @@ find "${TARGET_DIR}" -type f \( -name "*.desktop" -o -name "*.png" -o -name "*.x
if [ "$(ls -A "${REPO_DIR}/Desktop" 2>/dev/null)" ]; then
echo " Successfully copied Desktop-related files to '${REPO_DIR}/Desktop'."
else
echo " Warning: No .desktop, .png, or .xml files found in '${TARGET_DIR}'. Nothing was copied."
echo " Warning: No .desktop, .png, or .xml files found in '${TARGET_DIR}'. Skipping installation."
exit 0 # Exit without error if no files were found
fi

# Check if desktop.sh exists before executing
if [ -f "${REPO_DIR}/scripts/setup-desktop.sh" ]; then
echo " Running ${REPO_DIR}/scripts/setup-desktop.sh to move Desktop files to appropriate directories and register as applications."
chmod +x "${REPO_DIR}/scripts/setup-desktop.sh"
"${REPO_DIR}/scripts/setup-desktop.sh"
echo " Success! install-desktop.sh Desktop files installed."
else
echo " Warning: ${REPO_DIR}/scripts/setup-desktop.sh not found. Skipping execution."
echo " Error: ${REPO_DIR}/scripts/setup-desktop.sh not found. This script is required for Desktop application installation."
exit 1
fi

echo " Success! install-desktop.sh"

2 changes: 2 additions & 0 deletions scripts/install-pip-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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"
# Be aware that the next line is resetting PATH to not include conda bins. If this becomes a problem, uncomment the following
# export PATH="$PATH"
exec su "${NB_USER}" -c "/bin/bash $0 $1" # Pass along the filename argument
fi

Expand Down
8 changes: 8 additions & 0 deletions scripts/setup-desktop.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#!/bin/bash
# Required user: root
# The default for XDG and xfce4 is for Desktop files to be in ~/Desktop but this leads to a variety of problems
# First we are altering the user directiory which seems rude, second orphan desktop files might be in ~/Desktop so who knows
# what the user Desktop experience with be, here the Desktop dir is set to /usr/share/Desktop so is part of the image.
# users that want to customize Desktop can change /etc/xdg/user-dirs.dirs though py-rocket resets that each time the server is restarted.
set -e

# Check if the script is run as root
if [[ $(id -u) -ne 0 ]]; then
echo " Error: This setup-desktop.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

# Copy in the Desktop files
APPLICATIONS_DIR=/usr/share/applications/packages
DESKTOP_DIR=/usr/share/Desktop
Expand Down
2 changes: 2 additions & 0 deletions scripts/setup-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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 setup-start.sh"
# Be aware that the next line is resetting PATH to not include conda bins. If this becomes a problem, uncomment the following
# export PATH="$PATH"
exec su "${NB_USER}" -c "/bin/bash $0 $1" # Pass the script file as an argument
fi

Expand Down

0 comments on commit 7d7b285

Please sign in to comment.