Skip to content

Commit

Permalink
Merge pull request #95 from Security-Tools-Alliance/replace-names/url…
Browse files Browse the repository at this point in the history
…s-to-fork

build(install/uninstall/update): improve usability, readability and overall user experience of output
  • Loading branch information
psyray committed Jun 28, 2024
2 parents 058da0f + c5e305e commit 55c9179
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 144 deletions.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ services:
context: ./web
restart: always
entrypoint: /usr/src/app/celery-entrypoint.sh
# command: celery -A reNgine worker --autoscale=${MAX_CONCURRENCY},${MIN_CONCURRENCY} -l INFO
volumes:
- ./web:/usr/src/app
- github_repos:/usr/src/github
Expand Down Expand Up @@ -169,7 +168,6 @@ services:
networks:
- rengine_network


networks:
rengine_network:

Expand Down
168 changes: 101 additions & 67 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,120 +1,154 @@
#!/bin/bash

#log messages in different colors
# Define color codes.
# Using `tput setaf` at some places because the variable only works with log/echo

COLOR_BLACK=0
COLOR_RED=1
COLOR_GREEN=2
COLOR_YELLOW=3
COLOR_BLUE=4
COLOR_MAGENTA=5
COLOR_CYAN=6
COLOR_WHITE=7
COLOR_DEFAULT=$COLOR_WHITE # Use white as default for clarity

# Fetch the internal and external IP address so that it can be printed later when the script has finished installing reNgine-ng
external_ip=$(curl -s https://ipecho.net/plain)
internal_ips=$(ip -4 -br addr | awk '$2 == "UP" {print $3} /^lo/ {print $3}' | cut -d'/' -f1)
formatted_ips=""
for ip in $internal_ips; do
formatted_ips="${formatted_ips}https://$ip\n"
done

# Log messages in different colors
log() {
tput setaf "$2"
local color=${2:-$COLOR_DEFAULT} # Use default color if $2 is not set
if [ "$color" -ne $COLOR_DEFAULT ]; then
tput setaf "$color"
fi
printf "$1\r\n"
tput sgr0 # Reset text color
}

# Check for root privileges
if [ "$(id -u)" -ne 0 ]; then
log "Error: Please run this script as root!" 1
log "Example: sudo $0" 1
exit 1
if [ "$(whoami)" != "root" ]
then
log ""
log "Error installing reNgine-ng: please run this script as root!" $COLOR_RED
log "Example: sudo ./install.sh" $COLOR_RED
exit
fi

tput setaf 2;
cat web/art/reNgine.txt

log "\r\nBefore running this script, please make sure Docker is running and you have made changes to the '.env' file." 1
log "Changing the postgres username & password from .env is highly recommended.\r\n" 1
log "\r\nBefore running this script, please make sure Docker is running and you have made changes to the '.env' file." $COLOR_RED
log "Changing the PostgreSQL username & password in the '.env' is highly recommended.\r\n" $COLOR_RED

log "#########################################################################" 4
log "Please note that this installation script is only intended for Linux" 3
log "Only x86_64 platform are supported" 3
log "#########################################################################\r\n" 4
log "Please note that this installation script is only intended for Linux" $COLOR_RED
log "Only x86_64 platform are supported" $COLOR_RED

log ""
tput setaf 1;
read -p "Are you sure you made changes to the '.env' file (y/n)? " answer
case ${answer:0:1} in
y|Y|yes|YES|Yes )
log "Continuing Installation!" 2
log "\nContinuing installation!\n" $COLOR_GREEN
;;
* )
if [ -x "$(command -v nano)" ]; then
log "nano already installed, skipping." 2
if ! command -v nano &> /dev/null; then
. /etc/os-release
case "$ID" in
ubuntu|debian) sudo apt update && sudo apt install -y nano ;;
fedora) sudo dnf install -y nano ;;
centos|rhel) sudo yum install -y nano ;;
arch) sudo pacman -Sy nano ;;
opensuse|suse) sudo zypper install -y nano ;;
*) log "Unsupported Linux distribution. Please install nano manually." $COLOR_RED; exit 1 ;;
esac
[ $? -eq 0 ] && log "nano installed!" $COLOR_GREEN || { log "Failed to install nano." $COLOR_RED; exit 1; }
else
sudo apt update && sudo apt install nano -y
log "nano installed!!!" 2
log "nano already installed, skipping." $COLOR_GREEN
fi
nano .env
;;
esac

log "\r\nInstalling reNgine and its dependencies" 4
log "=========================================================================" 4

log "\r\n#########################################################################" 4
log "Installing curl..." 4

if ! command -v curl 2> /dev/null; then
apt update && apt install curl -y
log "CURL installed!!!" 2
log "Installing reNgine-ng and its dependencies..." $COLOR_CYAN

log "Installing curl..." $COLOR_CYAN

if ! command -v curl &> /dev/null; then
. /etc/os-release
case "$ID" in
ubuntu|debian) sudo apt update && sudo apt install -y curl ;;
fedora) sudo dnf install -y curl ;;
centos|rhel) sudo yum install -y curl ;;
arch) sudo pacman -Sy curl ;;
opensuse|suse) sudo zypper install -y curl ;;
*) log "Unsupported Linux distribution. Please install curl manually." $COLOR_RED; exit 1 ;;
esac
[ $? -eq 0 ] && log "CURL installed!" $COLOR_GREEN || { log "Failed to install CURL." $COLOR_RED; exit 1; }
else
log "CURL already installed, skipping." 2
log "CURL already installed, skipping." $COLOR_GREEN
fi


log "\r\n#########################################################################" 4
log "Installing Docker..." 4

log "Installing Docker..." $COLOR_CYAN
if ! command -v docker 2> /dev/null; then
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
log "Docker installed!!!" 2
log "Docker installed!" $COLOR_GREEN
else
log "Docker already installed, skipping." 2
log "Docker already installed, skipping." $COLOR_GREEN
fi

log "\r\n#########################################################################" 4
log "Installing Docker Compose" 4

log "Installing Docker Compose..." $COLOR_CYAN
if ! command -v docker compose 2> /dev/null; then
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/latest/download/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
log "Docker Compose installed!!!" 2
log "Docker Compose installed!" $COLOR_GREEN
else
log "Docker Compose already installed, skipping." 2
log "Docker Compose already installed, skipping." $COLOR_GREEN
fi

log "\r\n#########################################################################" 4
log "Installing make" 4

if ! command -v make 2> /dev/null; then
apt install make -y
log "make installed!!!" 2
if ! command -v make &> /dev/null; then
. /etc/os-release
case "$ID" in
ubuntu|debian) sudo apt update && sudo apt install -y make ;;
fedora) sudo dnf install -y make ;;
centos|rhel) sudo yum install -y make ;;
arch) sudo pacman -Sy make ;;
opensuse|suse) sudo zypper install -y make ;;
*) log "Unsupported Linux distribution. Please install make manually." $COLOR_RED; exit 1 ;;
esac
[ $? -eq 0 ] && log "make installed!" $COLOR_GREEN || { log "Failed to install make." $COLOR_RED; exit 1; }
else
log "make already installed, skipping." 2
log "make already installed, skipping." $COLOR_GREEN
fi

log "\r\n#########################################################################" 4
log "Checking Docker status" 4
log "Checking Docker status..." $COLOR_CYAN
if docker info >/dev/null 2>&1; then
log "Docker is running." 2
log "Docker is running." $COLOR_GREEN
else
log "Docker is not running. Please run docker and try again." 1
log "You can run Docker service using: sudo systemctl start docker" 1
log "Docker is not running. Please run Docker and try again." $COLOR_RED
log "You can run Docker service using: sudo systemctl start docker" $COLOR_RED
exit 1
fi

log "\r\n#########################################################################" 4
log "Installing reNgine, please be patient it could take a while" 4
log "Installing reNgine-ng, please be patient as it could take a while..." $COLOR_CYAN
sleep 5

log "\r\n=========================================================================" 5
log "Generating certificates and building docker images" 5
log "=========================================================================" 5
make certs && make build && log "reNgine is built" 2 || { log "reNgine installation failed!!" 1; exit 1; }
log "Generating certificates and building Docker images..." $COLOR_CYAN
make certs && make build && log "reNgine-ng is built" $COLOR_GREEN || { log "reNgine-ng installation failed!" $COLOR_RED; exit 1; }

log "\r\n=========================================================================" 5
log "Docker containers starting, please wait celery container could be long" 5
log "=========================================================================" 5
make up && log "reNgine is installed!!!" 2 || { log "reNgine installation failed!!" 1; exit 1; }
log "Docker containers starting, please wait as Celery container could take a while..." $COLOR_CYAN
sleep 5
make up && log "reNgine-ng is installed!" $COLOR_GREEN || { log "reNgine-ng installation failed!" $COLOR_RED; exit 1; }


log "\r\n#########################################################################" 4
log "Creating an account" 4
log "#########################################################################" 4
log "Creating an account..." $COLOR_CYAN
make username

log "\r\nThank you for installing reNgine, happy recon!!" 2
log "\r\nThank you for installing reNgine-ng, happy recon!" $COLOR_GREEN

log "\r\nIn case you're running this locally, reNgine-ng should be available at one of the following IPs:\n$formatted_ips" $COLOR_GREEN
log "In case you're running this on a server, reNgine-ng should be available at: https://$external_ip/" $COLOR_GREEN
6 changes: 3 additions & 3 deletions make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if "%1" == "build" docker compose %COMPOSE_ALL_FILES% build %SERVICES%
:: Generate Username (Use only after make up).
if "%1" == "username" docker compose %COMPOSE_ALL_FILES% exec web python3 manage.py createsuperuser
:: Pull Docker images.
if "%1" == "pull" docker login docker.pkg.github.com & docker-compose %COMPOSE_ALL_FILES% pull
if "%1" == "pull" docker login docker.pkg.github.com & docker compose %COMPOSE_ALL_FILES% pull
:: Down all services.
if "%1" == "down" docker compose %COMPOSE_ALL_FILES% down
:: Stop all services.
Expand All @@ -30,6 +30,6 @@ if "%1" == "logs" docker compose %COMPOSE_ALL_FILES% logs --follow --tail=1000 %
:: Show all Docker images.
if "%1" == "images" docker compose %COMPOSE_ALL_FILES% images %SERVICES%
:: Remove containers and delete volume data.
if "%1" == "prune" docker compose %COMPOSE_ALL_FILES% stop %SERVICES% & docker-compose %COMPOSE_ALL_FILES% rm -f %SERVICES% & docker volume prune -f
if "%1" == "prune" docker compose %COMPOSE_ALL_FILES% stop %SERVICES% & docker compose %COMPOSE_ALL_FILES% rm -f %SERVICES% & docker volume prune -f
:: Show this help.
if "%1" == "help" @echo Make application Docker images and manage containers using Docker Compose files only for windows.
if "%1" == "help" @echo Make application Docker images and manage containers using Docker Compose files only for Windows.
Loading

0 comments on commit 55c9179

Please sign in to comment.