|
@@ -197,6 +197,12 @@ comprobarError() {
|
|
|
911)
|
|
|
error="\n$type $codeNum:\tImposible activar Virtual Host '$extraInfo'.\n"
|
|
|
;;
|
|
|
+ 912)
|
|
|
+ error="\n$type $codeNum:\tError interno (recargar servicio).\n"
|
|
|
+ ;;
|
|
|
+ 913)
|
|
|
+ error="\n$type $codeNum:\tImposible recargar servicio '$extraInfo'.\n"
|
|
|
+ ;;
|
|
|
*)
|
|
|
error="ERROR 13:\tError interno (comprobación de errores)\n"
|
|
|
exitNum=1
|
|
@@ -334,6 +340,9 @@ inicializarVariables() {
|
|
|
progresoTotal=0
|
|
|
logFile="./."$(basename $0)".log"
|
|
|
maxUpload="100M"
|
|
|
+ webServerName=""
|
|
|
+ sqlServerName=""
|
|
|
+ phpFPMName=""
|
|
|
}
|
|
|
|
|
|
instalacionExpress() {
|
|
@@ -464,14 +473,17 @@ establecerFQDN() {
|
|
|
|
|
|
instalarApache() {
|
|
|
if [ $debianOS = true ];then
|
|
|
+ webServerName="apache2"
|
|
|
result=$(apt-get -q -y install apache2 2>&1)
|
|
|
comprobarError $? 101 $result
|
|
|
elif [ $rhelOS = true ]; then
|
|
|
+ webServerName="httpd"
|
|
|
result=$(yum -y install httpd 2>&1)
|
|
|
comprobarError $? 101 $result
|
|
|
else
|
|
|
comprobarError 1 104
|
|
|
fi
|
|
|
+ deshabilitarServicio $webServerName
|
|
|
}
|
|
|
|
|
|
configurarApache() {
|
|
@@ -492,6 +504,7 @@ configurarApache() {
|
|
|
}
|
|
|
|
|
|
instalarNginx() {
|
|
|
+ webServerName="nginx"
|
|
|
if [ $debianOS = true ];then
|
|
|
result=$(apt-get -q -y install nginx 2>&1)
|
|
|
comprobarError $? 102 $result
|
|
@@ -504,6 +517,7 @@ instalarNginx() {
|
|
|
else
|
|
|
comprobarError 1 105
|
|
|
fi
|
|
|
+ deshabilitarServicio $webServerName
|
|
|
}
|
|
|
|
|
|
configurarNginx() {
|
|
@@ -526,12 +540,12 @@ configurarNginx() {
|
|
|
|
|
|
instalarVirtualHost() {
|
|
|
# Configuramos un Virtual Host para Apache o Nginx
|
|
|
- # Uso: instalarVirtualHost $webServerRoot $virtualHost
|
|
|
- if [ $# -ne 2 ];then
|
|
|
+ # Uso: instalarVirtualHost $virtualHost
|
|
|
+ if [ $# -ne 1 ];then
|
|
|
comprobarError 1 908
|
|
|
fi
|
|
|
- webServerRoot=$(realpath $1)
|
|
|
- virtualHost=$(realpath $2)
|
|
|
+ webServerRoot=$(realpath "/etc/$webServerName/")
|
|
|
+ virtualHost=$(realpath $1)
|
|
|
virtualHostName=$(basename $virtualHost)
|
|
|
if [ ! -f $virtualHost ];then
|
|
|
comprobarError 1 909 $virtualHostName
|
|
@@ -548,6 +562,7 @@ instalarVirtualHost() {
|
|
|
comprobarError $? 910
|
|
|
ln -s "$webServerRoot/sites-available/$virtualHostName" "$webServerRoot/sites-enabled/$virtualHostName" >> $logFile 2>&1
|
|
|
comprobarError $? 911 $virtualHostName
|
|
|
+ recargarServicio $webServerName
|
|
|
unset webServerRoot virtualHost virtualHostName
|
|
|
}
|
|
|
|
|
@@ -632,6 +647,7 @@ establecerSQLPasswd() {
|
|
|
}
|
|
|
|
|
|
instalarMySQL() {
|
|
|
+ sqlServerName="mysql"
|
|
|
if [ $debianOS = true ];then
|
|
|
result=$(apt-get -q -y install mysql-server mysql-client 2>&1)
|
|
|
comprobarError $? 201 $result
|
|
@@ -646,6 +662,7 @@ instalarMySQL() {
|
|
|
}
|
|
|
|
|
|
instalarMariaDB() {
|
|
|
+ sqlServerName="mariadb"
|
|
|
if [ $debianOS = true ];then
|
|
|
result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1)
|
|
|
comprobarError $? 202 $result
|
|
@@ -660,6 +677,7 @@ instalarMariaDB() {
|
|
|
instalarPHP() {
|
|
|
# Instalamos PHP-7 de forma diferente si es junto a Apache o con Nginx
|
|
|
if [ $debianOS = true ];then
|
|
|
+ phpFPMName="php7.2-fpm"
|
|
|
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
|
|
@@ -670,6 +688,7 @@ instalarPHP() {
|
|
|
comprobarError 1 301
|
|
|
fi
|
|
|
elif [ $rhelOS = true ];then
|
|
|
+ phpFPMName="php-fpm"
|
|
|
# Necesitamos un repositorio adicional para PHP-7 (EPEL-RELEASE)
|
|
|
result=$(yum -y install epel-release yum-utils 2>&1)
|
|
|
comprobarError $? 103 $result
|
|
@@ -707,6 +726,7 @@ instalarPHP() {
|
|
|
else
|
|
|
comprobarError 1 300
|
|
|
fi
|
|
|
+ deshabilitarServicio $phpFPMName
|
|
|
}
|
|
|
|
|
|
configurarPHP() {
|
|
@@ -772,36 +792,25 @@ instalarPHPInfo() {
|
|
|
comprobarError $? 106
|
|
|
unset infoFile
|
|
|
# Instalar VirtualHost
|
|
|
- if [ $apacheOn = true ];then
|
|
|
- if [ $debianOS = true ];then
|
|
|
- webServerRoot="/etc/apache2/"
|
|
|
- virtualHost="./etc/apache-debian/sites-available/phpinfo.conf"
|
|
|
- elif [ $rhelOS = true ];then
|
|
|
- webServerRoot="/etc/httpd/"
|
|
|
- virtualHost="./etc/apache-rhel/sites-available/phpinfo.conf"
|
|
|
- fi
|
|
|
- elif [ $nginxOn = true ];then
|
|
|
- webServerRoot="/etc/nginx/"
|
|
|
- if [ $debianOS = true ];then
|
|
|
- virtualHost="./etc/nginx-debian/sites-available/phpinfo.conf"
|
|
|
- elif [ $rhelOS = true ];then
|
|
|
- virtualHost="./etc/nginx-rhel/sites-available/phpinfo.conf"
|
|
|
- fi
|
|
|
+ if [ $debianOS = true ];then
|
|
|
+ virtualHost="./etc/$webServerName-debian/sites-available/phpinfo.conf"
|
|
|
+ elif [ $rhelOS = true ];then
|
|
|
+ virtualHost="./etc/$webServerName-rhel/sites-available/phpinfo.conf"
|
|
|
fi
|
|
|
- instalarVirtualHost $webServerRoot $virtualHost
|
|
|
- unset webServerRoot virtualHost
|
|
|
+ instalarVirtualHost $virtualHost
|
|
|
+ unset virtualHost
|
|
|
}
|
|
|
|
|
|
habilitarServicio() {
|
|
|
# Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
|
|
|
# Intentamos con systemctl (SystemD)
|
|
|
- echo -en "Habilitando Servicio '$1'" | tee -a $logFile
|
|
|
+ #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
|
|
|
+ #echo -en " (SystemD)..." | tee -a $logFile
|
|
|
systemctl start $1 > /dev/null 2>&1
|
|
|
comprobarError $? 901 $1
|
|
|
systemctl enable $1 > /dev/null 2>&1
|
|
@@ -810,12 +819,12 @@ habilitarServicio() {
|
|
|
# Intentamos con service (Upstart)
|
|
|
which service > /dev/null 2>&1
|
|
|
if [ $? -eq 0 ]; then
|
|
|
- echo -en " (Upstart)..." | tee -a $logFile
|
|
|
+ #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
|
|
|
+ #echo -en " (SystemV)..." | tee -a $logFile
|
|
|
/etc/init.d/$1 start > /dev/null 2>&1
|
|
|
comprobarError $? 901 $1
|
|
|
fi
|
|
@@ -836,8 +845,8 @@ habilitarServicio() {
|
|
|
fi
|
|
|
fi
|
|
|
fi
|
|
|
- # Mejora: comprobar si el servicio está funcionando
|
|
|
- echo -en " OK.\n" | tee -a $logFile
|
|
|
+ # Mejora: comprobar si el servicio está parado
|
|
|
+ #echo -en " OK.\n" | tee -a $logFile
|
|
|
}
|
|
|
|
|
|
deshabilitarServicio() {
|
|
@@ -888,6 +897,36 @@ deshabilitarServicio() {
|
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
|
}
|
|
|
|
|
|
+recargarServicio() {
|
|
|
+ # Recargamos el servicio (con SystemD, Upstart o SystemV)
|
|
|
+ # Intentamos con systemctl (SystemD)
|
|
|
+ #echo -en "Recargando Servicio '$1'" | tee -a $logFile
|
|
|
+ if [ $# -le 0 ];then
|
|
|
+ comprobarError 1 912
|
|
|
+ fi
|
|
|
+ which systemctl > /dev/null 2>&1
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ #echo -en " (SystemD)..." | tee -a $logFile
|
|
|
+ systemctl reload $1 > /dev/null 2>&1
|
|
|
+ comprobarError $? 913 $1
|
|
|
+ else
|
|
|
+ # Intentamos con service (Upstart)
|
|
|
+ which service > /dev/null 2>&1
|
|
|
+ if [ $? -eq 0 ]; then
|
|
|
+ #echo -en " (Upstart)..." | tee -a $logFile
|
|
|
+ service $1 reload > /dev/null 2>&1
|
|
|
+ comprobarError $? 913 $1
|
|
|
+ else
|
|
|
+ # Intentamos con init.d (SystemV)
|
|
|
+ #echo -en " (SystemV)..." | tee -a $logFile
|
|
|
+ /etc/init.d/$1 reload > /dev/null 2>&1
|
|
|
+ comprobarError $? 913 $1
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+ # Mejora: comprobar si el servicio está funcionando
|
|
|
+ #echo -en " OK.\n" | tee -a $logFile
|
|
|
+}
|
|
|
+
|
|
|
configurarCortafuegos() {
|
|
|
# Configuramos cortafuegos (añadir reglas y encender)
|
|
|
# Comprobamos si estamos usando SSH
|
|
@@ -1019,8 +1058,8 @@ mostrarExpress
|
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
|
fi
|
|
|
# Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
|
|
|
- if [ $mySQLOn = true ];then
|
|
|
- habilitarServicio mysql
|
|
|
+ if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
|
|
|
+ habilitarServicio "sqlServerName"
|
|
|
echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile
|
|
|
# {
|
|
|
# echo -en "%s\n" $((100 * progreso / progresoTotal))
|
|
@@ -1028,15 +1067,6 @@ mostrarExpress
|
|
|
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
|
|
|
- elif [ $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 y Configurar máximo de subida de archivos)
|
|
|
if [ $phpOn = true ];then
|
|
@@ -1109,19 +1139,11 @@ mostrarExpress
|
|
|
# {
|
|
|
# echo -en "%s\n" $((100 * progreso / progresoTotal))
|
|
|
if [ $apacheOn = true ];then
|
|
|
- if [ $debianOS = true ];then
|
|
|
- habilitarServicio apache2
|
|
|
- elif [ $rhelOS = true ];then
|
|
|
- habilitarServicio httpd
|
|
|
- fi
|
|
|
+ habilitarServicio $webServerName
|
|
|
elif [ $nginxOn = true ];then
|
|
|
- habilitarServicio nginx
|
|
|
+ habilitarServicio $webServerName
|
|
|
if [ $phpOn = true ];then
|
|
|
- if [ $debianOS = true ];then
|
|
|
- habilitarServicio php7.2-fpm
|
|
|
- elif [ $rhelOS = true ];then
|
|
|
- habilitarServicio php-fpm
|
|
|
- fi
|
|
|
+ habilitarServicio $phpFPMName
|
|
|
fi
|
|
|
fi
|
|
|
progreso=$((progreso + 1))
|