Automate generation and parsing of the secret_key for configuration.py. Remove user prompt to enter it manually.

This commit is contained in:
Oliver Gwyther 2024-04-15 22:35:54 +01:00
parent a9b5a3a0ed
commit ec354fb93e

View File

@ -19,7 +19,7 @@ echo "Checking Python version. Please ensure this meets the minimum requirements
python3 --version python3 --version
# Prompt user to confirm if the currently installed Python version meets the minimum requirements # Prompt user to confirm if the currently installed Python version meets the minimum requirements
read -p "Does the installed Python version meet the minimum requirements? (y/n): " PYTHON_CONFIRM read -p "Does the installed Python version meet the minimum requirements of Python 3.8, 3.9, 3.10 or 3.11.? (y/n): " PYTHON_CONFIRM
if [[ $PYTHON_CONFIRM != "y" ]]; then if [[ $PYTHON_CONFIRM != "y" ]]; then
echo "Please install the required version of Python and rerun this script." echo "Please install the required version of Python and rerun this script."
exit 1 exit 1
@ -61,10 +61,14 @@ sed -i "s/'NAME': '',/'NAME': 'netbox',/g" configuration.py
sed -i "s/'PASSWORD': '',/'PASSWORD': '$PG_PASSWORD',/g" configuration.py sed -i "s/'PASSWORD': '',/'PASSWORD': '$PG_PASSWORD',/g" configuration.py
sed -i "s/'HOST': '',/'HOST': 'localhost',/g" configuration.py sed -i "s/'HOST': '',/'HOST': 'localhost',/g" configuration.py
# Prompt user to enter ALLOWED_HOSTS, REDIS, and SECRET_KEY # Generate secret key and parse it into configuration.py
echo "Generating secret key..."
SECRET_KEY=$(python3 /opt/netbox/generate_secret_key.py)
sed -i "s/SECRET_KEY = ''/SECRET_KEY = '$SECRET_KEY'/g" configuration.py
# Prompt user to enter ALLOWED_HOSTS
echo "Please enter manually input the following inforation..." echo "Please enter manually input the following inforation..."
read -p "Enter ALLOWED_HOSTS (separated by commas): " ALLOWED_HOSTS read -p "Enter ALLOWED_HOSTS (separated by commas): " ALLOWED_HOSTS
read -p "Enter SECRET_KEY: " SECRET_KEY
# Parse user input into configuration.py # Parse user input into configuration.py
echo "Parsing the entered information to configuration.py..." echo "Parsing the entered information to configuration.py..."