From 41fed2388bba7282efe11a2a54dfa55fd62cd99c Mon Sep 17 00:00:00 2001 From: AnonymousWP <50231698+AnonymousWP@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:12:33 +0100 Subject: [PATCH] feat: add non-interactive installation parameter --- .env | 7 +++++++ Makefile | 5 +++++ README.md | 31 ++++++++++++++++++++++------ docker-compose.yml | 1 + install.sh | 50 ++++++++++++++++++++++++++++++++++++---------- 5 files changed, 77 insertions(+), 17 deletions(-) diff --git a/.env b/.env index fca522eee..f5d282d0c 100644 --- a/.env +++ b/.env @@ -28,3 +28,10 @@ POSTGRES_HOST=db # MAX_CONCURRENCY=80 MIN_CONCURRENCY=10 + +# +# Rengine web interface super user (for non-interactive install) +# +DJANGO_SUPERUSER_USERNAME=rengine +DJANGO_SUPERUSER_EMAIL=rengine@example.com +DJANGO_SUPERUSER_PASSWORD=Sm7IJG.IfHAFw9snSKv diff --git a/Makefile b/Makefile index f1b8d1d1d..fc2d9cae7 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +include .env .DEFAULT_GOAL:=help # Credits: https://github.com/sherifabdlnaby/elastdocker/ @@ -25,7 +26,11 @@ build: ## Build all services. ${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} build ${SERVICES} username: ## Generate Username (Use only after make up). +ifeq ($(isNonInteractive), true) + ${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} exec web python3 manage.py createsuperuser --username ${DJANGO_SUPERUSER_USERNAME} --email ${DJANGO_SUPERUSER_EMAIL} --noinput +else ${COMPOSE_PREFIX_CMD} docker-compose ${COMPOSE_ALL_FILES} exec web python3 manage.py createsuperuser +endif pull: ## Pull Docker images. docker login docker.pkg.github.com diff --git a/README.md b/README.md index c0af47891..7586902bb 100644 --- a/README.md +++ b/README.md @@ -319,12 +319,27 @@ screenshot: { git clone https://github.com/yogeshojha/rengine && cd rengine ``` -1. Edit the dotenv file, **please make sure to change the password for postgresql `POSTGRES_PASSWORD`!** +1. Edit the `.env` file, **please make sure to change the password for postgresql `POSTGRES_PASSWORD`!** ```bash nano .env ``` +1. **Optional, only for non-interactive install**: In the `.env` file, **please make sure to change the super admin values!** + + ```bash + DJANGO_SUPERUSER_USERNAME=yourUsername + DJANGO_SUPERUSER_EMAIL=YourMail@example.com + DJANGO_SUPERUSER_PASSWORD=yourStrongPassword + ``` + If you need to carry out a non-interactive installation, you can setup the login, email and password of the web interface admin directly from the .env file (instead of manually setting them from prompts during the installation process). This option can be interesting for automated installation (via ansible, vagrant, etc.). + + `DJANGO_SUPERUSER_USERNAME`: web interface admin username (used to login to the web interface). + + `DJANGO_SUPERUSER_EMAIL`: web interface admin email. + + `DJANGO_SUPERUSER_PASSWORD`: web interface admin password (used to login to the web interface). + 1. In the dotenv file, you may also modify the Scaling Configurations ```bash @@ -332,9 +347,9 @@ screenshot: { MIN_CONCURRENCY=10 ``` - MAX_CONCURRENCY: This parameter specifies the maximum number of reNgine's concurrent Celery worker processes that can be spawned. In this case, it's set to 80, meaning that the application can utilize up to 80 concurrent worker processes to execute tasks concurrently. This is useful for handling a high volume of scans or when you want to scale up processing power during periods of high demand. If you have more CPU cores, you will need to increase this for maximised performance. + `MAX_CONCURRENCY`: This parameter specifies the maximum number of reNgine's concurrent Celery worker processes that can be spawned. In this case, it's set to 80, meaning that the application can utilize up to 80 concurrent worker processes to execute tasks concurrently. This is useful for handling a high volume of scans or when you want to scale up processing power during periods of high demand. If you have more CPU cores, you will need to increase this for maximised performance. - MIN_CONCURRENCY: On the other hand, MIN_CONCURRENCY specifies the minimum number of concurrent worker processes that should be maintained, even during periods of lower demand. In this example, it's set to 10, which means that even when there are fewer tasks to process, at least 10 worker processes will be kept running. This helps ensure that the application can respond promptly to incoming tasks without the overhead of repeatedly starting and stopping worker processes. + `MIN_CONCURRENCY`: On the other hand, MIN_CONCURRENCY specifies the minimum number of concurrent worker processes that should be maintained, even during periods of lower demand. In this example, it's set to 10, which means that even when there are fewer tasks to process, at least 10 worker processes will be kept running. This helps ensure that the application can respond promptly to incoming tasks without the overhead of repeatedly starting and stopping worker processes. These settings allow for dynamic scaling of Celery workers, ensuring that the application efficiently manages its workload by adjusting the number of concurrent workers based on the workload's size and complexity @@ -344,6 +359,12 @@ screenshot: { sudo ./install.sh ``` + Or for a non-interactive installation, use `-n` argument (make sure you've modified the `.env` file before launching the installation). + + ```bash + sudo ./install.sh -n + ``` + If `install.sh` does not have install permission, please change it, `chmod +x install.sh` **reNgine can now be accessed from or if you're on the VPS ** @@ -359,12 +380,10 @@ Installation instructions can be found at [https://reNgine.wiki/install/detailed 1. Updating is as simple as running the following command: ```bash - cd rengine && sudo ./update.sh + cd rengine && sudo ./update.sh ``` If `update.sh` does not have execution permissions, please change it, `sudo chmod +x update.sh` - - **NOTE:** if you're updating from 1.3.6 and you're getting a 'password authentication failed' error, consider uninstalling 1.3.6 first, then install 2.x.x as you'd normally do. ### Changelog diff --git a/docker-compose.yml b/docker-compose.yml index e74825b92..657153f77 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -94,6 +94,7 @@ services: - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - POSTGRES_PORT=${POSTGRES_PORT} - POSTGRES_HOST=${POSTGRES_HOST} + - DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD} # THIS IS A MUST FOR CHECKING UPDATE, EVERYTIME A COMMIT IS MERGED INTO # MASTER, UPDATE THIS!!! MAJOR.MINOR.PATCH https://semver.org/ - RENGINE_CURRENT_VERSION='2.0.1' diff --git a/install.sh b/install.sh index bf745da91..1c9935e4e 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,15 @@ #!/bin/bash +usageFunction() +{ + echo " " + tput setaf 2; + echo "Usage: $0 (-n) (-h)" + echo -e "\t-n Non-interactive installation (Optional)" + echo -e "\t-h Show usage" + exit 1 +} + tput setaf 2; cat web/art/reNgine.txt @@ -7,15 +17,29 @@ tput setaf 1; echo "Before running this script, please make sure Docker is runni tput setaf 2; echo "Changing the postgres username & password from .env is highly recommended." tput setaf 4; -read -p "Are you sure, you made changes to .env file (y/n)? " answer -case ${answer:0:1} in - y|Y|yes|YES|Yes ) - echo "Continiuing Installation!" - ;; - * ) - nano .env - ;; -esac + +isNonInteractive=false +while getopts nh opt; do + case $opt in + n) isNonInteractive=true ;; + h) usageFunction ;; + ?) usageFunction ;; + esac +done + +if [ $isNonInteractive = false ]; then + read -p "Are you sure, you made changes to .env file (y/n)? " answer + case ${answer:0:1} in + y|Y|yes|YES|Yes ) + echo "Continiuing Installation!" + ;; + * ) + nano .env + ;; + esac +else + echo "Non-interactive installation parameter set. Installation begins." +fi echo " " tput setaf 3; @@ -60,6 +84,7 @@ else tput setaf 2; echo "Docker installed!!!" fi + echo " " tput setaf 4; echo "#########################################################################" @@ -68,12 +93,13 @@ echo "#########################################################################" if [ -x "$(command -v docker-compose)" ]; then tput setaf 2; echo "docker-compose already installed, skipping." else - curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + curl -L "https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose tput setaf 2; echo "docker-compose installed!!!" fi + echo " " tput setaf 4; echo "#########################################################################" @@ -100,6 +126,8 @@ else exit 1 fi + + echo " " tput setaf 4; echo "#########################################################################" @@ -115,7 +143,7 @@ if [ "${failed}" -eq 0 ]; then echo "#########################################################################" echo "Creating an account" echo "#########################################################################" - make username + make username isNonInteractive=$isNonInteractive tput setaf 2 && printf "\n%s\n" "Thank you for installing reNgine, happy recon!!" else