upgrade.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. # Fall back to pip3 if pip is missing
  21. PIP="pip"
  22. type $PIP >/dev/null 2>&1 || PIP="pip3"
  23. # Install any new Python packages
  24. COMMAND="${PREFIX}${PIP} install -r requirements.txt --upgrade"
  25. echo "Updating required Python packages ($COMMAND)..."
  26. eval $COMMAND
  27. # Apply any database migrations
  28. COMMAND="./netbox/manage.py migrate"
  29. echo "Updating required Python packages ($COMMAND)..."
  30. eval $COMMAND
  31. # Collect static files
  32. COMMAND="./netbox/manage.py collectstatic --no-input"
  33. echo "Collecting static files ($COMMAND)..."
  34. eval $COMMAND