upgrade.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # This script will prepare NetBox to run after the code has been upgraded to
  3. # its most recent release.
  4. #
  5. # Once the script completes, remember to restart the WSGI service (e.g.
  6. # gunicorn or uWSGI).
  7. # Optionally use sudo if not already root, and always prompt for password
  8. # before running the command
  9. PREFIX="sudo -k "
  10. if [ "$(whoami)" = "root" ]; then
  11. # When running upgrade as root, ask user to confirm if they wish to
  12. # continue
  13. read -n1 -rsp $'Running NetBox upgrade as root, press any key to continue or ^C to cancel\n'
  14. PREFIX=""
  15. fi
  16. # Delete stale bytecode
  17. COMMAND="${PREFIX}find . -name \"*.pyc\" -delete"
  18. echo "Cleaning up stale Python bytecode ($COMMAND)..."
  19. eval $COMMAND
  20. # Prefer python3/pip3
  21. PYTHON="python3"
  22. type $PYTHON >/dev/null 2>&1 || PYTHON="python"
  23. PIP="pip3"
  24. type $PIP >/dev/null 2>&1 || PIP="pip"
  25. # Install any new Python packages
  26. COMMAND="${PREFIX}${PIP} install -r requirements.txt --upgrade"
  27. echo "Updating required Python packages ($COMMAND)..."
  28. eval $COMMAND
  29. # Apply any database migrations
  30. COMMAND="${PYTHON} netbox/manage.py migrate"
  31. echo "Applying database migrations ($COMMAND)..."
  32. eval $COMMAND
  33. # Collect static files
  34. COMMAND="${PYTHON} netbox/manage.py collectstatic --no-input"
  35. echo "Collecting static files ($COMMAND)..."
  36. eval $COMMAND