Upgrade script installs venv in wrong directory if pwd-returned directory contains spaces #9902

Closed
opened 2025-12-29 21:24:11 +01:00 by adam · 4 comments
Owner

Originally created by @prryplatypus on GitHub (Jun 25, 2024).

Originally assigned to: @prryplatypus on GitHub.

Deployment Type

Self-hosted

NetBox Version

v2.9.1

Python Version

3.11

Steps to Reproduce

  1. Clone netbox into a directory with spaces (e.g.: ~/Documents/Some Folder/Repos/netbox)
  2. Follow the installation instructions

Expected Behavior

The upgrade.sh script creates the venv in ~/Documents/Some Folder/Repos/netbox/venv and completes successfully.

Observed Behavior

The upgrade.sh script creates the venv in ~/Documents/Some and the script fails.

Originally created by @prryplatypus on GitHub (Jun 25, 2024). Originally assigned to: @prryplatypus on GitHub. ### Deployment Type Self-hosted ### NetBox Version v2.9.1 ### Python Version 3.11 ### Steps to Reproduce 1. Clone netbox into a directory with spaces (e.g.: `~/Documents/Some Folder/Repos/netbox`) 2. Follow the installation instructions ### Expected Behavior The `upgrade.sh` script creates the venv in `~/Documents/Some Folder/Repos/netbox/venv` and completes successfully. ### Observed Behavior The `upgrade.sh` script creates the venv in `~/Documents/Some` and the script fails.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:24:11 +01:00
adam closed this issue 2025-12-29 21:24:12 +01:00
Author
Owner

@prryplatypus commented on GitHub (Jun 25, 2024):

Small snippet that might be useful for escaping spaces: printf "%q/venv\n" "$(pwd -P)"

@prryplatypus commented on GitHub (Jun 25, 2024): Small snippet that might be useful for escaping spaces: `printf "%q/venv\n" "$(pwd -P)"`
Author
Owner

@RangerRick commented on GitHub (Jun 25, 2024):

it's actually being called in an eval so it needs double-quoting... should be able to quote anywhere eval is called, and then also quote any arguments inside that are dynamic, eg, replace:

# Create a new virtual environment
COMMAND="${PYTHON} -m venv ${VIRTUALENV}"
echo "Creating a new virtual environment at ${VIRTUALENV}..."
eval $COMMAND || {

...with:

# Create a new virtual environment
COMMAND="${PYTHON} -m venv \"${VIRTUALENV}\""
echo "Creating a new virtual environment at ${VIRTUALENV}..."
eval "$COMMAND" || {

Might be worth adding shellcheck to the CI/CD pipeline to catch stuff like this.

@RangerRick commented on GitHub (Jun 25, 2024): it's actually being called in an `eval` so it needs double-quoting... should be able to quote anywhere `eval` is called, and then also quote any arguments inside that are dynamic, eg, replace: ```bash # Create a new virtual environment COMMAND="${PYTHON} -m venv ${VIRTUALENV}" echo "Creating a new virtual environment at ${VIRTUALENV}..." eval $COMMAND || { ``` ...with: ```bash # Create a new virtual environment COMMAND="${PYTHON} -m venv \"${VIRTUALENV}\"" echo "Creating a new virtual environment at ${VIRTUALENV}..." eval "$COMMAND" || { ``` Might be worth adding `shellcheck` to the CI/CD pipeline to catch stuff like this.
Author
Owner

@prryplatypus commented on GitHub (Jun 26, 2024):

I can open a PR to fix this later today

@prryplatypus commented on GitHub (Jun 26, 2024): I can open a PR to fix this later today
Author
Owner

@jeremystretch commented on GitHub (Jun 26, 2024):

Thanks @prryplatypus, I've assigned this to you.

@jeremystretch commented on GitHub (Jun 26, 2024): Thanks @prryplatypus, I've assigned this to you.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9902