#!/bin/bash ################################################################# # auto-mediawiki # # Instala un servidor LAMP (Linux+Apache+MySQL+PHP) e instala # # MediaWiki y lo configura. # # # # Guzman Castanedo Villalba (guzman@castanedo.es) Junio 2018 # # GPLv3 (https://www.gnu.org/licenses/gpl.html) # ################################################################# comprobarError() { # comprobarError exitNum codeNum extraInfo # 1xx: Servidor Web # 2xx: Base de Datos # 3xx: PHP # 4xx: SSL/TLS # 5xx: MediaWiki # 6xx: Moodle # 7xx: Actualizaciones automáticas # 8xx: Dependencias # 9xx: Servicios type="ERROR" exitNum=$1 codeNum=$2 extraInfo=$3 case $codeNum in 1) error="$type $codeNum:\tInstalación interrumpida por el usuario.\n" ;; 2) error="$type $codeNum:\tError interno (selección express).\n" ;; 3) error="$type $codeNum:\tError interno (selección avanzada).\n" ;; 100) error="$type $codeNum:\tError interno (selección del servidor web).\n" ;; 101) error="\n$type $codeNum:\tError al instalar Apache2.\nDetalles:\n$extraInfo\n" ;; 102) error="\n$type $codeNum:\tError al instalar Nginx.\nDetalles:\n$extraInfo\n" ;; 103) error="\n$type $codeNum:\tError al nstalar repositorio 'epel-release'.\nDetalles:\n$extraInfo\n" ;; 104) error="\n$type $codeNum:\tError interno (instalación Apache2).\n" ;; 105) error="\n$type $codeNum:\tError interno (instalación Nginx).\n" ;; 106) type="WARNING" error="\n$type $codeNum:\tImposible instalar 'info.php'.\n" ;; 200) error="$type $codeNum:\tError interno (selección de base de datos).\n" ;; 201) error="\n$type $codeNum:\tError al instalar MySQL.\nDetalles:\n$extraInfo\n" ;; 202) error="\n$type $codeNum:\tError al instalar MariaDB.\nDetalles:\n$extraInfo\n" ;; 203) error="\n$type $codeNum:\tError interno (instalación MySQL).\n" ;; 204) error="\n$type $codeNum:\tError interno (instalación MariaDB).\n" ;; 205) error="\n$type $codeNum:\t$DIST no incluye MySQL en sus repositorios.\n" ;; 206) type="WARNING" error="$type $codeNum:\tUsuario 'root' ya dispone de contraseña.\n" ;; 207) error="$type $codeNum:\tImposible cambiar la contraseña de 'root'.\n" ;; 208) error="$type $codeNum:\tImposible desactivar acceso 'root' desde el exterior.\n" ;; 209) error="$type $codeNum:\tImposible eliminar usuarios anónimos.\n" ;; 210) type="WARNING" error="$type $codeNum:\tImposible eliminar bases de datos de pruebas.\n" ;; 211) type="WARNING" error="$type $codeNum:\tImposible eliminar los permisos de las bases de datos de pruebas.\n" ;; 212) error="$type $codeNum:\tImposible recargar base de datos.\n" ;; 300) error="\n$type $codeNum:\tError interno (instalación PHP).\n" ;; 301) error="\n$type $codeNum:\tError interno (Web Server no seleccionado).\n" ;; 302) error="\n$type $codeNum:\tError al instalar PHP.\nDetalles:\n$extraInfo\n" ;; 303) error="\n$type $codeNum:\tError al instalar Repositorio Remi.\nDetalles:\n$extraInfo\n" ;; 304) error="\n$type $codeNum:\tSistema Operativo no compatible con PHP-7.2 ($OS $DIST $REV).\n" ;; 800) error="$type $codeNum:\tEs necesario ser root ('sudo $0').\n" ;; 801) error="$type $codeNum:\t'whiptail' no instalado.\n" ;; 802) error="$type $codeNum:\t'hostnamectl' no instalado.\n" ;; 803) error="$type $codeNum:\t'apt-get' no instalado.\n" ;; 804) error="$type $codeNum:\t'yum' no instalado.\n" ;; 805) error="\n$type $codeNum:\tImposible actualizar repositorio\nDetalles:\n$extraInfo.\n" ;; 806) error="$type $codeNum:\t'ufw' no instalado.\n" ;; 807) error="$type $codeNum:\t'firewall-cmd' no instalado.\n" ;; 808) error="$type $codeNum:\t'tput' no instalado.\n" ;; 900) error="$type $codeNum:\tError interno (habilitar servicio).\n" ;; 901) error="$type $codeNum:\tImposible encender servicio '$extraInfo'.\n" ;; 902) error="$type $codeNum:\tImposible habilitar servicio '$extraInfo' durante el arranque.\n" ;; 903) error="$type $codeNum:\tError interno (deshabilitar servicio).\n" ;; 904) error="$type $codeNum:\tImposible parar servicio '$extraInfo'.\n" ;; 905) error="$type $codeNum:\tImposible deshabilitar servicio '$extraInfo' durante el arranque.\n" ;; *) error="ERROR 13:\tError interno (comprobación de errores)\n" exitNum=1 codeNum=13 ;; esac if [ $exitNum -ne 0 ];then echo -en "$error" | tee -a $logFile if [ $type = "ERROR" ];then exit $codeNum fi fi unset error exitNum codeNum type } OSInfo() { echo -en "Detectando SO..." >> $logFile OS=$(uname -s) if [ $OS = "Linux" ]; then OS="GNU/Linux" if [ -f /etc/os-release ]; then DIST=$(grep ^NAME= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2) REV=$(grep ^VERSION= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2) ID_LIKE=$(grep ^ID_LIKE= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2) VERSION=$(grep ^VERSION_ID= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2) for i in $ID_LIKE; do #echo -en "$i\n" case $i in debian|ubuntu) debianOS=true break ;; rhel|fedora) rhelOS=true break ;; *) debianOS=false rhelOS=false ;; esac done elif [ -f /etc/debian-version ]; then # Familia Debian (Debian, Ubuntu, Linux Mint, ...) DIST="Debian" REV="" ID_LIKE="debian" VERSION="" debianOS=true elif [ -f /etc/redhat-release ]; then # Familia Red-Hat (RHEL, Fedora, CentOS, ...) DIST="Red-Hat" REV="" ID_LIKE="rhel" VERSION="" rhelOS=true else # Other Linux (No Soportado) DIST="" REV="" ID_LIKE="" VERSION="" fi else # UNIX, OS X, ... (No Soportado) DIST=$OS REV="" ID_LIKE="" VERSION="" fi echo -en " $OS $DIST $REV\n" >> $logFile HDInfo=$(df -h | head -1)"\n"$(df -h | grep ^/dev/sd)"\n"$(df -h | grep ^/dev/mapper) echo -en "$HDInfo\n" >> $logFile } comprobarRoot() { comprobarError $(id -u) 800 } comprobarDependencias() { # Comprobamos whiptail which whiptail > /dev/null 2>&1 comprobarError $? 801 # Comprobamos hostnamectl which hostnamectl > /dev/null 2>&1 comprobarError $? 802 # Comprobamos tput which tput > /dev/null 2>&1 comprobarError $? 808 if [ $debianOS = true ];then # Comprobamos apt-get which apt-get > /dev/null 2>&1 comprobarError $? 803 # Actualizamos base de datos del repositorio echo -en "Actualizando repositorio APT..." | tee -a $logFile result=$(apt-get -q -y update) comprobarError $? 805 $result echo -en " OK.\n" | tee -a $logFile # Comprobamos Firewall (ufw) which ufw > /dev/null 2>&1 comprobarError $? 806 fi if [ $rhelOS = true ]; then # Comprobamos yum which yum > /dev/null 2>&1 comprobarError $? 804 # Actualizamos base de datos del repositorio echo -en "Actualizando repositorio YUM..." | tee -a $logFile result=$(yum -y makecache 2>&1) comprobarError $? 805 $result echo -en " OK.\n" | tee -a $logFile # Comprobamos Firewall (firewall-cmd) which firewall-cmd > /dev/null 2>&1 comprobarError $? 807 fi } inicializarVariables() { debianOS=false rhelOS=false apacheOn=false nginxOn=false mySQLOn=false mariaDBOn=false phpOn=false mediaWikiOn=false moodleOn=false infoPHPOn=false actualizacionesOn=false progreso=0 progresoTotal=0 logFile="./."$(basename $0)".log" maxUpload="100M" } instalacionExpress() { apacheOn=true mariaDBOn=true phpOn=true mediaWikiOn=true moodleOn=true actualizacionesOn=true progresoTotal=15 # Preguntas mínimas establecerFQDN leerSQLPasswd } mostrarBienvenida() { ANCHO=$(tput cols) ALTO=$(tput lines) if [ $debianOS = false ] && [ $rhelOS = false ]; then whiptail --title "ERROR S.O. NO SOPORTADO" --msgbox "Este script automatiza la creación de una web MediaWiki SOLO para distribuciones Linux de la familia Debian (Ubuntu, Linux Mint, ...) y de la familia Red-Hat (CentOS, Fedora, ...).\n\nInformación del sistema:\nOS: $OS $DIST $REV\n$HDInfo" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Salir" exit 1 fi whiptail --title "INSTALACION MEDIAWIKI" --yesno "Este script automatiza completamente la instalación de una wiki.\nPara ello instala un servidor LAMP, el software MediaWiki y lo configura todo.\n\nInformación del sistema:\nOS: $OS $DIST $REV\n$HDInfo" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --yes-button "Continuar" --no-button "Salir" comprobarError $? 1 } mostrarExpress() { express=$(whiptail --title "INSTALACION EXPRESS" --radiolist ": seleccionar : cambiar : moverse\n\nLa instalación express instala Apache2, MariaDB, PHP-7, Let's Encrypt, MediaWiki, Moodle y actualizaciones automáticas.\nSeleccione el tipo de instalación que desee:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \ "Express" "Instalación rápida" ON \ "Avanzada" "Permite escoger todas las opciones disponibles" OFF \ --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3) comprobarError $? 1 case $express in Express) instalacionExpress # DECIDIR QUÉ OPCIONES SON LAS MÍNIMAS ;; Avanzada) mostrarAvanzada ;; *) comprobarError 1 2 ;; esac } mostrarAvanzada() { webServer=$(whiptail --title "INSTALACION AVANZADA" --radiolist ": seleccionar : cambiar : moverse\n\nEscoge el tipo de Servidor Web que quieres instalar:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \ "LAMP" "GNU/Linux + Apache + MySQL/MariaDB + PHP-7" ON \ "LEMP" "GNU/Linux + Nginx + MySQL/MariaDB + PHP-7" OFF \ --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3) comprobarError $? 1 for i in $webServer; do case $i in LAMP) apacheOn=true ;; LEMP) nginxOn=true ;; *) comprobarError 1 100 ;; esac done # Opciones comunes establecerFQDN mostrarDatabase phpOn=true establecerMaxUpload progresoTotal=$((progresoTotal + 6)) mostrarComponentes } mostrarComponentes() { componentes=$(whiptail --title "INSTALACION AVANZADA" --checklist ": seleccionar : cambiar : moverse\n\nEscoge los componentes que quieres instalar:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 5 \ "SSL/TLS" "Instalar certificados para activar HTTPS" ON \ "MediaWiki" "Instalar wiki con MediaWiki" ON \ "Moodle" "Instalar campus virtual con Moodle" ON \ "InfoPHP" "Instalar info.php (sólo para pruebas)" OFF \ "Actualizaciones" "Programar actualizaciones automáticas" ON \ --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3) comprobarError $? 1 # Mejora: autodetección de componentes ya instalados for i in $componentes; do case $i in \"SSL/TLS\") # 2 Opciones: Let's Encrypt o Autofirmado progresoTotal=$((progresoTotal + 2)) ;; \"MediaWiki\") mediaWikiOn=true progresoTotal=$((progresoTotal + 2)) ;; \"Moodle\") moodleOn=true progresoTotal=$((progresoTotal + 2)) ;; \"InfoPHP\") infoPHPOn=true progresoTotal=$((progresoTotal + 2)) ;; \"Actualizaciones\") actualizacionesOn=true progresoTotal=$((progresoTotal + 1)) ;; *) comprobarError 1 3 ;; esac done progresoTotal=$((progresoTotal + 2)) } establecerFQDN() { while [ -z $hostname ]; do hostname=$(whiptail --title "FQDN" --inputbox "El nombre de dominio principal (FQDN) de este servidor es:\n"$(hostname)"\n\nQuieres cambiarlo por otro?" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Cambiar" --cancel-button "No Cambiar" 3>&1 1>&2 2>&3) if [ $? -eq 0 ] && [ ! -z $hostname ]; then hostnamectl set-hostname $hostname else hostname=$(hostname) fi done echo -en "Hostname: $hostname\n" >> $logFile } instalarApache() { if [ $debianOS = true ];then result=$(apt-get -q -y install apache2 2>&1) comprobarError $? 101 $result elif [ $rhelOS = true ]; then result=$(yum -y install httpd 2>&1) comprobarError $? 101 $result else comprobarError 1 104 fi } instalarNginx() { if [ $debianOS = true ];then result=$(apt-get -q -y install nginx 2>&1) comprobarError $? 102 $result elif [ $rhelOS = true ]; then # Hay que instalar primero otro repositorio result=$(yum -y install epel-release) comprobarError $? 103 $result result=$(yum -y install nginx 2>&1) comprobarError $? 102 $result else comprobarError 1 105 fi } mostrarDatabase() { if [ $debianOS = true ]; then database=$(whiptail --title "BASE DE DATOS" --radiolist ": seleccionar : cambiar : moverse\n\nEscoge la base de datos que quieres usar:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \ "MySQL" "Instalar la base de datos MySQL (no uso comercial)" ON \ "MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" OFF \ --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3) comprobarError $? 1 case $database in MySQL) mySQLOn=true ;; MariaDB) mariaDBOn=true ;; *) comprobarError 1 200 ;; esac elif [ $rhelOS = true ]; then whiptail --title "BASE DE DATOS" --yesno "Para su distribucion $OS $DIST $REV, sólo está disponible la base de datos MariaDB." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --yes-button "Continuar" --no-button "Salir" comprobarError $? 1 mariaDBOn=true else comprobarError 1 200 fi # Otras opciones (contraseña) leerSQLPasswd } leerSQLPasswd() { control=false error="" # Leemos la contreseña (stdin) y confirmamos while [ $control = false ]; do sqlPasswd=$(whiptail --title "CONTRASEÑA SQL" --passwordbox "$error""Introduzca la contraseña para el usuario 'root' de la base de datos:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3) comprobarError $? 1 sqlPasswd2=$(whiptail --title "CONTRASEÑA SQL" --passwordbox "Confirme la contraseña:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3) comprobarError $? 1 #echo -en "SQL Password 1: $sqlPasswd\n" #echo -en "SQL Password 2: $sqlPasswd2\n" if [ -z $sqlPasswd ] || [ -z $sqlPasswd2 ]; then error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n" elif [ $sqlPasswd != $sqlPasswd2 ];then error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n" else control=true fi done #echo -en "SQL Password: $sqlPasswd\n" unset control error sqlPasswd2 } establecerSQLPasswd() { # Establecemos SQL root passwd y securizamos BD (mysql_secure_installation) # Comprobamos si ya tiene una contraseña asignada mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1 if [ $? -eq 0 ];then # Establecemos contraseña del usuario root mysql -e "UPDATE mysql.user SET Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1 comprobarError $? 207 # Desactivamos acceso root desde el exterior (solo localhost) mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" >> $logFile 2>&1 comprobarError $? 208 # Eliminamos todos los usuarios anónimos mysql -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1 comprobarError $? 209 # Eliminamos bases de datos 'test' mysql -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1 comprobarError $? 210 # Eliminamos privilegios de la base de datos 'test' mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1 comprobarError $? 211 # Aplicamos los cambios mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1 comprobarError $? 212 else comprobarError 1 206 fi } instalarMySQL() { if [ $debianOS = true ];then result=$(apt-get -q -y install mysql-server mysql-client 2>&1) comprobarError $? 201 $result elif [ $rhelOS = true ];then # MySQL no disponible en RHEL. 2 opciones: # 1) Instalar un repositorio adicional # 2) No instalar MySQL en distribuciones RHEL comprobarError 1 205 else comprobarError 1 203 fi } instalarMariaDB() { if [ $debianOS = true ];then result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1) comprobarError $? 202 $result elif [ $rhelOS = true ];then result=$(yum -y install mariadb-server mariadb 2>&1) comprobarError $? 202 $result else comprobarError 1 204 fi } instalarPHP() { # Instalamos PHP-7 de forma diferente si es junto a Apache o con Nginx if [ $debianOS = true ];then if [ $apacheOn = true ]; then result=$(apt-get -q -y install php libapache2-mod-php php-mysql php-intl php-mbstring openssl 2>&1) comprobarError $? 302 $result elif [ $nginxOn = true ];then result=$(apt-get -q -y install php-fpm libapache2-mod-php php-mysql php-intl php-mbstring openssl 2>&1) comprobarError $? 302 $result else comprobarError 1 301 fi elif [ $rhelOS = true ];then # Necesitamos un repositorio adicional para PHP-7 (EPEL-RELEASE) result=$(yum -y install epel-release yum-utils) comprobarError $? 103 $result # Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE) if [ $VERSION = "7" ];then result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-7.rpm 2>&1) comprobarError $? 303 $result elif [ $VERSION = "6" ];then result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-6.rpm 2>&1) comprobarError $? 303 $result elif [ $VERSION = "28" ];then result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-28.rpm 2>&1) comprobarError $? 303 $result elif [ $VERSION = "27" ];then result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-27.rpm 2>&1) comprobarError $? 303 $result else comprobarError 1 304 fi # Activamos repositorio remi-php72 result=$(yum-config-manager --enable remi-php72 2>&1) comprobarError $? 303 $result # Instalamos PHP-7.2 if [ $apacheOn = true ];then result=$(yum -y install php php-mysql php-intl php-mbstring php-mcrypt openssl 2>&1) comprobarError $? 302 $result elif [ $nginxOn = true ];then result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt openssl 2>&1) comprobarError $? 302 $result else comprobarError 1 301 fi else comprobarError 1 300 fi } establecerMaxUpload() { control=false error="" while [ $control = false ];do maxUpload2=$(whiptail --title "PHP MAX UPLOAD" --inputbox "$error""Introduzca el tamaño máximo permitido de los ficheros subidos al servidor:\n( )" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) $maxUpload --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3) comprobarError $? 1 if [ -z $maxUpload2 ];then error="ERROR: NO PUEDES DEJAR ESTE PARÁMETRO VACIO.\n" else control=true fi done maxUpload=$maxUpload2 unset control maxUpload2 } instalarPHPInfo() { infoFile="./var/www/info.php" if [ ! -f $infoFile ];then comprobarError 1 106 fi cp $infoFile /var/www/html/ 2>/dev/null comprobarError $? 106 unset infoFile } habilitarServicio() { # Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV) # Intentamos con systemctl (SystemD) echo -en "Habilitando servicio $1" | tee -a $logFile if [ $# -le 0 ];then comprobarError 1 900 fi which systemctl > /dev/null 2>&1 if [ $? -eq 0 ]; then echo -en " (SystemD)..." | tee -a $logFile systemctl start $1 > /dev/null 2>&1 comprobarError $? 901 $1 systemctl enable $1 > /dev/null 2>&1 comprobarError $? 902 $1 else # Intentamos con service (Upstart) which service > /dev/null 2>&1 if [ $? -eq 0 ]; then echo -en " (Upstart)..." | tee -a $logFile service $1 start > /dev/null 2>&1 comprobarError $? 901 $1 else # Intentamos con init.d (SystemV) echo -en " (SystemV)..." | tee -a $logFile /etc/init.d/$1 start > /dev/null 2>&1 comprobarError $? 901 $1 fi # Intentamos habilitar en el arranque (Upstart) which update-rc.d > /dev/null 2>&1 if [ $? -eq 0 ];then update-rc.d $1 enable comprobarError $? 902 $1 else # Intentamos habilitar en el arranque (SystemV) which chkconfig > /dev/null 2>&1 if [ $? -eq 0 ];then chkconfig $1 on comprobarError $? 902 $1 else # ¿Qué mas opciones nos quedan? comprobarError 1 902 $1 fi fi fi # Mejora: comprobar si el servicio está funcionando echo -en " OK.\n" | tee -a $logFile } deshabilitarServicio() { # Paramos y deshabilitamos el servicio (con SystemD, Upstart o SystemV) # Intentamos con systemctl (SystemD) echo -en "Deshabilitando servicio $1" | tee -a $logFile if [ $# -le 0 ];then comprobarError 1 903 fi which systemctl > /dev/null 2>&1 if [ $? -eq 0 ]; then echo -en " (SystemD)..." | tee -a $logFile systemctl stop $1 > /dev/null 2>&1 comprobarError $? 904 $1 systemctl disable $1 > /dev/null 2>&1 comprobarError $? 905 $1 else # Intentamos con service (Upstart) which service > /dev/null 2>&1 if [ $? -eq 0 ]; then echo -en " (Upstart)..." | tee -a $logFile service $1 stop > /dev/null 2>&1 comprobarError $? 904 $1 else # Intentamos con init.d (SystemV) echo -en " (SystemV)..." | tee -a $logFile /etc/init.d/$1 stop > /dev/null 2>&1 comprobarError $? 904 $1 fi # Intentamos habilitar en el arranque (Upstart) which update-rc.d > /dev/null 2>&1 if [ $? -eq 0 ];then update-rc.d $1 disable comprobarError $? 905 $1 else # Intentamos habilitar en el arranque (SystemV) which chkconfig > /dev/null 2>&1 if [ $? -eq 0 ];then chkconfig $1 off comprobarError $? 905 $1 else # ¿Qué mas opciones nos quedan? comprobarError 1 905 $1 fi fi fi # Mejora: comprobar si el servicio está funcionando echo -en " OK.\n" | tee -a $logFile } # Comprobación del sistema e inicialización inicializarVariables comprobarRoot OSInfo comprobarDependencias # Bienvenida mostrarBienvenida # Selección de componentes (express vs avanzada) mostrarExpress # Pre-configuración # Habilitar cortafuegos -> PROBLEMA: se corta la conexión ssh # Instalación # FALTA: whiptail --gauge -> Más bonito # Servidor Web if [ $apacheOn = true ]; then echo -en "Instalando Web Server Apache..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) instalarApache progreso=$((progreso + 1)) # } > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile elif [ $nginxOn = true ]; then echo -en "Instalando Web Server Nginx..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) instalarNginx progreso=$((progreso + 1)) # } > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile fi # Base de Datos if [ $mySQLOn = true ]; then echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) instalarMySQL progreso=$((progreso + 1)) # } > >(whiptail --gauge "Instalando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile elif [ $mariaDBOn = true ]; then echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) instalarMariaDB progreso=$((progreso + 1)) # } > >(whiptail --gauge "Instalando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile fi # PHP if [ $phpOn = true ]; then echo -en "Instalando PHP-7..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) instalarPHP progreso=$((progreso + 1)) # } > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile fi # SSL/TLS # Falta por implementar # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Instalando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) # MediaWiki if [ $mediaWikiOn = true ]; then echo -en "Instalando MediaWiki..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile fi # Moodle if [ $moodleOn = true ]; then echo -en "Instalando Moodle..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile fi # PRECAUCION!!!! Hay que habilitar algunos servicios antes de configurarlos # Por ejemplo: para cambiar la contraseña de root en mysql # Configuración # Configuración Apache # Virtual Hosts if [ $infoPHPOn = true ];then echo -en "Configurando 'info.php'..." | tee -a $logFile instalarPHPInfo echo -en " OK.\n" | tee -a $logFile fi echo -en "Configurando Servidor Web..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile # Configuración Database # Arrancar Base de Datos, establecer contraseña y configuración segura if [ $mySQLOn = true ];then habilitarServicio mysql echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) establecerSQLPasswd progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile fi if [ $mariaDBOn = true ];then habilitarServicio mariadb echo -en "Configurando Base de Datos MariaDB..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) establecerSQLPasswd progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile fi # Configuración PHP # cgi.fix_pathinfo=0 # Configurar máximo de subida de archivos echo -en "Configurando PHP-7..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile # Configuración MediWiki echo -en "Configurando MediaWiki..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile # Configuración Moodle echo -en "Configurando Moodle..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV) # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) if [ $apacheOn = true ];then if [ $debianOS = true ];then habilitarServicio apache2 elif [ $rhelOS = true ];then habilitarServicio httpd fi elif [ $nginxOn = true ];then habilitarServicio nginx if [ $phpOn = true ];then if [ $debianOS = true ];then habilitarServicio php7.2-fpm elif [ $rhelOS = true ];then habilitarServicio php-fpm fi fi fi progreso=$((progreso + 1)) # } > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) # Añadir reglas del cortafuegos echo -en "Configurando Cortafuegos..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile # Configuración SSL/TLS # Generar certificados # Configurar certificados echo -en "Configurando SSL/TLS..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile # Configurar actualizaciones if [ $actualizacionesOn = true ]; then echo -en "Configurando actualizaciones automáticas..." | tee -a $logFile # { # echo -en "%s\n" $((100 * progreso / progresoTotal)) sleep 2 progreso=$((progreso + 1)) # } > >(whiptail --gauge "Configurando actualizaciones automáticas..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal))) echo -en " OK.\n" | tee -a $logFile fi