#!/bin/bash DOMAINS=() welcome_message() { 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/" echo -e "For \e[1mbug reports\e[21m, please open a new issue on https://github.com/sleede/fab-manager/issues" echo -e "You can call for \e[1mcommunity assistance\e[21m on https://forum.fab-manager.com/" printf "\nYou can interrupt this installation at any time by pressing Ctrl+C\n" printf "If you do not feel confortable with this installation, you can \e[4msubscribe to our hosting offers\e[24m:\nhttps://www.fab-manager.com/saas-offer\n\n" read -rp "Continue? (Y/n) " confirm &1) if [ $? -eq 0 ]; then echo "has_sudo__pass_set" elif echo $prompt | grep -q '^sudo:'; then echo "has_sudo__needs_pass" else echo "no_sudo" fi } elevate_cmd() { local cmd=$@ HAS_SUDO=$(has_sudo) case "$HAS_SUDO" in has_sudo__pass_set) sudo $cmd ;; has_sudo__needs_pass) echo "Please supply sudo password for the following command: sudo $cmd" sudo $cmd ;; *) echo "Please supply root password for the following command: su -c \"$cmd\"" su -c "$cmd" ;; esac } read_email() { local email read -rp "Please input a valid email address > " email ' domain "$FABMANAGER_PATH/config/env" # nginx configuration if [ "$NGINX" != "n" ]; then mkdir -p "$FABMANAGER_PATH/config/nginx" \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/nginx_with_ssl.conf.example > "$FABMANAGER_PATH/config/nginx/fabmanager.conf.ssl" \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/nginx.conf.example > "$FABMANAGER_PATH/config/nginx/fabmanager.conf" fi # let's encrypt configuration if [ "$LETSENCRYPT" != "n" ]; then mkdir -p "$FABMANAGER_PATH/letsencrypt/etc/config" mkdir -p "$FABMANAGER_PATH/letsencrypt/systemd" mkdir -p "$FABMANAGER_PATH/letsencrypt/etc/webrootauth" \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" fi # ElasticSearch configuration files \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/elasticsearch.yml > "$FABMANAGER_PATH/elasticsearch/config/elasticsearch.yml" \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/log4j2.properties > "$FABMANAGER_PATH/elasticsearch/config/log4j2.properties" # docker-compose \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/docker-compose.yml > "$FABMANAGER_PATH/docker-compose.yml" } yq() { docker run --rm -i -v "${FABMANAGER_PATH}:/workdir" mikefarah/yq:4 "$@" } prepare_nginx() { if [ "$NGINX" != "n" ]; then sed -i.bak "s/MAIN_DOMAIN/${MAIN_DOMAIN[0]}/g" "$FABMANAGER_PATH/config/nginx/fabmanager.conf" sed -i.bak "s/MAIN_DOMAIN/${MAIN_DOMAIN[0]}/g" "$FABMANAGER_PATH/config/nginx/fabmanager.conf.ssl" sed -i.bak "s/ANOTHER_DOMAIN_1/$OTHER_DOMAINS/g" "$FABMANAGER_PATH/config/nginx/fabmanager.conf.ssl" sed -i.bak "s/URL_WITH_PROTOCOL_HTTPS/https:\/\/${MAIN_DOMAIN[0]}/g" "$FABMANAGER_PATH/config/nginx/fabmanager.conf.ssl" else # if nginx is not installed, remove its associated block from docker-compose.yml echo "Removing nginx..." yq -i eval 'del(.services.nginx)' docker-compose.yml printf "The two following configurations are useful if you want to install Fab-manager behind a reverse proxy...\n" read -rp "- Do you want to map the Fab-manager's service to an external network? (Y/n) " confirm /dev/null; then echo "Creating the external network $network..." docker network create "$network" fi fi read -rp "- Do you want to rename the Fab-manager's service? (Y/n) " confirm " value " value &2 echo "Please input a password for this administrator's account" read -rsp " > " password &2 printf "\nError: password is too short (minimal length: 8 characters)\n" password=$(read_password 'no-confirm') fi if [ "$1" != 'no-confirm' ]; then >&2 printf "\nConfirm the password\n" read -rsp " > " confirmation &2 printf "\nError: passwords mismatch\n" password=$(read_password) fi fi echo "$password" } setup_assets_and_databases() { printf "\n\nWe will now setup the database.\n" read -rp "Continue? (Y/n) " confirm