#!/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[0m on https://feedback.fab-manager.com/" echo -e "For \e[1mbug reports\e[0m, please open a new issue on https://github.com/sleede/fab-manager/issues" echo -e "You can call for \e[1mcommunity assistance\e[0m 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[0m:\nhttps://www.fab-manager.com/saas-offer\n\n" read -rp "Continue? (Y/n) " confirm /dev/null 2>/dev/null then if ! command docker-compose version 1>/dev/null 2>/dev/null then echo -e "\e[91m[ ❌ ] docker-compose was not found, exiting...\e[39m" && exit 1 else command docker-compose "$@" fi else docker compose "$@" fi } is_root() { return $(id -u) } has_sudo() { local prompt prompt=$(sudo -nv 2>&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 -rep "Please input a valid email address > " email ' domain "$FABMANAGER_PATH/config/env" # Fab-manager auth provider configuration file touch "$FABMANAGER_PATH/config/auth_provider.yml" # 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" # proxy if [ "$CERTIFICATE" != "" ]; then mkdir -p "$FABMANAGER_PATH/config/proxy" echo "$CERTIFICATE" > "$FABMANAGER_PATH/config/proxy/certificate.pem" \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/proxy/.npmrc > "$FABMANAGER_PATH/config/proxy/.npmrc" \curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/setup/proxy/gitconfig > "$FABMANAGER_PATH/config/proxy/gitconfig" fi } yq() { docker run --rm -i -v "${FABMANAGER_PATH}:/workdir" --user "$UID" mikefarah/yq:4 "$@" } bat() { docker run --rm -i -v "${PWD}:/workdir" --user "$UID" sleede/bat:latest "$@" } 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 /dev/null; then get_md_anchor "$doc" "ALLOW_INSECURE_HTTP" | bat --file-name "ALLOW_INSECURE_HTTP" --language md --color=always printf "You have set \e[1mDEFAULT_PROTOCOL\e[0m to \e[1mhttp\e[21m.\n" read -rp "Do you want to allow insecure HTTP? (Y/n) " confirm &2 echo "Please input a password for this administrator's account" read -rsp " > " password &2 printf "\nError: password is too short (minimal length: 12 characters)\n" password=$(read_password 'no-confirm') fi if [[ ! $password =~ [0-9] || ! $password =~ [a-z] || ! $password =~ [A-Z] || ! $password =~ [[:punct:]] ]]; then >&2 printf "\nError: password is too weak (should contain uppercases, lowercases, digits and special 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