From 64cf1635efec7ed56dc04a0a96e6ba6cefb76a38 Mon Sep 17 00:00:00 2001 From: Antonio Espiritu Date: Wed, 30 Apr 2025 13:09:37 -0600 Subject: [PATCH] carga --- .DS_Store | Bin 0 -> 6148 bytes .gitattributes | 2 + LICENSE | 13 + README.md | 4 +- config | 3 + install_instancia | 73 ++++++ install_primaria | 73 ++++++ lib/_backend.sh | 258 +++++++++++++++++++ lib/_frontend.sh | 182 +++++++++++++ lib/_inquiry.sh | 244 ++++++++++++++++++ lib/_system.sh | 544 +++++++++++++++++++++++++++++++++++++++ lib/manifest.sh | 6 + ola.txt | 1 + utils/_banner.sh | 39 +++ utils/manifest.sh | 3 + variables/_app.sh | 15 ++ variables/_background.sh | 6 + variables/_fonts.sh | 16 ++ variables/_general.sh | 5 + variables/manifest.sh | 6 + 20 files changed, 1490 insertions(+), 3 deletions(-) create mode 100644 .DS_Store create mode 100644 .gitattributes create mode 100644 LICENSE create mode 100644 config create mode 100644 install_instancia create mode 100644 install_primaria create mode 100644 lib/_backend.sh create mode 100644 lib/_frontend.sh create mode 100644 lib/_inquiry.sh create mode 100644 lib/_system.sh create mode 100644 lib/manifest.sh create mode 100644 ola.txt create mode 100644 utils/_banner.sh create mode 100644 utils/manifest.sh create mode 100644 variables/_app.sh create mode 100644 variables/_background.sh create mode 100644 variables/_fonts.sh create mode 100644 variables/_general.sh create mode 100644 variables/manifest.sh diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8350e0a54655db0a2f753af37a61339fa1f6ddad GIT binary patch literal 6148 zcmeHK%T59@6g>r0(8S=*<$M8&e=s7%5FZOzxKtiWNCq$huIF$3Ccng`p4%2OEx0vC z@13-#?c8&FdzwtA08Dc=Is@tesw{$~8mk>9@1<;6$&VZojl}3=^Wh+y57?K0YQJ9r z*}DoF7-NEEw0~E8cll|}F64Oahd!2kUdS0>#nvMh5%)df?qi5KW_TiJ9QvAZN^P8m_Mj`@;pkzeMlTw6Gc&9mrrfNOMc zfi`Z@Lp$`AoXlGxry9ESJVy&R#0I7qMGR&UF!rpr6Xp`BE13kIHN37@#vRFa><6k1@WA2b6H2o2 + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md index 97ad3e0..0166584 100644 --- a/README.md +++ b/README.md @@ -1,3 +1 @@ -# instalador - -atende \ No newline at end of file +Todos os direitos reservados a https://atendechat.com diff --git a/config b/config new file mode 100644 index 0000000..3cd3e2a --- /dev/null +++ b/config @@ -0,0 +1,3 @@ +deploy_password=deploybotmal +mysql_root_password= +db_pass=3PDTleNftG3hfREtysleqHx61bgyKO89z2wIQ2Guw7M= diff --git a/install_instancia b/install_instancia new file mode 100644 index 0000000..a7ab8d1 --- /dev/null +++ b/install_instancia @@ -0,0 +1,73 @@ +#!/bin/bash + +# reset shell colors +tput init + +# https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + PROJECT_ROOT="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$PROJECT_ROOT/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +PROJECT_ROOT="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" + +# required imports +source "${PROJECT_ROOT}"/variables/manifest.sh +source "${PROJECT_ROOT}"/utils/manifest.sh +source "${PROJECT_ROOT}"/lib/manifest.sh + +# user configs file +if [[ ! -e "${PROJECT_ROOT}"/config ]]; then + cat << EOF > "${PROJECT_ROOT}"/config +deploy_password=${deploy_password} +mysql_root_password=${mysql_root_password} +db_pass=${db_pass} +EOF +fi + +# this file has passwords +sudo su - root </dev/null 2>&1 && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$PROJECT_ROOT/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +PROJECT_ROOT="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" + +# required imports +source "${PROJECT_ROOT}"/variables/manifest.sh +source "${PROJECT_ROOT}"/utils/manifest.sh +source "${PROJECT_ROOT}"/lib/manifest.sh + +# user configs file +if [[ ! -e "${PROJECT_ROOT}"/config ]]; then + cat << EOF > "${PROJECT_ROOT}"/config +deploy_password=${deploy_password} +mysql_root_password=${mysql_root_password} +db_pass=${db_pass} +EOF +fi + +# this file has passwords +sudo su - root < /home/deploy/${instancia_add}/backend/.env +NODE_ENV= +BACKEND_URL=${backend_url} +FRONTEND_URL=${frontend_url} +PROXY_PORT=443 +PORT=${backend_port} + +DB_DIALECT=postgres +DB_HOST=localhost +DB_PORT=5432 +DB_USER=${instancia_add} +DB_PASS=${mysql_root_password} +DB_NAME=${instancia_add} + +JWT_SECRET=${jwt_secret} +JWT_REFRESH_SECRET=${jwt_refresh_secret} + +REDIS_URI=redis://:${mysql_root_password}@127.0.0.1:${redis_port} +REDIS_OPT_LIMITER_MAX=1 +REGIS_OPT_LIMITER_DURATION=3000 + +USER_LIMIT=${max_user} +CONNECTIONS_LIMIT=${max_whats} +CLOSED_SEND_BY_ME=true + +npm_package_version="6.0.1" + +[-]EOF +EOF + + sleep 2 +} + +####################################### +# installs node.js dependencies +# Arguments: +# None +####################################### +backend_node_dependencies() { + print_banner + printf "${WHITE} 💻 Instalando dependências do backend...${GRAY_LIGHT}" + printf "\n\n" + + sleep 2 + + sudo su - deploy < /etc/nginx/sites-available/${instancia_add}-backend << 'END' +server { + server_name $backend_hostname; + location / { + proxy_pass http://127.0.0.1:${backend_port}; + proxy_http_version 1.1; + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_cache_bypass \$http_upgrade; + } +} +END +ln -s /etc/nginx/sites-available/${instancia_add}-backend /etc/nginx/sites-enabled +EOF + + sleep 2 +} diff --git a/lib/_frontend.sh b/lib/_frontend.sh new file mode 100644 index 0000000..dd6e293 --- /dev/null +++ b/lib/_frontend.sh @@ -0,0 +1,182 @@ +#!/bin/bash +# +# functions for setting up app frontend + +####################################### +# installed node packages +# Arguments: +# None +####################################### +frontend_node_dependencies() { + print_banner + printf "${WHITE} 💻 Instalando dependências do frontend...${GRAY_LIGHT}" + printf "\n\n" + + sleep 2 + + sudo su - deploy < /home/deploy/${instancia_add}/frontend/.env +REACT_APP_BACKEND_URL=${backend_url} +REACT_APP_HOURS_CLOSE_TICKETS_AUTO = 24 +[-]EOF +EOF + + sleep 2 + +sudo su - deploy << EOF + cat <<[-]EOF > /home/deploy/${instancia_add}/frontend/server.js +//simple express server to run frontend production build; +const express = require("express"); +const path = require("path"); +const app = express(); +app.use(express.static(path.join(__dirname, "build"))); +app.get("/*", function (req, res) { + res.sendFile(path.join(__dirname, "build", "index.html")); +}); +app.listen(${frontend_port}); + +[-]EOF +EOF + + sleep 2 +} + +####################################### +# starts pm2 for frontend +# Arguments: +# None +####################################### +frontend_start_pm2() { + print_banner + printf "${WHITE} 💻 Iniciando pm2 (frontend)...${GRAY_LIGHT}" + printf "\n\n" + + sleep 2 + + sudo su - deploy < /etc/nginx/sites-available/${instancia_add}-frontend << 'END' +server { + server_name $frontend_hostname; + + location / { + proxy_pass http://127.0.0.1:${frontend_port}; + proxy_http_version 1.1; + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_cache_bypass \$http_upgrade; + } +} +END + +ln -s /etc/nginx/sites-available/${instancia_add}-frontend /etc/nginx/sites-enabled +EOF + + sleep 2 +} diff --git a/lib/_inquiry.sh b/lib/_inquiry.sh new file mode 100644 index 0000000..9e34cbb --- /dev/null +++ b/lib/_inquiry.sh @@ -0,0 +1,244 @@ +#!/bin/bash + +get_mysql_root_password() { + + print_banner + printf "${WHITE} 💻 Insira senha para o usuario Deploy e Banco de Dados (Não utilizar caracteres especiais):${GRAY_LIGHT}" + printf "\n\n" + read -p "> " mysql_root_password +} + +get_link_git() { + + print_banner + printf "${WHITE} 💻 Insira o link do GITHUB do Atendechat que deseja instalar:${GRAY_LIGHT}" + printf "\n\n" + read -p "> " link_git +} + +get_instancia_add() { + + print_banner + printf "${WHITE} 💻 Informe um nome para a Instancia/Empresa que será instalada (Não utilizar espaços ou caracteres especiais, Utilizar Letras minusculas; ):${GRAY_LIGHT}" + printf "\n\n" + read -p "> " instancia_add +} + +get_max_whats() { + + print_banner + printf "${WHITE} 💻 Informe a Qtde de Conexões/Whats que a ${instancia_add} poderá cadastrar:${GRAY_LIGHT}" + printf "\n\n" + read -p "> " max_whats +} + +get_max_user() { + + print_banner + printf "${WHITE} 💻 Informe a Qtde de Usuarios/Atendentes que a ${instancia_add} poderá cadastrar:${GRAY_LIGHT}" + printf "\n\n" + read -p "> " max_user +} + +get_frontend_url() { + + print_banner + printf "${WHITE} 💻 Digite o domínio do FRONTEND/PAINEL para a ${instancia_add}:${GRAY_LIGHT}" + printf "\n\n" + read -p "> " frontend_url +} + +get_backend_url() { + + print_banner + printf "${WHITE} 💻 Digite o domínio do BACKEND/API para a ${instancia_add}:${GRAY_LIGHT}" + printf "\n\n" + read -p "> " backend_url +} + +get_frontend_port() { + + print_banner + printf "${WHITE} 💻 Digite a porta do FRONTEND para a ${instancia_add}; Ex: 3000 A 3999 ${GRAY_LIGHT}" + printf "\n\n" + read -p "> " frontend_port +} + + +get_backend_port() { + + print_banner + printf "${WHITE} 💻 Digite a porta do BACKEND para esta instancia; Ex: 4000 A 4999 ${GRAY_LIGHT}" + printf "\n\n" + read -p "> " backend_port +} + +get_redis_port() { + + print_banner + printf "${WHITE} 💻 Digite a porta do REDIS/AGENDAMENTO MSG para a ${instancia_add}; Ex: 5000 A 5999 ${GRAY_LIGHT}" + printf "\n\n" + read -p "> " redis_port +} + +get_empresa_delete() { + + print_banner + printf "${WHITE} 💻 Digite o nome da Instancia/Empresa que será Deletada (Digite o mesmo nome de quando instalou):${GRAY_LIGHT}" + printf "\n\n" + read -p "> " empresa_delete +} + +get_empresa_atualizar() { + + print_banner + printf "${WHITE} 💻 Digite o nome da Instancia/Empresa que deseja Atualizar (Digite o mesmo nome de quando instalou):${GRAY_LIGHT}" + printf "\n\n" + read -p "> " empresa_atualizar +} + +get_empresa_bloquear() { + + print_banner + printf "${WHITE} 💻 Digite o nome da Instancia/Empresa que deseja Bloquear (Digite o mesmo nome de quando instalou):${GRAY_LIGHT}" + printf "\n\n" + read -p "> " empresa_bloquear +} + +get_empresa_desbloquear() { + + print_banner + printf "${WHITE} 💻 Digite o nome da Instancia/Empresa que deseja Desbloquear (Digite o mesmo nome de quando instalou):${GRAY_LIGHT}" + printf "\n\n" + read -p "> " empresa_desbloquear +} + +get_empresa_dominio() { + + print_banner + printf "${WHITE} 💻 Digite o nome da Instancia/Empresa que deseja Alterar os Dominios (Atenção para alterar os dominios precisa digitar os 2, mesmo que vá alterar apenas 1):${GRAY_LIGHT}" + printf "\n\n" + read -p "> " empresa_dominio +} + +get_alter_frontend_url() { + + print_banner + printf "${WHITE} 💻 Digite o NOVO domínio do FRONTEND/PAINEL para a ${empresa_dominio}:${GRAY_LIGHT}" + printf "\n\n" + read -p "> " alter_frontend_url +} + +get_alter_backend_url() { + + print_banner + printf "${WHITE} 💻 Digite o NOVO domínio do BACKEND/API para a ${empresa_dominio}:${GRAY_LIGHT}" + printf "\n\n" + read -p "> " alter_backend_url +} + +get_alter_frontend_port() { + + print_banner + printf "${WHITE} 💻 Digite a porta do FRONTEND da Instancia/Empresa ${empresa_dominio}; A porta deve ser o mesma informada durante a instalação ${GRAY_LIGHT}" + printf "\n\n" + read -p "> " alter_frontend_port +} + + +get_alter_backend_port() { + + print_banner + printf "${WHITE} 💻 Digite a porta do BACKEND da Instancia/Empresa ${empresa_dominio}; A porta deve ser o mesma informada durante a instalação ${GRAY_LIGHT}" + printf "\n\n" + read -p "> " alter_backend_port +} + + +get_urls() { + get_mysql_root_password + get_link_git + get_instancia_add + get_max_whats + get_max_user + get_frontend_url + get_backend_url + get_frontend_port + get_backend_port + get_redis_port +} + +software_update() { + get_empresa_atualizar + frontend_update + backend_update +} + +software_delete() { + get_empresa_delete + deletar_tudo +} + +software_bloquear() { + get_empresa_bloquear + configurar_bloqueio +} + +software_desbloquear() { + get_empresa_desbloquear + configurar_desbloqueio +} + +software_dominio() { + get_empresa_dominio + get_alter_frontend_url + get_alter_backend_url + get_alter_frontend_port + get_alter_backend_port + configurar_dominio +} + +inquiry_options() { + + print_banner + printf "${WHITE} 💻 Bem vindo(a) ao Gerenciador Atendechat, Selecione abaixo a proxima ação!${GRAY_LIGHT}" + printf "\n\n" + printf " [0] Instalar Atendechat\n" + printf " [1] Atualizar Atendechat\n" + printf " [2] Deletar Atendechat\n" + printf " [3] Bloquear Atendechat\n" + printf " [4] Desbloquear Atendechat\n" + printf " [5] Alter. dominio Atendechat\n" + printf "\n" + read -p "> " option + + case "${option}" in + 0) get_urls ;; + + 1) + software_update + exit + ;; + + 2) + software_delete + exit + ;; + 3) + software_bloquear + exit + ;; + 4) + software_desbloquear + exit + ;; + 5) + software_dominio + exit + ;; + + *) exit ;; + esac +} + + diff --git a/lib/_system.sh b/lib/_system.sh new file mode 100644 index 0000000..eeb8e29 --- /dev/null +++ b/lib/_system.sh @@ -0,0 +1,544 @@ +#!/bin/bash +# +# system management + +####################################### +# creates user +# Arguments: +# None +####################################### +system_create_user() { + print_banner + printf "${WHITE} 💻 Agora, vamos criar o usuário para a instancia...${GRAY_LIGHT}" + printf "\n\n" + + sleep 2 + + sudo su - root < /etc/nginx/sites-available/${empresa_dominio}-backend << 'END' +server { + server_name $backend_hostname; + location / { + proxy_pass http://127.0.0.1:${alter_backend_port}; + proxy_http_version 1.1; + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_cache_bypass \$http_upgrade; + } +} +END +ln -s /etc/nginx/sites-available/${empresa_dominio}-backend /etc/nginx/sites-enabled +EOF + +sleep 2 + +frontend_hostname=$(echo "${alter_frontend_url/https:\/\/}") + +sudo su - root << EOF +cat > /etc/nginx/sites-available/${empresa_dominio}-frontend << 'END' +server { + server_name $frontend_hostname; + location / { + proxy_pass http://127.0.0.1:${alter_frontend_port}; + proxy_http_version 1.1; + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_cache_bypass \$http_upgrade; + } +} +END +ln -s /etc/nginx/sites-available/${empresa_dominio}-frontend /etc/nginx/sites-enabled +EOF + + sleep 2 + + sudo su - root < /etc/apt/sources.list.d/pgdg.list' + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - + sudo apt-get update -y && sudo apt-get -y install postgresql + sleep 2 + sudo timedatectl set-timezone America/Sao_Paulo + sudo npm install -g pm2 + +EOF + + sleep 2 +} +####################################### +# installs docker +# Arguments: +# None +####################################### +system_docker_install() { + print_banner + printf "${WHITE} 💻 Instalando docker...${GRAY_LIGHT}" + printf "\n\n" + + sleep 2 + + sudo su - root < /etc/nginx/conf.d/deploy.conf << 'END' +client_max_body_size 100M; +END + +EOF + + sleep 2 +} + +####################################### +# installs nginx +# Arguments: +# None +####################################### +system_certbot_setup() { + print_banner + printf "${WHITE} 💻 Configurando certbot...${GRAY_LIGHT}" + printf "\n\n" + + sleep 2 + + backend_domain=$(echo "${backend_url/https:\/\/}") + frontend_domain=$(echo "${frontend_url/https:\/\/}") + + sudo su - root <