upgrade.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. PYTHON="python3"
  8. PIP="pip3"
  9. # Optionally use sudo if not already root, and always prompt for password
  10. # before running the command
  11. PREFIX="sudo -k "
  12. if [ "$(whoami)" = "root" ]; then
  13. # When running upgrade as root, ask user to confirm if they wish to
  14. # continue
  15. read -n1 -rsp $'Running NetBox upgrade as root, press any key to continue or ^C to cancel\n'
  16. PREFIX=""
  17. fi
  18. # Delete stale bytecode
  19. COMMAND="${PREFIX}find . -name \"*.pyc\" -delete"
  20. echo "Cleaning up stale Python bytecode ($COMMAND)..."
  21. eval $COMMAND
  22. # Uninstall any Python packages which are no longer needed
  23. COMMAND="${PREFIX}${PIP} uninstall -r old_requirements.txt -y"
  24. echo "Removing old Python packages ($COMMAND)..."
  25. eval $COMMAND
  26. # Install any new Python packages
  27. COMMAND="${PREFIX}${PIP} install -r requirements.txt --upgrade"
  28. echo "Updating required Python packages ($COMMAND)..."
  29. eval $COMMAND
  30. # Apply any database migrations
  31. COMMAND="${PYTHON} netbox/manage.py migrate"
  32. echo "Applying database migrations ($COMMAND)..."
  33. eval $COMMAND
  34. # Collect static files
  35. COMMAND="${PYTHON} netbox/manage.py collectstatic --no-input"
  36. echo "Collecting static files ($COMMAND)..."
  37. eval $COMMAND