| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794 | 
							- #!/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"
 
- 			;;
 
- 		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="$type $codeNum:\tError interno (instalación PHP).\n"
 
- 			;;
 
- 		301)
 
- 			error="$type $codeNum:\tError interno (Web Server no seleccionado).\n"
 
- 			;;
 
- 		302)
 
- 			error="$type $codeNum:\tError al instalar PHP.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		303)
 
- 			error="$type $codeNum:\tError al instalar Repositorio Remi.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		304)
 
- 			error="$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"
 
- 			;;
 
- 		*)
 
- 			error="ERROR 13:\tError interno (comprobación de errores)\n"
 
- 			exitNum=1
 
- 			codeNum=13
 
- 			;;
 
- 	esac
 
- 	if [ $exitNum -ne 0 ];then
 
- 		printf "$error"
 
- 		if [ $type = "ERROR" ];then
 
- 			exit $codeNum
 
- 		fi
 
- 	fi
 
- 	unset error exitNum codeNum type
 
- }
 
- OSInfo() {
 
- 	#printf "Detectando SO..."
 
- 	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
 
- 				#printf "$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
 
- 	#printf " $OS $DIST $REV\n"
 
- 	HDInfo=$(df -h | head -1)"\n"$(df -h | grep ^/dev/sd)"\n"$(df -h | grep ^/dev/mapper)
 
- }
 
- 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
 
- 		printf "Actualizando repositorio APT..."
 
- 		result=$(apt-get -q -y update)
 
- 		comprobarError $? 805 $result
 
- 		printf " OK.\n"
 
- 		# 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
 
- 		printf "Actualizando repositorio YUM..."
 
- 		result=$(yum -y makecache 2>&1)
 
- 		comprobarError $? 805 $result
 
- 		printf " OK.\n"
 
- 		# 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
 
- 	actualizacionesOn=false
 
- 	progreso=0
 
- 	progresoTotal=0
 
- }
 
- 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 "<ESPACIO>: seleccionar   <TAB>: cambiar   <FLECHAS>: 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() {
 
- 	componentes=$(whiptail --title "INSTALACION AVANZADA" --checklist "<ESPACIO>: seleccionar   <TAB>: cambiar   <FLECHAS>: moverse\n\nEscoge los componentes que quieres instalar:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 6 \
 
- 	"LAMP" "Linux + Apache + MySQL/MariaDB + PHP" ON \
 
- 	"LEMP" "Linux + Nginx + MySQL/MariaDB + PHP" ON \
 
- 	"SSL/TLS" "Instalar certificados para activar HTTPS" ON \
 
- 	"MediaWiki" "Instalar wiki con MediaWiki" ON \
 
- 	"Moodle" "Instalar campus virtual con Moodle" ON \
 
- 	"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
 
- 			\"LAMP\")
 
- 				apacheOn=true
 
- 				establecerFQDN
 
- 				mostrarDatabase
 
- 				phpOn=true
 
- 				progresoTotal=$((progresoTotal + 6))
 
- 				;;
 
- 			\"LEMP\")
 
- 				nginxOn=true
 
- 				establecerFQDN
 
- 				mostrarDatabase
 
- 				phpOn=true
 
- 				progresoTotal=$((progresoTotal + 6))
 
- 				;;
 
- 			\"SSL/TLS\")
 
- 				# 2 Opciones: Let's Encrypt o Autofirmado
 
- 				progresoTotal=$((progresoTotal + 2))
 
- 				;;
 
- 			\"MediaWiki\")
 
- 				mediaWikiOn=true
 
- 				progresoTotal=$((progresoTotal + 2))
 
- 				;;
 
- 			\"Moodle\")
 
- 				moodleOn=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
 
- 	#printf "\nHostname: $hostname\n"
 
- }
 
- 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 "<ESPACIO>: seleccionar   <TAB>: cambiar   <FLECHAS>: 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
 
- 		#printf "SQL Password 1: $sqlPasswd\n"
 
- 		#printf "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
 
- 	#printf "SQL Password: $sqlPasswd\n"
 
- 	unset control error sqlPasswd2
 
- }
 
- establecerSQLPasswd() {
 
- 	# Establecemos SQL root passwd y securizamos BD (mysql_secure_installation)
 
- 	# Mejora: ¿Si ya tiene una contraseña asignada?
 
- 	mysql -e "FLUSH PRIVILEGES" > /dev/null 2>&1
 
- 	if [ $? -eq 0 ];then
 
- 		# Establecemos contraseña del usuario root
 
- 		mysql -e "UPDATE mysql.user SET Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" > /dev/null 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')" > /dev/null 2>&1
 
- 		comprobarError $? 208
 
- 		# Eliminamos todos los usuarios anónimos
 
- 		mysql -e "DELETE FROM mysql.user WHERE User=''" > /dev/null 2>&1
 
- 		comprobarError $? 209
 
- 		# Eliminamos bases de datos 'test'
 
- 		mysql -e "DROP DATABASE IF EXISTS test" > /dev/null 2>&1
 
- 		comprobarError $? 210
 
- 		# Eliminamos privilegios de la base de datos 'test'
 
- 		mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" > /dev/null 2>&1
 
- 		comprobarError $? 211
 
- 		# Aplicamos los cambios
 
- 		mysql -e "FLUSH PRIVILEGES" > /dev/null 2>&1
 
- 		comprobarError $? 212
 
- 	else
 
- 		comprobarError $? 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 php-mcrypt 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 php-mcrypt 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)
 
- 		comprobarError $? 103 $result
 
- 		# Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE)
 
- 		if [ $VERSION = "7" ];then
 
- 			result=$(rpm -U http://rpms.famillecollet.com/enterprise/remi-release-7.rpm 2>&1)
 
- 			comprobarError $? 303 $result
 
- 		elif [ $VERSION = "6" ];then
 
- 			result=$(rpm -U http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 2>&1)
 
- 			comprobarError $? 303 $result
 
- 		else
 
- 			comprobarError 1 304
 
- 		fi
 
- 		# Instalamos PHP-7.2
 
- 		if [ $apacheOn = true ];then
 
- 			result=$(yum -y install php72 php72-php-pecl-mysql php72-php-intl php72-php-mbstring php72-php-pecl-mcrypt openssl 2>&1)
 
- 			comprobarError 1 302 $result
 
- 		elif [ $nginxOn = true ];then
 
- 			result=$(yum -y install php72 php72-php-fpm php72-php-pecl-mysql php72-php-intl php72-php-mbstring php72-php-pecl-mcrypt openssl 2>&1)
 
- 			comprobarError $? 302 $result
 
- 		else
 
- 			comprobarError 1 301
 
- 		fi
 
- 	else
 
- 		comprobarError 1 300
 
- 	fi
 
- }
 
- habilitarServicio() {
 
- 	# Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
 
- 	# Intentamos con systemctl (SystemD)
 
- 	printf "Habilitando servicio $1"
 
- 	if [ $# -le 0 ];then
 
- 		comprobarError 1 900
 
- 	fi
 
- 	which systemctl > /dev/null 2>&1
 
- 	if [ $? -eq 0 ]; then
 
- 		printf " (SystemD)..."
 
- 		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
 
- 			printf " (Upstart)..."
 
- 			service $1 start > /dev/null 2>&1
 
- 			comprobarError $? 901 $1
 
- 		else
 
- 			# Intentamos con init.d (SystemV)
 
- 			printf " (SystemV)..."
 
- 			/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
 
- 	printf " OK.\n"
 
- }
 
- # Comprobación del sistema e inicialización
 
- comprobarRoot
 
- inicializarVariables
 
- 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
 
- 		printf "Instalando Web Server Apache..."
 
- 		{
 
- 			printf "%s\n" $((100 * progreso / progresoTotal))
 
- 			instalarApache
 
- 			progreso=$((progreso + 1))
 
- 		} > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 		printf " OK.\n"
 
- 	elif [ $nginxOn = true ]; then
 
- 		printf "Instalando Web Server Nginx..."
 
- 		{
 
- 			printf "%s\n" $((100 * progreso / progresoTotal))
 
- 			instalarNginx
 
- 			progreso=$((progreso + 1))
 
- 		} > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 		printf " OK.\n"
 
- 	fi
 
- 	# Base de Datos
 
- 	if [ $mySQLOn = true ]; then
 
- 		printf "Instalando Base de Datos MySQL..."
 
- 		{
 
- 			printf "%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)))
 
- 		printf " OK.\n"
 
- 	elif [ $mariaDBOn = true ]; then
 
- 		printf "Instalando Base de Datos MariaDB..."
 
- 		{
 
- 			printf "%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)))
 
- 		printf " OK.\n"
 
- 	fi
 
- 	# PHP
 
- 	if [ $phpOn = true ]; then
 
- 		printf "Instalando PHP-7..."
 
- 		{
 
- 			printf "%s\n" $((100 * progreso / progresoTotal))
 
- 			instalarPHP
 
- 			progreso=$((progreso + 1))
 
- 		} > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 		printf " OK.\n"
 
- 	fi
 
- 	# SSL/TLS
 
- 		# Falta por implementar
 
- 		{
 
- 			printf "%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
 
- 		printf "Instalando MediaWiki..."
 
- 		{
 
- 			printf "%s\n" $((100 * progreso / progresoTotal))
 
- 			sleep 2
 
- 			progreso=$((progreso + 1))
 
- 		} > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 		printf " OK.\n"
 
- 	fi
 
- 	# Moodle
 
- 	if [ $moodleOn = true ]; then
 
- 		printf "Instalando Moodle..."
 
- 		{
 
- 			printf "%s\n" $((100 * progreso / progresoTotal))
 
- 			sleep 2
 
- 			progreso=$((progreso + 1))
 
- 		} > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 		printf " OK.\n"
 
- 	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
 
- 		printf "Configurando Servidor Web..."
 
- 		{
 
- 			printf "%s\n" $((100 * progreso / progresoTotal))
 
- 			sleep 2
 
- 			progreso=$((progreso + 1))
 
- 		} > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 		printf " OK.\n"
 
- 	# Configuración Database
 
- 		# Arrancar Base de Datos, establecer contraseña y configuración segura
 
- 		if [ $mySQLOn = true ];then
 
- 			printf "Configurando Base de Datos MySQL..."
 
- 			{
 
- 				printf "%s\n" $((100 * progreso / progresoTotal))
 
- 				habilitarServicio mysql
 
- 				establecerSQLPasswd
 
- 				progreso=$((progreso + 1))
 
- 			} > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 			printf " OK.\n"
 
- 		fi
 
- 		if [ $mariaDBOn = true ];then
 
- 			printf "Configurando Base de Datos MAriaDB..."
 
- 			{
 
- 				printf "%s\n" $((100 * progreso / progresoTotal))
 
- 				habilitarServicio mariadb
 
- 				establecerSQLPasswd
 
- 				progreso=$((progreso + 1))
 
- 			} > >(whiptail --gauge "Configurando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 			printf " OK.\n"
 
- 		fi
 
- 	# Configuración PHP
 
- 		# cgi.fix_pathinfo=0
 
- 		# Configurar máximo de subida de archivos
 
- 		printf "Configurando PHP-7..."
 
- 		{
 
- 			printf "%s\n" $((100 * progreso / progresoTotal))
 
- 			sleep 2
 
- 			progreso=$((progreso + 1))
 
- 		} > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 		printf " OK.\n"
 
- 	# Configuración MediWiki
 
- 	printf "Configurando MediaWiki..."
 
- 	{
 
- 		printf "%s\n" $((100 * progreso / progresoTotal))
 
- 		sleep 2
 
- 		progreso=$((progreso + 1))
 
- 	} > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 	printf " OK.\n"
 
- 	# Configuración Moodle
 
- 	printf "Configurando Moodle..."
 
- 	{
 
- 		printf "%s\n" $((100 * progreso / progresoTotal))
 
- 		sleep 2
 
- 		progreso=$((progreso + 1))
 
- 	} > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 	printf " OK.\n"
 
- 	# Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
 
- 	printf "Arrancando Servicios..."
 
- 	{
 
- 		printf "%s\n" $((100 * progreso / progresoTotal))
 
- 		sleep 2
 
- 		progreso=$((progreso + 1))
 
- 	} > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 	printf " OK.\n"
 
- 	# Añadir reglas del cortafuegos
 
- 	printf "Configurando Cortafuegos..."
 
- 	{
 
- 		printf "%s\n" $((100 * progreso / progresoTotal))
 
- 		sleep 2
 
- 		progreso=$((progreso + 1))
 
- 	} > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 	printf " OK.\n"
 
- 	# Configuración SSL/TLS
 
- 		# Generar certificados
 
- 		# Configurar certificados
 
- 		printf "Configurando SSL/TLS..."
 
- 		{
 
- 			printf "%s\n" $((100 * progreso / progresoTotal))
 
- 			sleep 2
 
- 			progreso=$((progreso + 1))
 
- 		} > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 
- 		printf " OK.\n"
 
- 	# Configurar actualizaciones
 
- 	if [ $actualizacionesOn = true ]; then
 
- 		printf "Configurando actualizaciones automáticas..."
 
- 		{
 
- 			printf "%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)))
 
- 		printf " OK.\n"
 
- 	fi
 
 
  |