Skip to content

Commit

Permalink
Merge pull request #199 from nmfs-opensci/eeholmes-patch-2
Browse files Browse the repository at this point in the history
fix home/jovyan permissions
  • Loading branch information
eeholmes authored Nov 19, 2024
2 parents cd4dc51 + 05eb71e commit 7a0da80
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ RUN mkdir -p ${XDG_CONFIG_HOME} && \
chmod +x ${REPO_DIR}/scripts/setup-desktop.sh && \
${REPO_DIR}/scripts/setup-desktop.sh

# Fix home permissions. Not needed in JupyterHub with persistent memory but needed if not used in that context
RUN /pyrocket_scripts/fix-home-permissions.sh

# Set up the start command
USER ${NB_USER}
RUN chmod +x ${REPO_DIR}/start \
Expand Down
25 changes: 25 additions & 0 deletions scripts/fix-home-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
# Required User: root

echo "Running fix-home-permissions.sh"

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

# Define the target directory
TARGET_DIR="/home/${NB_USER}"

# Change ownership only for items not owned by ${NB_USER}
sudo find "${TARGET_DIR}" ! -user "${NB_USER}" -exec chown "${NB_USER}:${NB_USER}" {} \;

# Set permissions on all directories: read, write, and execute for ${NB_USER}
sudo find "${TARGET_DIR}" -type d -exec chmod 755 {} \;

# Set permissions on all files: read and write for ${NB_USER}
sudo find "${TARGET_DIR}" -type f -exec chmod 644 {} \;
2 changes: 1 addition & 1 deletion scripts/install-vscode-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fi
# Set the extensions directory to be the conda dir so that it persists
# Create if it doesn't exist; make owner jovyan
EXT_DIR="${NB_PYTHON_PREFIX}/share/code-server/extensions"
install -o jovyan -g jovyan -m 755 -d "${EXT_DIR}"
install -o ${NB_USER} -g ${NB_USER} -m 755 -d "${EXT_DIR}"

# Install each extension listed in the file; skip empty lines or comments
while IFS= read -r EXT; do
Expand Down

0 comments on commit 7a0da80

Please sign in to comment.