403Webshell
Server IP : 146.190.157.162  /  Your IP : 216.73.217.6
Web Server : Apache
System : Linux ubuntu-s-2vcpu-4gb-amd-sfo3-01-KIT-DIGITAL 6.5.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 7 15:10:09 UTC 2024 x86_64
User : businessweek ( 639)
PHP Version : 8.2.10-2ubuntu2.2
Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_signal,pcntl_signal_dispatch,pcntl_getpriority,pcntl_setpriority,dl,putenv,parse_ini_file,show_source
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/wordpress-manager-v2/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wordpress-manager-v2/scripts/deploy-to-prd.sh
#!/bin/bash

# Cargar variables de entorno desde el archivo .env
set -a
source /var/www/html/wordpress-manager-v2/.env
set +a

# Archivo de log
LOG_FILE="/var/www/html/wordpress-manager-v2/logs/wordpress_deploy.log"
exec > >(tee -a ${LOG_FILE} ) 2>&1
set -e

echo "Iniciando despliegue del sitio..."

# Parámetros
project="$1"
domain="$2"
mysqldb="$3"
ssl="$4"

mysqlroothost=$MYSQL_ROOT_HOST
mysqlrootusername=$MYSQL_ROOT_USERNAME
mysqlrootpassword=$MYSQL_ROOT_PASSWORD

# Agregar reglas para protocolo si ssl es igual a letsencrypt
protocolo="http"
if [ "$ssl" == "letsencrypt" ]; then
    protocolo="https"
fi

# sudo ping -c 1 "$domain" &> /dev/null

# # Verifica si el ping falló
# if [ $? -ne 0 ]; then
#     echo "No hay un host disponible para $domain"
#     exit 1
# fi

# Actualizar las URLs en la base de datos
echo "Actualizando las URLs en la base de datos..."
mysql -h "$mysqlroothost" -u "$mysqlrootusername" -p"$mysqlrootpassword" "$mysqldb" -e "
UPDATE wp_options SET option_value = '$protocolo://$domain' WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://$project.devuocloud.com','$protocolo://$domain');
UPDATE wp_posts SET guid = replace(guid, 'https://$project.devuocloud.com','$protocolo://$domain');
UPDATE wp_posts SET post_content = replace(post_content, 'http://$project.devuocloud.com', '$protocolo://$domain');
UPDATE wp_posts SET post_content = replace(post_content, 'https://$project.devuocloud.com', '$protocolo://$domain');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://$project.devuocloud.com','$protocolo://$domain');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://$project.devuocloud.com','$protocolo://$domain');
"
if [ $? -ne 0 ]; then
    echo "Error actualizando las URLs en la base de datos."
    exit 1
fi

# Deshabilitar el sitio en Apache
echo "Deshabilitando el sitio en Apache..."
sudo a2dissite $project.conf
if [ $? -ne 0 ]; then
    echo "Error deshabilitando el sitio en Apache."
    exit 1
fi

# Eliminar el archivo de configuración anterior
echo "Eliminando el archivo de configuración anterior..."
sudo rm /etc/apache2/sites-available/$project.conf
if [ $? -ne 0 ]; then
    echo "Error eliminando el archivo de configuración de Apache."
    exit 1
fi

# Crear la nueva configuración de Apache
echo "Creando la nueva configuración de Apache para $project..."
sudo touch /etc/apache2/sites-available/$project.conf
if [ $? -ne 0 ]; then
    echo "Error creando el archivo de configuración de Apache."
    exit 1
fi

# Configuración de Apache
apache_config="
<VirtualHost *:80>
    ServerAdmin prod@uosolutions.com
    ServerName $domain
    ServerAlias www.$domain
    DocumentRoot /var/www/html/$project

    <Directory /var/www/html/$project>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/apache2/$project-error.log
    CustomLog /var/log/apache2/$project-access.log combined
    RewriteEngine on
"

# Agregar reglas de reescritura si ssl es igual a letsencrypt
if [ "$ssl" == "letsencrypt" ]; then
    apache_config+="
    RewriteCond %{SERVER_NAME} =$domain [OR]
    RewriteCond %{SERVER_NAME} =www.$domain
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    "
fi

apache_config+="
</VirtualHost>"
echo "$apache_config" | sudo tee /etc/apache2/sites-available/$project.conf > /dev/null
if [ $? -ne 0 ]; then
    echo "Error escribiendo la configuración de Apache."
    exit 1
fi

# Habilitar el nuevo sitio en Apache
echo "Habilitando el nuevo sitio en Apache..."
sudo a2ensite $project.conf
if [ $? -ne 0 ]; then
    echo "Error habilitando el sitio en Apache."
    exit 1
fi

# Reload Apache
echo "Reload Apache..."
sudo systemctl reload apache2
if [ $? -ne 0 ]; then
    echo "Error reload Apache."
    exit 1
fi

# Ejecutar certbot si ssl es igual a letsencrypt
echo "Validando certbot para $domain y www.$domain..."
if [ "$ssl" == "letsencrypt" ]; then

echo "Ejecutando certbot para $domain y www.$domain..."
sudo certbot --apache -d $domain -d www.$domain --non-interactive --agree-tos
if [ $? -ne 0 ]; then
    echo "Error ejecutando certbot."
    exit 1
fi
fi

echo "Ejecutando validación final de permisos..."
/bin/bash /var/www/html/wordpress-manager-v2/scripts/permissionsDisable.sh "$project"

if [ $? -eq 0 ]; then
    echo "✅ Permisos validados y cerrados correctamente."
else
    echo "⚠️ Advertencia: Hubo un problema al setear los permisos."
fi

echo "Despliegue completado exitosamente."

Youez - 2016 - github.com/yon3zu
LinuXploit