Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include permission validation step to programmatically cloned repos #2258

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ if [ "$#" -lt 1 ] || [ "$1" = "--help" ]; then
[ "$1" = "--help" ] && exit 0 || exit 1
fi

fix_parent_dir_permissions() {
# Fix parent directory permissions to allow the JupyterLab user to access the cloned repository

local folder_path="$1"

# Retrieve the very first parent directory
local parent_dir=$(echo "$folder_path" | cut -d '/' -f1)

# Check if the parent directory has the correct permissions
if [ "$(stat -c "%u:%g" "$parent_dir")" != "1000:100" ]; then
echo "Fixing permissions for parent directory: $parent_dir"
chown -R 1000:100 "$parent_dir" || { echo "Error: Unable to set ownership for $parent_dir"; return 1; }
chmod -R 755 "$parent_dir" || { echo "Error: Unable to set permissions for $parent_dir"; return 1; }
fi
}

clone_update_repository() {
# Clone or update a Git repository into a specified folder,
# and create a `.firstrun` file to mark the script's execution.
Expand All @@ -47,6 +63,8 @@ clone_update_repository() {
mkdir -p "$folder_path"
fi

fix_parent_dir_permissions "$folder_path" || return 1

if [ -d "$folder_path/.git" ]; then
echo -e "Updating Git repository in ${folder_path}..."
(cd "$folder_path" && git pull)
Expand All @@ -55,7 +73,13 @@ clone_update_repository() {
(git clone "$git_repo_url" "$folder_path")
fi

echo -e "Creating .firstrun file in ${folder_path}..."
touch "$firstrun_file"

# User permissions for JupyterLab user to newly created git folders
echo -e "Setting permissions for ${folder_path}..."
chown -R 1000:100 "$folder_path" || { echo "Error: Unable to set ownership for $folder_path"; return 1; }

echo -e "Execution for ${folder_path} completed. ${GREEN}✅${NC}"
fi
}
Expand All @@ -72,7 +96,6 @@ for pair in "$@"; do
echo -e "${RED}Invalid argument format: \"${pair}\". Please provide folder path and Git repository URL in the correct order.${NC}" >> "$ERROR_LOG"
else
clone_update_repository "$folder_path" "$git_repo_url" || echo -e "${RED}Error executing for ${folder_path}.${NC}" >> "$ERROR_LOG"
chown -R 1000:100 "$folder_path" # User permissions for JupyterLab user
fi
done

Expand Down
Loading