Skip to content

Commit 49f06cf

Browse files
committed
Optionally use sudo if not running upgrade.sh as root
1 parent 1bb2a3f commit 49f06cf

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

upgrade.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# This script will prepare NetBox to run after the code has been upgraded to
33
# its most recent release.
44
#
55
# Once the script completes, remember to restart the WSGI service (e.g.
66
# gunicorn or uWSGI).
77

8+
# Optionally use sudo if not already root, and always prompt for password
9+
# before running the command
10+
PREFIX="sudo -k "
11+
if [ "$(whoami)" = "root" ]; then
12+
# When running upgrade as root, ask user to confirm if they wish to
13+
# continue
14+
read -n1 -rsp $'Running NetBox upgrade as root, press any key to continue or ^C to cancel\n'
15+
PREFIX=""
16+
fi
17+
818
# Install any new Python packages
9-
echo "Updating required Python packages (pip install -r requirements.txt --upgrade)..."
10-
sudo pip install -r requirements.txt --upgrade
19+
COMMAND="${PREFIX}pip install -r requirements.txt --upgrade"
20+
echo "Updating required Python packages ($COMMAND)..."
21+
eval $COMMAND
1122

1223
# Apply any database migrations
1324
./netbox/manage.py migrate

0 commit comments

Comments
 (0)