inclusão da sugestão de criação do env
This commit is contained in:
parent
f25039bded
commit
9c29d591ec
3 changed files with 121 additions and 38 deletions
143
run.sh
143
run.sh
|
|
@ -25,13 +25,13 @@ APP="appname"
|
|||
# Virtual environment name
|
||||
VENV=".venv"
|
||||
|
||||
# Nome de usuário do repositório
|
||||
# Git username
|
||||
# Nome de usuário do repositório ou grupo
|
||||
# Git username or group
|
||||
GIT_USER="username"
|
||||
|
||||
# Endereço do projeto no repositório
|
||||
# Git project url
|
||||
GITURL="https://repositório.com/$GIT_USER/$APP.git"
|
||||
GITURL="https://repo.com/$GIT_USER/$APP.git"
|
||||
|
||||
# IP público ou domínio
|
||||
# Public IP address or domain
|
||||
|
|
@ -76,10 +76,14 @@ MSG_PT[entry]="Digite sim ou s para continuar (sim/não): "
|
|||
MSG_PT[error_root]="Você precisa executar o script como root"
|
||||
MSG_PT[error_requirements]="Não encontrei o arquivo requirements.txt"
|
||||
MSG_PT[error_env]="Não encontrei o arquivo .env"
|
||||
MSG_PT[sugest_env]="Posso criar esse arquivo pra você?
|
||||
Eu criarei com as variáveis [SECRET_KEY, ALLOWED_HOSTS, DEBUG].
|
||||
Sim! vou criar uma SECRET_KEY como Django
|
||||
apenas para dar sequência e testar o servidor, claro que você pode alterar depois."
|
||||
MSG_PT[error_allwhost]="Não encontrei a variável ALLOWED_HOSTS, você lembrou de extrair do settings.py?"
|
||||
MSG_PT[error_debug]="Não encontrei a variável DEBUG, você lembrou de extrair do settings.py?"
|
||||
MSG_PT[repo]="Por favor verificar o repositório ou suas credenciais"
|
||||
MSG_PT[done]="FEITO"
|
||||
MSG_PT[done]="TUDO PRONTO! Só curtir!"
|
||||
MSG_PT[fail]="FALHOU"
|
||||
|
||||
declare -A MSG_EN
|
||||
|
|
@ -89,16 +93,32 @@ MSG_EN[entry]="Shall we proceed? (yes/no): "
|
|||
MSG_EN[error_root]="You must be root"
|
||||
MSG_EN[error_req]="Can't find requirements.txt file"
|
||||
MSG_EN[error_env]="Can't find .env file"
|
||||
MSG_EN[sugest_env]="Can i create this file for you?
|
||||
I'll create basic variables like [SECRET_KEY, ALLOWED_HOSTS, DEBUG].
|
||||
Yep! i'll create a SECRET_KEY like Django
|
||||
just for continue and test server, although you can change it after."
|
||||
MSG_EN[error_allwhost]="Can't find ALLOWED_HOSTS variable did you extract it from settings.py?"
|
||||
MSG_EN[error_debug]="Can't find DEBUG variable did you extract it from settings.py?"
|
||||
MSG_EN[repo]="Please check your repo or credentials"
|
||||
MSG_EN[done]="DONE"
|
||||
MSG_EN[done]="ALL DONE! Enjoy it!"
|
||||
MSG_EN[fail]="FAIL"
|
||||
|
||||
STEP=0
|
||||
SCRIPT_PATH=$(dirname $0)
|
||||
SCRIPT_STEP_FILE="$SCRIPT_PATH/centos_django.step"
|
||||
|
||||
CHARS="abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
|
||||
for ((i=0;i<${#CHARS};i++)); do ARRAY[$i]="${CHARS:i:1}"; done
|
||||
|
||||
# Cria uma sequência de 50 caracteres aleatórios
|
||||
# Create 50 random chars
|
||||
key_gen() {
|
||||
for ((c=1; c<=50; c++)); do
|
||||
KEY="$KEY${ARRAY[$((RANDOM % 50))]}"
|
||||
done
|
||||
echo $KEY
|
||||
}
|
||||
|
||||
# Lê o arquivo de configuração e atualiza os valores das variáveis
|
||||
# Read config file and set all variables
|
||||
if [[ -f "$SCRIPT_PATH/$ARQ_CONF" ]]; then
|
||||
|
|
@ -126,16 +146,22 @@ fi
|
|||
# Verifica se o usuário ativo é o root
|
||||
# Verify if is a root user
|
||||
if [[ "$EUID" -ne 0 ]];then
|
||||
HAS_ERROS="yes"
|
||||
ERRORS+=("${MSGS[error_root]}")
|
||||
echo -e "\033[31m${MSGS[error_root]}\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verifica a existência do usuário no sistema
|
||||
# Check if user exists
|
||||
CNU=$(grep -c $USERNAME /etc/passwd)
|
||||
if [[ $CNU -lt 1 ]]; then
|
||||
echo "precisa criar o usuário"
|
||||
#useradd --create-home $USERNAME
|
||||
useradd --create-home $USERNAME
|
||||
fi
|
||||
|
||||
# Sanitiza a variável SERVICE
|
||||
# Sanitize SERVICE var
|
||||
if [[ ! $SERVICE =~ ".service" ]]; then
|
||||
SERVICE+=".service"
|
||||
fi
|
||||
|
||||
# Obtém o IP
|
||||
|
|
@ -184,28 +210,44 @@ clone_project() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Verifica a existência dos arquivos requirements.txt e .env
|
||||
# Check for existence of requirements.txt and .env files
|
||||
validate_files() {
|
||||
# Verifica a existência do arquivo requirements.txt
|
||||
# Check for existence of requirements.txt file
|
||||
validate_requirements() {
|
||||
if [[ ! -f "/home/$USERNAME/$APP/requirements.txt" ]]; then
|
||||
HAS_ERROS="yes"
|
||||
ERRORS+=("${MSGS[error_req]}")
|
||||
fi
|
||||
|
||||
if [[ ! -f "/home/$USERNAME/$APP/.env" ]]; then
|
||||
HAS_ERROS="yes"
|
||||
ERRORS+=("${MSGS[error_env]}")
|
||||
fi
|
||||
|
||||
if [[ ${#ERRORS[@]} -ge 1 ]]; then
|
||||
echo -e "\033[31m${MSGS[errors]}"
|
||||
for error in "${ERRORS[@]}"; do
|
||||
echo -e "\033[0m - \033[37m$error\033[0m"
|
||||
done
|
||||
echo -e "\033[31m${MSGS[errors]}" &&
|
||||
echo -e "\033[0m - \033[37m${MSGS[error_req]}\033[0m" &&
|
||||
update_step_error "$x"
|
||||
fi
|
||||
}
|
||||
|
||||
# Verifica a existência do arquivo .env
|
||||
# Check for existence of .env file
|
||||
validate_env() {
|
||||
if [[ ! -f "/home/$USERNAME/$APP/.env" ]]; then
|
||||
echo -e "\033[31m${MSGS[errors]}"
|
||||
echo -e "\033[0m - \033[37m${MSGS[error_env]}\033[0m" &&
|
||||
echo -e "\n${MSGS[sugest_env]}\n" &&
|
||||
read -p "${MSGS[entry]}" resp_env &&
|
||||
if [[ -n resp_env ]]; then
|
||||
if [[ ${resp_env,,} == "sim" ]] || [[ ${resp_env,,} == "s" ]] || [[ ${resp_env,,} == "yes" ]] || [[ ${resp_env,,} == "y" ]]; then
|
||||
make_env_file
|
||||
fi
|
||||
else
|
||||
update_step_error "$x"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Cria um arquivo .env
|
||||
# Create a .env file
|
||||
make_env_file() {
|
||||
ENV="SECRET_KEY='$(key_gen)'\n
|
||||
ALLOWED_HOSTS=localhost, 127.0.0.1\n
|
||||
DEBUG=False
|
||||
"
|
||||
$(echo -e $ENV | sed -e 's/^[ \t]*//' > /home/$USERNAME/$APP/.env)
|
||||
}
|
||||
|
||||
# Incrementar IP em ALLOWED_HOSTS no arquivo .env caso não tenha incrementado
|
||||
# Increase ALLOWED_HOSTS IP on .env file if it doesn't exist
|
||||
increment_ip() {
|
||||
|
|
@ -260,7 +302,6 @@ install_packages() {
|
|||
# Criar o ambiente Virtual
|
||||
# Create venv
|
||||
create_venv() {
|
||||
# python3 -m venv /home/$USERNAME/$APP/$VENV && . /home/$USERNAME/$APP/$VENV/bin/activate
|
||||
python3 -m venv /home/$USERNAME/$APP/$VENV
|
||||
if [[ $? -ge 1 ]]; then
|
||||
update_step_error "$x"
|
||||
|
|
@ -317,6 +358,44 @@ enable_ports() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Corrigir a configuração inicial do nginx
|
||||
# Manage default nginx config file
|
||||
manage_default_nginx_file() {
|
||||
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf~ &&
|
||||
cat > /etc/nginx/nginx.conf <<EOF
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log;
|
||||
pid /run/nginx.pid;
|
||||
|
||||
|
||||
include /usr/share/nginx/modules/*.conf;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
# Criar o arquivo de configurações do NGINX
|
||||
# Create nginx config file
|
||||
create_nginx_file() {
|
||||
|
|
@ -423,16 +502,17 @@ fi
|
|||
# Start service
|
||||
run_service() {
|
||||
chmod -R 751 /home/$USERNAME
|
||||
chmod 664 /etc/systemd/system/$SERVICE.service &&
|
||||
chmod 664 /etc/systemd/system/$SERVICE &&
|
||||
chown -R $USERNAME:$USERNAME /home/$USERNAME &&
|
||||
systemctl daemon-reload &&
|
||||
systemctl enable nginx &&
|
||||
systemctl start nginx &&
|
||||
systemctl enable $SERVICE.service &&
|
||||
systemctl start $SERVICE.service &&
|
||||
systemctl enable $SERVICE &&
|
||||
systemctl start $SERVICE &&
|
||||
systemctl restart nginx
|
||||
}
|
||||
|
||||
#TODO: Verificar a nova instalação do certbot
|
||||
# Instalar o Certbot
|
||||
# Install Certbot
|
||||
certbot() {
|
||||
|
|
@ -456,7 +536,8 @@ crontab_certbot() {
|
|||
|
||||
declare -a commands=(
|
||||
"clone_project"
|
||||
"validate_files"
|
||||
"validate_requirements"
|
||||
"validate_env"
|
||||
"increment_ip"
|
||||
"update_debug"
|
||||
"install_packages"
|
||||
|
|
@ -464,6 +545,7 @@ declare -a commands=(
|
|||
"install_dependencies"
|
||||
"install_firewall"
|
||||
"enable_ports"
|
||||
"manage_default_nginx_file"
|
||||
"create_nginx_file"
|
||||
"create_uwsgi_ini_file"
|
||||
"criar_emperor_uwsgi"
|
||||
|
|
@ -472,7 +554,6 @@ declare -a commands=(
|
|||
"run_service"
|
||||
)
|
||||
|
||||
|
||||
REPORT=()
|
||||
|
||||
if [[ ${#ERRORS[@]} -ge 1 ]]; then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue