From 01844d002275044e5d4132ff46a429d755b23d05 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 6 Jan 2020 16:44:18 +0100 Subject: [PATCH] fix setup script --- setup/letsencrypt.service | 2 +- setup/setup.sh | 68 ++++++++++++++++++++++++++------------- setup/webroot.ini.example | 1 + 3 files changed, 48 insertions(+), 23 deletions(-) mode change 100644 => 100755 setup/setup.sh diff --git a/setup/letsencrypt.service b/setup/letsencrypt.service index f601166fd..28db3b6b0 100644 --- a/setup/letsencrypt.service +++ b/setup/letsencrypt.service @@ -4,5 +4,5 @@ Requires=docker.service [Service] Type=oneshot -ExecStart=/usr/bin/docker run --rm --name certbot_fabmanager -v "/apps/fabmanager/letsencrypt:/etc/letsencrypt" certbot/certbot:latest -c "/etc/letsencrypt/config/webroot.ini" certonly +ExecStart=/usr/bin/docker run --rm --name certbot_fabmanager -v "/apps/fabmanager/letsencrypt/etc:/etc/letsencrypt" certbot/certbot:latest -c "/etc/letsencrypt/config/webroot.ini" certonly ExecStartPost=-/usr/bin/docker restart fabmanager_nginx_1 diff --git a/setup/setup.sh b/setup/setup.sh old mode 100644 new mode 100755 index 63bb3d906..0e522f574 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -4,9 +4,15 @@ DOMAINS=() welcome_message() { - echo "============================================" - echo -e "\e[31m Fab-Manager's setup\e[0m" - echo "============================================" + clear + echo "#======================================================================#" + echo -e "#\e[31m ____ __ ____ _ _ __ __ _ __ ___ ____ ____ \e[0m#" + echo -e "#\e[31m ( __)/ _\ ( _ \ ___ ( \/ ) / _\ ( ( \ / _\ / __)( __)( _ \\ \e[0m#" + echo -e "#\e[31m ) _)/ \ ) _ ((___)/ \/ \/ \/ // \( (_ \ ) _) ) / \e[0m#" + echo -e "#\e[31m (__) \_/\_/(____/ \_)(_/\_/\_/\_)__)\_/\_/ \___/(____)(__\_) \e[0m#" + echo "# #" + echo "#======================================================================#" + printf "\n Welcome to Fab-Manager's setup assistant\n\n\n" echo "Thank you for installing Fab-Manager." printf "This script will guide you through the installation process of Fab-Manager\n\n" echo -e "Please report any \e[1mfeedback or improvement request\e[21m on https://feedback.fab-manager.com/" @@ -27,10 +33,11 @@ system_requirements() else local _groups=("sudo" "docker") for _group in "${_groups[@]}"; do + echo -e "detecting group $_group for current user..." if ! groups | grep "$_group"; then echo "Please add your current user to the $_group group." echo "You can run the following as root: \"usermod -aG $_group $(whoami)\", then logout and login again" - echo "current user is misconfigured, exiting..." && exit 1 + echo -e "\e[91m[ ❌ ] current user is misconfigured, exiting...\e[39m" && exit 1 fi done fi @@ -40,9 +47,10 @@ system_requirements() if ! command -v "$_command" then echo "Please install $_command before running this script." - echo "$_command was not found, exiting..." && exit 1 + echo -e "\e[91m[ ❌ ] $_command was not found, exiting...\e[39m" && exit 1 fi done + printf "\e[92m[ ✔ ] All requirements successfully checked.\e[39m \n\n" } read_email() @@ -58,18 +66,18 @@ read_email() config() { - echo 'We recommand nginx to serve the application over the network (internet). You can use your own solution or let this script install and configure nginx for Fab-Manager.' + echo 'We recommend nginx to serve the application over the network (internet). You can use your own solution or let this script install and configure nginx for Fab-Manager.' read -rp 'Do you want install nginx? (Y/n) ' NGINX "$FABMANAGER_PATH/letsencrypt/config/webroot.ini" + \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/webroot.ini.example > "$FABMANAGER_PATH/letsencrypt/etc/config/webroot.ini" # temp systemd files \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/letsencrypt.service > "$FABMANAGER_PATH/letsencrypt/systemd/letsencrypt.service" \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/letsencrypt.timer > "$FABMANAGER_PATH/letsencrypt/systemd/letsencrypt.timer" @@ -147,11 +155,13 @@ function join_by { local IFS="$1"; shift; echo "$*"; } prepare_letsencrypt() { if [ "$LETSENCRYPT" != "n" ]; then - mkdir -p "$FABMANAGER_PATH/config/nginx/ssl" - echo "Now, we will generate a Diffie-Hellman (DH) 4096 bits encryption key, to encrypt connections. This will take a moment, please wait..." - openssl dhparam -out "$FABMANAGER_PATH/config/nginx/ssl/dhparam.pem" 4096 - sed -i.bak "s/REPLACE_WITH_YOUR@EMAIL.COM/$EMAIL/g" "$FABMANAGER_PATH/letsencrypt/config/webroot.ini" - sed -i.bak "s/MAIN_DOMAIN, ANOTHER_DOMAIN_1/$(join_by , "${DOMAINS[@]}")/g" "$FABMANAGER_PATH/letsencrypt/config/webroot.ini" + if ! openssl dhparam -in "$FABMANAGER_PATH/config/nginx/ssl/dhparam.pem"; then + mkdir -p "$FABMANAGER_PATH/config/nginx/ssl" + printf "\n\nNow, we will generate a Diffie-Hellman (DH) 4096 bits encryption key, to encrypt connections. This will take a moment, please wait...\n" + openssl dhparam -out "$FABMANAGER_PATH/config/nginx/ssl/dhparam.pem" 4096 + fi + sed -i.bak "s/REPLACE_WITH_YOUR@EMAIL.COM/$EMAIL/g" "$FABMANAGER_PATH/letsencrypt/etc/config/webroot.ini" + sed -i.bak "s/MAIN_DOMAIN, ANOTHER_DOMAIN_1/$(join_by , "${DOMAINS[@]}")/g" "$FABMANAGER_PATH/letsencrypt/etc/config/webroot.ini" echo "Now downloading and configuring the certificate signing bot..." docker pull certbot/certbot:latest sed -i.bak "s:/apps/fabmanager:$FABMANAGER_PATH:g" "$FABMANAGER_PATH/letsencrypt/systemd/letsencrypt.service" @@ -163,6 +173,17 @@ prepare_letsencrypt() prepare_docker() { + if [ "$(docker ps | wc -l)" -gt 1 ]; then + printf "\n\nIf you have previously interrupted the installer, it is recommended to stop any existing docker container before continuing.\n" + echo "Here's a list of all existing containers:" + docker ps -a + read -rp "Force remove all containers? (y/N) " confirm