carga
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
||||||
13
LICENSE
Normal file
13
LICENSE
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright (C) 2004 riservato.xyz <contact@riservato.xyz>
|
||||||
|
|
||||||
|
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.
|
||||||
@@ -1,3 +1 @@
|
|||||||
# instalador
|
Todos os direitos reservados a https://atendechat.com
|
||||||
|
|
||||||
atende
|
|
||||||
|
|||||||
3
config
Normal file
3
config
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
deploy_password=deploybotmal
|
||||||
|
mysql_root_password=
|
||||||
|
db_pass=3PDTleNftG3hfREtysleqHx61bgyKO89z2wIQ2Guw7M=
|
||||||
73
install_instancia
Normal file
73
install_instancia
Normal file
@@ -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 <<EOF
|
||||||
|
chown root:root "${PROJECT_ROOT}"/config
|
||||||
|
chmod 700 "${PROJECT_ROOT}"/config
|
||||||
|
EOF
|
||||||
|
source "${PROJECT_ROOT}"/config
|
||||||
|
|
||||||
|
# interactive CLI
|
||||||
|
inquiry_options
|
||||||
|
|
||||||
|
# dependencies related
|
||||||
|
#system_update
|
||||||
|
#system_node_install
|
||||||
|
#system_pm2_install
|
||||||
|
#system_docker_install
|
||||||
|
#system_puppeteer_dependencies
|
||||||
|
#system_snapd_install
|
||||||
|
#system_nginx_install
|
||||||
|
#system_certbot_install
|
||||||
|
|
||||||
|
# system config
|
||||||
|
#system_create_user
|
||||||
|
|
||||||
|
# backend related
|
||||||
|
system_git_clone
|
||||||
|
backend_set_env
|
||||||
|
backend_redis_create
|
||||||
|
backend_node_dependencies
|
||||||
|
backend_node_build
|
||||||
|
backend_db_migrate
|
||||||
|
backend_db_seed
|
||||||
|
backend_start_pm2
|
||||||
|
backend_nginx_setup
|
||||||
|
|
||||||
|
# frontend related
|
||||||
|
frontend_set_env
|
||||||
|
frontend_node_dependencies
|
||||||
|
frontend_node_build
|
||||||
|
frontend_start_pm2
|
||||||
|
frontend_nginx_setup
|
||||||
|
|
||||||
|
# network related
|
||||||
|
#system_nginx_conf
|
||||||
|
system_nginx_restart
|
||||||
|
system_certbot_setup
|
||||||
73
install_primaria
Normal file
73
install_primaria
Normal file
@@ -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 <<EOF
|
||||||
|
chown root:root "${PROJECT_ROOT}"/config
|
||||||
|
chmod 700 "${PROJECT_ROOT}"/config
|
||||||
|
EOF
|
||||||
|
source "${PROJECT_ROOT}"/config
|
||||||
|
|
||||||
|
# interactive CLI
|
||||||
|
inquiry_options
|
||||||
|
|
||||||
|
# dependencies related
|
||||||
|
system_update
|
||||||
|
system_node_install
|
||||||
|
system_pm2_install
|
||||||
|
system_docker_install
|
||||||
|
system_puppeteer_dependencies
|
||||||
|
system_snapd_install
|
||||||
|
system_nginx_install
|
||||||
|
system_certbot_install
|
||||||
|
|
||||||
|
# system config
|
||||||
|
system_create_user
|
||||||
|
|
||||||
|
# backend related
|
||||||
|
system_git_clone
|
||||||
|
backend_set_env
|
||||||
|
backend_redis_create
|
||||||
|
backend_node_dependencies
|
||||||
|
backend_node_build
|
||||||
|
backend_db_migrate
|
||||||
|
backend_db_seed
|
||||||
|
backend_start_pm2
|
||||||
|
backend_nginx_setup
|
||||||
|
|
||||||
|
# frontend related
|
||||||
|
frontend_set_env
|
||||||
|
frontend_node_dependencies
|
||||||
|
frontend_node_build
|
||||||
|
frontend_start_pm2
|
||||||
|
frontend_nginx_setup
|
||||||
|
|
||||||
|
# network related
|
||||||
|
system_nginx_conf
|
||||||
|
system_nginx_restart
|
||||||
|
system_certbot_setup
|
||||||
258
lib/_backend.sh
Normal file
258
lib/_backend.sh
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# functions for setting up app backend
|
||||||
|
#######################################
|
||||||
|
# creates REDIS db using docker
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
backend_redis_create() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Criando Redis & Banco Postgres...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
usermod -aG docker deploy
|
||||||
|
docker run --name redis-${instancia_add} -p ${redis_port}:6379 --restart always --detach redis redis-server --requirepass ${mysql_root_password}
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
sudo su - postgres
|
||||||
|
createdb ${instancia_add};
|
||||||
|
psql
|
||||||
|
CREATE USER ${instancia_add} SUPERUSER INHERIT CREATEDB CREATEROLE;
|
||||||
|
ALTER USER ${instancia_add} PASSWORD '${mysql_root_password}';
|
||||||
|
\q
|
||||||
|
exit
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# sets environment variable for backend.
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
backend_set_env() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Configurando variáveis de ambiente (backend)...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# ensure idempotency
|
||||||
|
backend_url=$(echo "${backend_url/https:\/\/}")
|
||||||
|
backend_url=${backend_url%%/*}
|
||||||
|
backend_url=https://$backend_url
|
||||||
|
|
||||||
|
# ensure idempotency
|
||||||
|
frontend_url=$(echo "${frontend_url/https:\/\/}")
|
||||||
|
frontend_url=${frontend_url%%/*}
|
||||||
|
frontend_url=https://$frontend_url
|
||||||
|
|
||||||
|
sudo su - deploy << EOF
|
||||||
|
cat <<[-]EOF > /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 <<EOF
|
||||||
|
cd /home/deploy/${instancia_add}/backend
|
||||||
|
npm install --force
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# compiles backend code
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
backend_node_build() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Compilando o código do backend...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
cd /home/deploy/${instancia_add}/backend
|
||||||
|
npm run build
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# updates frontend code
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
backend_update() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Atualizando o backend...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
cd /home/deploy/${empresa_atualizar}
|
||||||
|
pm2 stop ${empresa_atualizar}-backend
|
||||||
|
git pull
|
||||||
|
cd /home/deploy/${empresa_atualizar}/backend
|
||||||
|
npm install
|
||||||
|
npm update -f
|
||||||
|
npm install @types/fs-extra
|
||||||
|
rm -rf dist
|
||||||
|
npm run build
|
||||||
|
npx sequelize db:migrate
|
||||||
|
npx sequelize db:migrate
|
||||||
|
npx sequelize db:seed
|
||||||
|
pm2 start ${empresa_atualizar}-backend
|
||||||
|
pm2 save
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# runs db migrate
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
backend_db_migrate() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Executando db:migrate...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
cd /home/deploy/${instancia_add}/backend
|
||||||
|
npx sequelize db:migrate
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# runs db seed
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
backend_db_seed() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Executando db:seed...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
cd /home/deploy/${instancia_add}/backend
|
||||||
|
npx sequelize db:seed:all
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# starts backend using pm2 in
|
||||||
|
# production mode.
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
backend_start_pm2() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Iniciando pm2 (backend)...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
cd /home/deploy/${instancia_add}/backend
|
||||||
|
pm2 start dist/server.js --name ${instancia_add}-backend
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# updates frontend code
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
backend_nginx_setup() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Configurando nginx (backend)...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
backend_hostname=$(echo "${backend_url/https:\/\/}")
|
||||||
|
|
||||||
|
sudo su - root << EOF
|
||||||
|
cat > /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
|
||||||
|
}
|
||||||
182
lib/_frontend.sh
Normal file
182
lib/_frontend.sh
Normal file
@@ -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 <<EOF
|
||||||
|
cd /home/deploy/${instancia_add}/frontend
|
||||||
|
npm install --force
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# compiles frontend code
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
frontend_node_build() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Compilando o código do frontend...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
cd /home/deploy/${instancia_add}/frontend
|
||||||
|
npm run build
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# updates frontend code
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
frontend_update() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Atualizando o frontend...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
cd /home/deploy/${empresa_atualizar}
|
||||||
|
pm2 stop ${empresa_atualizar}-frontend
|
||||||
|
git pull
|
||||||
|
cd /home/deploy/${empresa_atualizar}/frontend
|
||||||
|
npm install
|
||||||
|
rm -rf build
|
||||||
|
npm run build
|
||||||
|
pm2 start ${empresa_atualizar}-frontend
|
||||||
|
pm2 save
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# sets frontend environment variables
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
frontend_set_env() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Configurando variáveis de ambiente (frontend)...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# ensure idempotency
|
||||||
|
backend_url=$(echo "${backend_url/https:\/\/}")
|
||||||
|
backend_url=${backend_url%%/*}
|
||||||
|
backend_url=https://$backend_url
|
||||||
|
|
||||||
|
sudo su - deploy << EOF
|
||||||
|
cat <<[-]EOF > /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 <<EOF
|
||||||
|
cd /home/deploy/${instancia_add}/frontend
|
||||||
|
pm2 start server.js --name ${instancia_add}-frontend
|
||||||
|
pm2 save
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
pm2 startup
|
||||||
|
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u deploy --hp /home/deploy
|
||||||
|
EOF
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# sets up nginx for frontend
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
frontend_nginx_setup() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Configurando nginx (frontend)...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
frontend_hostname=$(echo "${frontend_url/https:\/\/}")
|
||||||
|
|
||||||
|
sudo su - root << EOF
|
||||||
|
|
||||||
|
cat > /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
|
||||||
|
}
|
||||||
244
lib/_inquiry.sh
Normal file
244
lib/_inquiry.sh
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
544
lib/_system.sh
Normal file
544
lib/_system.sh
Normal file
@@ -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 <<EOF
|
||||||
|
sudo useradd -m -s /bin/bash -G sudo deploy
|
||||||
|
|
||||||
|
ENCRYPTED_PASS=deploybotmal
|
||||||
|
|
||||||
|
echo "deploy:${ENCRYPTED_PASS}" | sudo chpasswd
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# clones repostories using git
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_git_clone() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Fazendo download do código Atendechat...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
git clone https://agente-atendechat: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@github.com/atendechat-org/codatendechat.git /home/deploy/${instancia_add}/
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# updates system
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_update() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Vamos atualizar o sistema do Atendechat...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
apt -y update
|
||||||
|
sudo apt-get install -y libxshmfence-dev libgbm-dev wget unzip fontconfig locales gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# delete system
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
deletar_tudo() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Vamos deletar o Atendechat...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
docker container rm redis-${empresa_delete} --force
|
||||||
|
cd && rm -rf /etc/nginx/sites-enabled/${empresa_delete}-frontend
|
||||||
|
cd && rm -rf /etc/nginx/sites-enabled/${empresa_delete}-backend
|
||||||
|
cd && rm -rf /etc/nginx/sites-available/${empresa_delete}-frontend
|
||||||
|
cd && rm -rf /etc/nginx/sites-available/${empresa_delete}-backend
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - postgres
|
||||||
|
dropuser ${empresa_delete}
|
||||||
|
dropdb ${empresa_delete}
|
||||||
|
exit
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
rm -rf /home/deploy/${empresa_delete}
|
||||||
|
pm2 delete ${empresa_delete}-frontend ${empresa_delete}-backend
|
||||||
|
pm2 save
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Remoção da Instancia/Empresa ${empresa_delete} realizado com sucesso ...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# bloquear system
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
configurar_bloqueio() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Vamos bloquear o Atendechat...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
pm2 stop ${empresa_bloquear}-backend
|
||||||
|
pm2 save
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Bloqueio da Instancia/Empresa ${empresa_bloquear} realizado com sucesso ...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# desbloquear system
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
configurar_desbloqueio() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Vamos Desbloquear o Atendechat...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
pm2 start ${empresa_bloquear}-backend
|
||||||
|
pm2 save
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Desbloqueio da Instancia/Empresa ${empresa_desbloquear} realizado com sucesso ...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# alter dominio system
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
configurar_dominio() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Vamos Alterar os Dominios do Atendechat...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
cd && rm -rf /etc/nginx/sites-enabled/${empresa_dominio}-frontend
|
||||||
|
cd && rm -rf /etc/nginx/sites-enabled/${empresa_dominio}-backend
|
||||||
|
cd && rm -rf /etc/nginx/sites-available/${empresa_dominio}-frontend
|
||||||
|
cd && rm -rf /etc/nginx/sites-available/${empresa_dominio}-backend
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - deploy <<EOF
|
||||||
|
cd && cd /home/deploy/${empresa_dominio}/frontend
|
||||||
|
sed -i "1c\REACT_APP_BACKEND_URL=https://${alter_backend_url}" .env
|
||||||
|
cd && cd /home/deploy/${empresa_dominio}/backend
|
||||||
|
sed -i "2c\BACKEND_URL=https://${alter_backend_url}" .env
|
||||||
|
sed -i "3c\FRONTEND_URL=https://${alter_frontend_url}" .env
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
backend_hostname=$(echo "${alter_backend_url/https:\/\/}")
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
cat > /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 <<EOF
|
||||||
|
service nginx restart
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
backend_domain=$(echo "${backend_url/https:\/\/}")
|
||||||
|
frontend_domain=$(echo "${frontend_url/https:\/\/}")
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
certbot -m $deploy_email \
|
||||||
|
--nginx \
|
||||||
|
--agree-tos \
|
||||||
|
--non-interactive \
|
||||||
|
--domains $backend_domain,$frontend_domain
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Alteração de dominio da Instancia/Empresa ${empresa_dominio} realizado com sucesso ...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# installs node
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_node_install() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Instalando nodejs...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||||
|
apt-get install -y nodejs
|
||||||
|
sleep 2
|
||||||
|
npm install -g npm@latest
|
||||||
|
sleep 2
|
||||||
|
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /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 <<EOF
|
||||||
|
apt install -y apt-transport-https \
|
||||||
|
ca-certificates curl \
|
||||||
|
software-properties-common
|
||||||
|
|
||||||
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
||||||
|
|
||||||
|
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
|
||||||
|
|
||||||
|
apt install -y docker-ce
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Ask for file location containing
|
||||||
|
# multiple URL for streaming.
|
||||||
|
# Globals:
|
||||||
|
# WHITE
|
||||||
|
# GRAY_LIGHT
|
||||||
|
# BATCH_DIR
|
||||||
|
# PROJECT_ROOT
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_puppeteer_dependencies() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Instalando puppeteer dependencies...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
apt-get install -y libxshmfence-dev \
|
||||||
|
libgbm-dev \
|
||||||
|
wget \
|
||||||
|
unzip \
|
||||||
|
fontconfig \
|
||||||
|
locales \
|
||||||
|
gconf-service \
|
||||||
|
libasound2 \
|
||||||
|
libatk1.0-0 \
|
||||||
|
libc6 \
|
||||||
|
libcairo2 \
|
||||||
|
libcups2 \
|
||||||
|
libdbus-1-3 \
|
||||||
|
libexpat1 \
|
||||||
|
libfontconfig1 \
|
||||||
|
libgcc1 \
|
||||||
|
libgconf-2-4 \
|
||||||
|
libgdk-pixbuf2.0-0 \
|
||||||
|
libglib2.0-0 \
|
||||||
|
libgtk-3-0 \
|
||||||
|
libnspr4 \
|
||||||
|
libpango-1.0-0 \
|
||||||
|
libpangocairo-1.0-0 \
|
||||||
|
libstdc++6 \
|
||||||
|
libx11-6 \
|
||||||
|
libx11-xcb1 \
|
||||||
|
libxcb1 \
|
||||||
|
libxcomposite1 \
|
||||||
|
libxcursor1 \
|
||||||
|
libxdamage1 \
|
||||||
|
libxext6 \
|
||||||
|
libxfixes3 \
|
||||||
|
libxi6 \
|
||||||
|
libxrandr2 \
|
||||||
|
libxrender1 \
|
||||||
|
libxss1 \
|
||||||
|
libxtst6 \
|
||||||
|
ca-certificates \
|
||||||
|
fonts-liberation \
|
||||||
|
libappindicator1 \
|
||||||
|
libnss3 \
|
||||||
|
lsb-release \
|
||||||
|
xdg-utils
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# installs pm2
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_pm2_install() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Instalando pm2...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
|
||||||
|
npm install -g pm2
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# installs snapd
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_snapd_install() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Instalando snapd...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
apt install -y snapd
|
||||||
|
snap install core
|
||||||
|
snap refresh core
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# installs certbot
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_certbot_install() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Instalando certbot...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
apt-get remove certbot
|
||||||
|
snap install --classic certbot
|
||||||
|
ln -s /snap/bin/certbot /usr/bin/certbot
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# installs nginx
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_nginx_install() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 Instalando nginx...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
apt install -y nginx
|
||||||
|
rm /etc/nginx/sites-enabled/default
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# restarts nginx
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_nginx_restart() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 reiniciando nginx...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root <<EOF
|
||||||
|
service nginx restart
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# setup for nginx.conf
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
system_nginx_conf() {
|
||||||
|
print_banner
|
||||||
|
printf "${WHITE} 💻 configurando nginx...${GRAY_LIGHT}"
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
sudo su - root << EOF
|
||||||
|
|
||||||
|
cat > /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 <<EOF
|
||||||
|
certbot -m $deploy_email \
|
||||||
|
--nginx \
|
||||||
|
--agree-tos \
|
||||||
|
--non-interactive \
|
||||||
|
--domains $backend_domain,$frontend_domain
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
}
|
||||||
6
lib/manifest.sh
Normal file
6
lib/manifest.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source "${PROJECT_ROOT}"/lib/_backend.sh
|
||||||
|
source "${PROJECT_ROOT}"/lib/_frontend.sh
|
||||||
|
source "${PROJECT_ROOT}"/lib/_system.sh
|
||||||
|
source "${PROJECT_ROOT}"/lib/_inquiry.sh
|
||||||
39
utils/_banner.sh
Normal file
39
utils/_banner.sh
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Print banner art.
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Print a board.
|
||||||
|
# Globals:
|
||||||
|
# BG_BROWN
|
||||||
|
# NC
|
||||||
|
# WHITE
|
||||||
|
# CYAN_LIGHT
|
||||||
|
# RED
|
||||||
|
# GREEN
|
||||||
|
# YELLOW
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
#######################################
|
||||||
|
print_banner() {
|
||||||
|
clear
|
||||||
|
|
||||||
|
|
||||||
|
printf "${GREEN}";
|
||||||
|
printf "###### ###### ###### ## ## ##### ###### ###### ## ## ###### ######\n";
|
||||||
|
printf "## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ##\n";
|
||||||
|
printf "## ## ## #### ###### ## ## #### ## ###### ## ## ##\n";
|
||||||
|
printf "###### ## ## ## ### ## ## ## ## ## ## ###### ##\n";
|
||||||
|
printf "## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##\n";
|
||||||
|
printf "## ## ## ###### ## ## ##### ###### ###### ## ## ## ## ##\n";
|
||||||
|
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
|
printf "2024 @ Todos os direitos reservados a https://atendechat.com\n"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
printf "${NC}";
|
||||||
|
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
3
utils/manifest.sh
Normal file
3
utils/manifest.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source "${PROJECT_ROOT}"/utils/_banner.sh
|
||||||
15
variables/_app.sh
Normal file
15
variables/_app.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Variables to be used for background styling.
|
||||||
|
|
||||||
|
# app variables
|
||||||
|
|
||||||
|
jwt_secret=$(openssl rand -base64 32)
|
||||||
|
jwt_refresh_secret=$(openssl rand -base64 32)
|
||||||
|
|
||||||
|
db_pass=$(openssl rand -base64 32)
|
||||||
|
|
||||||
|
db_user=$(openssl rand -base64 32)
|
||||||
|
db_name=$(openssl rand -base64 32)
|
||||||
|
|
||||||
|
deploy_email=deploy@deploy.com
|
||||||
6
variables/_background.sh
Normal file
6
variables/_background.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Variables to be used for background styling.
|
||||||
|
|
||||||
|
# color
|
||||||
|
readonly BG_BROWN="\e[0;43m"
|
||||||
16
variables/_fonts.sh
Normal file
16
variables/_fonts.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Variables to be used for font styling.
|
||||||
|
|
||||||
|
# color
|
||||||
|
readonly RED="\033[1;31m"
|
||||||
|
readonly GREEN="\033[1;32m"
|
||||||
|
readonly BLUE="\033[1;32m"
|
||||||
|
readonly WHITE="\033[1;37m"
|
||||||
|
readonly YELLOW="\033[1;33m"
|
||||||
|
readonly GRAY_LIGHT="\033[0;37m"
|
||||||
|
readonly CYAN_LIGHT="\033[1;36m"
|
||||||
|
|
||||||
|
# thickness
|
||||||
|
readonly BOLD=$(tput bold)
|
||||||
|
readonly NORMAL=$(tput sgr0)
|
||||||
5
variables/_general.sh
Normal file
5
variables/_general.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Special variables to be used for general purposes.
|
||||||
|
|
||||||
|
readonly NC="\033[0m" # reset colors
|
||||||
6
variables/manifest.sh
Normal file
6
variables/manifest.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source "${PROJECT_ROOT}"/variables/_app.sh
|
||||||
|
source "${PROJECT_ROOT}"/variables/_general.sh
|
||||||
|
source "${PROJECT_ROOT}"/variables/_background.sh
|
||||||
|
source "${PROJECT_ROOT}"/variables/_fonts.sh
|
||||||
Reference in New Issue
Block a user