You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
231 lines
10 KiB
231 lines
10 KiB
#!/bin/bash
|
|
#
|
|
# Script de instalación completa de ViciBox (ambiente de configuración)
|
|
# Basado en la carpeta backvicibox.
|
|
#
|
|
# Orden: Perl → MariaDB → PHP → Apache (y apuntar a welcome.php)
|
|
# → restore.sh → parches a vicibox-install.pl → vicibox-install --vicibox-express
|
|
#
|
|
# Uso: sudo ./install-vicibox.sh
|
|
#
|
|
|
|
set -e
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
LOG_FILE="${SCRIPT_DIR}/install-vicibox.log"
|
|
|
|
info() { echo -e "${GREEN}[INFO]${NC} $1" | tee -a "$LOG_FILE"; }
|
|
warn() { echo -e "${YELLOW}[WARN]${NC} $1" | tee -a "$LOG_FILE"; }
|
|
error() { echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE"; }
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
error "Ejecutar como root: sudo $0"
|
|
exit 1
|
|
fi
|
|
|
|
# zypper: --gpg-auto-import-keys evita el prompt "reject/trust" en repos OBS (ej. Asterisk).
|
|
# Si pulsaste "r" (reject), el repo queda inválido: zypper rr home_vicidial_asterisk-18 y vuelve a añadirlo con --gpg-auto-import-keys ar ...
|
|
|
|
# Comprobar que estamos en backvicibox y existen archivos
|
|
if [ ! -f "${SCRIPT_DIR}/restore.sh" ]; then
|
|
error "No se encuentra restore.sh. Ejecutar desde el directorio backvicibox."
|
|
exit 1
|
|
fi
|
|
if [ ! -f "${SCRIPT_DIR}/vicibox-scripts.tar.gz" ] || [ ! -f "${SCRIPT_DIR}/astguiclient-trunk.tar.gz" ]; then
|
|
error "Faltan vicibox-scripts.tar.gz o astguiclient-trunk.tar.gz en ${SCRIPT_DIR}"
|
|
exit 1
|
|
fi
|
|
|
|
info "=========================================="
|
|
info "Instalación ViciBox (dependencias + restore + express)"
|
|
info "=========================================="
|
|
echo ""
|
|
|
|
# --- 0. Módulos Perl (antes que todo) ---
|
|
info "0. Instalando módulos Perl requeridos (perl-DBI, perl-DBD-mysql, perl-libwww-perl)..."
|
|
zypper --gpg-auto-import-keys -n install -y perl-DBI perl-DBD-mysql perl-libwww-perl >> "$LOG_FILE" 2>&1 || true
|
|
info " perl-DBI, perl-DBD-mysql, perl-libwww-perl instalados"
|
|
echo ""
|
|
|
|
# --- 1. Perl, LWP, Subversion y cron (crontab) ---
|
|
# En openSUSE el paquete es perl-libwww-perl, no libwww-perl (Debian).
|
|
info "1. Instalando Perl, perl-libwww-perl, Subversion y cronie..."
|
|
zypper --gpg-auto-import-keys -n install -y perl perl-DBI perl-DBD-mysql perl-libwww-perl subversion cronie >> "$LOG_FILE" 2>&1
|
|
systemctl enable cron >> "$LOG_FILE" 2>&1 || systemctl enable crond >> "$LOG_FILE" 2>&1 || true
|
|
systemctl start cron >> "$LOG_FILE" 2>&1 || systemctl start crond >> "$LOG_FILE" 2>&1 || true
|
|
info " Perl: $(perl -v 2>&1 | head -1)"
|
|
echo ""
|
|
|
|
# --- 2. MariaDB ---
|
|
info "2. Instalando MariaDB..."
|
|
zypper --gpg-auto-import-keys -n install -y mariadb mariadb-client >> "$LOG_FILE" 2>&1
|
|
systemctl enable mariadb >> "$LOG_FILE" 2>&1
|
|
systemctl start mariadb >> "$LOG_FILE" 2>&1
|
|
info " MariaDB instalado y en ejecución"
|
|
echo ""
|
|
|
|
# --- 3. PHP 8 y módulo Apache ---
|
|
info "3. Instalando PHP 8 y módulo Apache..."
|
|
if ! zypper lr | grep -q "devel_languages_php_php80"; then
|
|
zypper --gpg-auto-import-keys -n addrepo https://download.opensuse.org/repositories/devel:languages:php:php80/SLE_15_SP6/devel:languages:php:php80.repo
|
|
fi
|
|
zypper --gpg-auto-import-keys --no-gpg-checks -n refresh >> "$LOG_FILE" 2>&1
|
|
# php8-mbstring: VICIdial admin.php usa mb_strlen/mb_substr (UTF-8); sin esto la pagina de usuario puede cortarse (fatal error).
|
|
zypper --gpg-auto-import-keys -n install -y php8 apache2-mod_php8 php8-mysql php8-mbstring >> "$LOG_FILE" 2>&1
|
|
info " PHP $(php8 -v 2>/dev/null | head -1 || true) instalado"
|
|
echo ""
|
|
|
|
# --- 4. Apache ---
|
|
info "4. Instalando Apache y configurando welcome.php..."
|
|
zypper --gpg-auto-import-keys -n install -y apache2 apache2-prefork >> "$LOG_FILE" 2>&1
|
|
# Configurar que la raíz y /vicidial apunten a welcome.php
|
|
cat > /etc/apache2/conf.d/vicidial-welcome.conf << 'APACHECONF'
|
|
# ViciDial: URL principal -> vicidial/welcome.php
|
|
<Directory "/srv/www/htdocs/vicidial">
|
|
DirectoryIndex welcome.php
|
|
Options None
|
|
<IfModule !mod_access_compat.c>
|
|
Require all granted
|
|
</IfModule>
|
|
</Directory>
|
|
RedirectMatch ^/$ /vicidial/welcome.php
|
|
APACHECONF
|
|
systemctl enable apache2 >> "$LOG_FILE" 2>&1
|
|
systemctl start apache2 >> "$LOG_FILE" 2>&1
|
|
info " Apache instalado y apuntando a /vicidial/welcome.php"
|
|
if command -v getenforce >/dev/null 2>&1 && [ "$(getenforce 2>/dev/null)" = "Enforcing" ]; then
|
|
setsebool -P httpd_can_network_connect_db 1 >> "$LOG_FILE" 2>&1 || true
|
|
setsebool -P httpd_can_network_connect 1 >> "$LOG_FILE" 2>&1 || true
|
|
info " SELinux: permitida conexión Apache→MariaDB (httpd_can_network_connect*)"
|
|
fi
|
|
for PHPINI in /etc/php8/apache2/php.ini /etc/php7/apache2/php.ini; do
|
|
if [ -f "$PHPINI" ]; then
|
|
sed -i 's/^;\?pcre\.jit=.*/pcre.jit=0/' "$PHPINI"
|
|
systemctl reload apache2 >> "$LOG_FILE" 2>&1 || true
|
|
break
|
|
fi
|
|
done
|
|
echo ""
|
|
|
|
# --- 4b. Asterisk (requerido por vicibox-install) ---
|
|
# OBS usa rutas: home:/vicidial:/asterisk-18
|
|
info "4b. Instalando Asterisk (repositorio VICIdial asterisk-18)..."
|
|
AST_REPO_FILE="home:vicidial:asterisk-18.repo"
|
|
AST_REPO_BASE="https://download.opensuse.org/repositories/home:/vicidial:/asterisk-18"
|
|
AST_OS_VER=""
|
|
[ -f /etc/os-release ] && AST_OS_VER=$(grep -E '^VERSION_ID=' /etc/os-release | cut -d'"' -f2)
|
|
AST_VERSIONS="$AST_OS_VER 16.0 15.6 15.5"
|
|
AST_REPO_ADDED=0
|
|
for AST_VER in $AST_VERSIONS; do
|
|
[ -z "$AST_VER" ] && continue
|
|
if zypper lr 2>/dev/null | grep -qiE 'vicidial|asterisk-18'; then
|
|
AST_REPO_ADDED=1
|
|
break
|
|
fi
|
|
REPO_URL="${AST_REPO_BASE}/${AST_VER}/${AST_REPO_FILE}"
|
|
info " Probando repositorio Asterisk (${AST_VER}): ${REPO_URL}"
|
|
if zypper --gpg-auto-import-keys -n addrepo --refresh "$REPO_URL" >> "$LOG_FILE" 2>&1; then
|
|
AST_REPO_ADDED=1
|
|
break
|
|
fi
|
|
done
|
|
if [ "$AST_REPO_ADDED" = "1" ]; then
|
|
info " Refrescando repositorios..."
|
|
zypper --gpg-auto-import-keys --no-gpg-checks -n refresh >> "$LOG_FILE" 2>&1
|
|
info " Instalando asterisk..."
|
|
if zypper --gpg-auto-import-keys -n install -y asterisk >> "$LOG_FILE" 2>&1; then
|
|
info " Habilitando e iniciando asterisk..."
|
|
systemctl enable asterisk >> "$LOG_FILE" 2>&1
|
|
systemctl start asterisk >> "$LOG_FILE" 2>&1 || true
|
|
info " Asterisk: $(asterisk -V 2>/dev/null || echo 'revisar servicio')"
|
|
else
|
|
warn " zypper no pudo instalar el paquete asterisk. Revisa install-vicibox.log"
|
|
fi
|
|
else
|
|
warn " No se pudo añadir el repo Asterisk. Manual (Leap 16.0):"
|
|
warn " zypper ar --refresh ${AST_REPO_BASE}/16.0/${AST_REPO_FILE}"
|
|
warn " zypper --gpg-auto-import-keys --no-gpg-checks ref && zypper in -y asterisk && systemctl enable --now asterisk"
|
|
fi
|
|
echo ""
|
|
|
|
# --- 5. Restore (scripts y código fuente) ---
|
|
info "5. Ejecutando restore.sh..."
|
|
cd "$SCRIPT_DIR"
|
|
./restore.sh >> "$LOG_FILE" 2>&1
|
|
echo ""
|
|
|
|
# --- 5b. Propietario Apache y SELinux RW (evita 500 en admin.php) ---
|
|
info "5b. Permisos web Vicidial (wwwrun + SELinux httpd_sys_rw_content_t)..."
|
|
if [ -d /srv/www/htdocs/vicidial ]; then
|
|
chown -R wwwrun:www /srv/www/htdocs/vicidial >> "$LOG_FILE" 2>&1
|
|
fi
|
|
if [ -d /srv/www/htdocs/agc ]; then
|
|
chown -R wwwrun:www /srv/www/htdocs/agc >> "$LOG_FILE" 2>&1
|
|
fi
|
|
if [ "$(getenforce 2>/dev/null)" = "Enforcing" ]; then
|
|
[ -d /srv/www/htdocs/vicidial ] && chcon -R -t httpd_sys_rw_content_t /srv/www/htdocs/vicidial >> "$LOG_FILE" 2>&1 || true
|
|
[ -d /srv/www/htdocs/agc ] && chcon -R -t httpd_sys_rw_content_t /srv/www/htdocs/agc >> "$LOG_FILE" 2>&1 || true
|
|
fi
|
|
info " Listo (escritura bajo /srv/www/htdocs/vicidial y agc)"
|
|
echo ""
|
|
|
|
# --- 6. Aplicar parches a vicibox-install.pl ---
|
|
info "6. Aplicando parches a vicibox-install.pl (socket MySQL, random_pass, etc.)..."
|
|
if [ -f "${SCRIPT_DIR}/patches/vicibox-install.pl" ]; then
|
|
cp "${SCRIPT_DIR}/patches/vicibox-install.pl" /usr/share/vicibox/vicibox-install.pl
|
|
chmod +x /usr/share/vicibox/vicibox-install.pl
|
|
info " Copiado vicibox-install.pl con parches desde patches/"
|
|
elif [ -f "${SCRIPT_DIR}/apply-vicibox-patches.sh" ]; then
|
|
"${SCRIPT_DIR}/apply-vicibox-patches.sh" >> "$LOG_FILE" 2>&1
|
|
info " Parches aplicados con apply-vicibox-patches.sh"
|
|
else
|
|
warn " No se encontró patches/vicibox-install.pl ni apply-vicibox-patches.sh."
|
|
warn " Se usará vicibox-install.pl sin parches (puede fallar socket MySQL/pwgen)."
|
|
fi
|
|
echo ""
|
|
|
|
# --- 7. Ejecutar instalación Express ---
|
|
info "7. Ejecutando vicibox-install --vicibox-express (confirmación automática 'y')..."
|
|
info " Esto puede tardar varios minutos..."
|
|
echo "y" | /usr/share/vicibox/vicibox-install.pl --vicibox-express >> "$LOG_FILE" 2>&1 || true
|
|
echo ""
|
|
|
|
# --- 8. Ajustar conexión web (127.0.0.1 para evitar error socket) ---
|
|
if [ -f /etc/astguiclient.conf ]; then
|
|
if grep -q 'VARDB_server => localhost' /etc/astguiclient.conf; then
|
|
sed -i 's/VARDB_server => localhost/VARDB_server => 127.0.0.1/' /etc/astguiclient.conf
|
|
info "8. Configuración: VARDB_server => 127.0.0.1 en /etc/astguiclient.conf (para la web)"
|
|
fi
|
|
else
|
|
info "8. /etc/astguiclient.conf no existe aún (normal si la instalación Express falló antes de crearlo)."
|
|
fi
|
|
echo ""
|
|
|
|
# --- 9. Crear usuario administrador sapian / sap64adm ---
|
|
info "9. Creando usuario administrador sapian en ViciDial..."
|
|
if [ -f "${SCRIPT_DIR}/create-admin-sapian.sh" ]; then
|
|
chmod +x "${SCRIPT_DIR}/create-admin-sapian.sh"
|
|
if "${SCRIPT_DIR}/create-admin-sapian.sh" >> "$LOG_FILE" 2>&1; then
|
|
info " Usuario administrador: sapian / sap64adm creado correctamente"
|
|
else
|
|
warn " No se pudo crear el usuario (¿base de datos ya instalada?). Puedes ejecutar después: sudo ${SCRIPT_DIR}/create-admin-sapian.sh"
|
|
fi
|
|
else
|
|
warn " No se encuentra create-admin-sapian.sh. Crear usuario sapian manualmente en admin.php si lo necesitas."
|
|
fi
|
|
echo ""
|
|
|
|
info "=========================================="
|
|
info "Proceso de instalación finalizado"
|
|
info "=========================================="
|
|
info "Log guardado en: $LOG_FILE"
|
|
info "Comprueba el estado de servicios: systemctl status mariadb apache2 asterisk"
|
|
info "Acceso web: http://<IP-del-servidor>/vicidial/welcome.php"
|
|
info "Admin ViciDial: usuario sapian, password sap64adm (admin.php)"
|
|
echo ""
|