| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870 | 
							- #!/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() {
 
- # Permite comprobar si se ha producido un error y de serlo devuelve un código de error
 
- # comprobarError exitNum codeNum extraInfo
 
- #	1xx: Servidor Web
 
- #	2xx: Base de Datos
 
- #	3xx: PHP
 
- #	4xx: SSL/TLS
 
- #	5xx: MediaWiki
 
- #	6xx: Moodle
 
- #	7xx: Backup automático
 
- #	8xx: Dependencias
 
- #	9xx: Servicios & Firewall
 
- 	
 
- 	type="ERROR"
 
- 	exitNum=$1
 
- 	shift
 
- 	codeNum=$1
 
- 	shift
 
- 	extraInfo=$@
 
- 	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"
 
- 			;;
 
- 		4)
 
- 			error="\n$type $codeNum:\tEl archivo '"$(realpath $extraInfo)"' no existe.\n"
 
- 			;;
 
- 		5)
 
- 			error="\n$type $codeNum:\tEl directorio '"$(realpath $extraInfo)"' no existe.\n"
 
- 			;;
 
- 		6)
 
- 			error="$type $codeNum:\tError interno (selección SSL/TLS).\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"
 
- 			;;
 
- 		107)
 
- 			error="\n$type $codeNum:\tError al configurar Nginx.\n"
 
- 			;;
 
- 		108)
 
- 			error="\n$type $codeNum:\tError al configurar Apache2.\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="\n$type $codeNum:\tUsuario 'root' ya dispone de contraseña."
 
- 			;;
 
- 		207)
 
- 			error="\n$type $codeNum:\tImposible cambiar la contraseña de 'root'."
 
- 			;;
 
- 		208)
 
- 			error="\n$type $codeNum:\tImposible desactivar acceso 'root' desde el exterior."
 
- 			;;
 
- 		209)
 
- 			error="\n$type $codeNum:\tImposible eliminar usuarios anónimos."
 
- 			;;
 
- 		210)
 
- 			type="WARNING"
 
- 			error="\n$type $codeNum:\tImposible eliminar bases de datos de pruebas."
 
- 			;;
 
- 		211)
 
- 			type="WARNING"
 
- 			error="\n$type $codeNum:\tImposible eliminar los permisos de las bases de datos de pruebas."
 
- 			;;
 
- 		212)
 
- 			error="\n$type $codeNum:\tImposible recargar base de datos."
 
- 			;;
 
- 		213)
 
- 			error="\n$type $codeNum:\tImposible configurar SQL.\n"
 
- 			;;
 
- 		214)
 
- 			type="WARNING"
 
- 			error="\n$type $codeNum:\tSQL ya está configurado."
 
- 			;;
 
- 		300)
 
- 			error="\n$type $codeNum:\tError interno (instalación PHP-7.2).\n"
 
- 			;;
 
- 		301)
 
- 			error="\n$type $codeNum:\tError interno (Web Server no seleccionado).\n"
 
- 			;;
 
- 		302)
 
- 			error="\n$type $codeNum:\tError al instalar PHP-7.2.\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"
 
- 			;;
 
- 		305)
 
- 			error="\n$type $codeNum:\tImposible configurar PHP-7.2.\n"
 
- 			;;
 
- 		401)
 
- 			error="\n$type $codeNum:\tError al instalar 'certbot' (Let's Encrypt).\n"
 
- 			;;
 
- 		402)
 
- 			error="\n$type $codeNum:\tImposible generar Certificados Autofirmados.\n"
 
- 			;;
 
- 		403)
 
- 			error="\n$type $codeNum:\tImposible generar claves de intercambio Diffie-Hellman.\n"
 
- 			;;
 
- 		501)
 
- 			error="\n$type $codeNum:\tImposible descargar MediaWiki-1.31.0.\n"
 
- 			;;
 
- 		502)
 
- 			error="\n$type $codeNum:\tImposible configurar MediaWiki-1.31.0.\n"
 
- 			;;
 
- 		503)
 
- 			type="WARNING"
 
- 			error="\n$type $codeNum:\tYa existe una copia configurada de MediaWiki en el dominio: '$extraInfo'."
 
- 			;;
 
- 		601)
 
- 			error="\n$type $codeNum:\tImposible descargar Moodle-3.5.1.\n"
 
- 			;;
 
- 		602)
 
- 			error="\n$type $codeNum:\tImposible configurar Moodle-3.5.1.\n"
 
- 			;;
 
- 		603)
 
- 			type="WARNING"
 
- 			error="\n$type $codeNum:\tYa existe una copia configurada de Moodle en el dominio: '$extraInfo'."
 
- 			;;
 
- 		604)
 
- 			error="\n$type $codeNum:\tImposible configurar SELinux.\n"
 
- 			;;
 
- 		605)
 
- 			error="\n$type $codeNum:\tImposible instalar 'policycoreutils-python'.Detalles:\n$extraInfo\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.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		809)
 
- 			error="$type $codeNum:\t'sed' no instalado.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		810)
 
- 			error="$type $codeNum:\t'curl' no instalado.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		811)
 
- 			error="$type $codeNum:\t'tar' no instalado.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		812)
 
- 			error="$type $codeNum:\t'gzip' no instalado.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		813)
 
- 			error="$type $codeNum:\t'bzip2' no instalado.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		814)
 
- 			error="$type $codeNum:\t'xz' no instalado.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		815)
 
- 			error="$type $codeNum:\t'openssl' no instalado.\nDetalles:\n$extraInfo\n"
 
- 			;;
 
- 		816)
 
- 			error="$type $codeNum:\t'find' 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"
 
- 			;;
 
- 		906)
 
- 			type="WARNING"
 
- 			error="\n$type $codeNum:\tImposible añadir regla al cortafuegos ('$extraInfo').\n"
 
- 			;;
 
- 		907)
 
- 			type="WARNING"
 
- 			error="\n$type $codeNum:\tImposible encender cortafuegos.\n"
 
- 			;;
 
- 		908)
 
- 			error="\n$type $codeNum:\tError interno (instalar Virtual Host).\n"
 
- 			;;
 
- 		909)
 
- 			error="\n$type $codeNum:\tVirtual Host '$extraInfo' no existe.\n"
 
- 			;;
 
- 		910)
 
- 			error="\n$type $codeNum:\tImposible copiar Virtual Host '$extraInfo'.\n"
 
- 			;;
 
- 		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
 
- 			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() {
 
- # Detecta el OS en el que se está ejecutando el programa, así como su versión
 
- 	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() {
 
- # Comprueba si se está ejecutando con privilegios de root
 
- 	comprobarError $(id -u) 800
 
- }
 
- comprobarDependencias() {
 
- # Comprueba si están instalados todos los programas necesarios.
 
- # En la mayoría de los casos, trata de instalarlos.
 
- 	# Comprobamos whiptail
 
- 	which whiptail > /dev/null 2>&1
 
- 	comprobarError $? 801
 
- 	# Comprobamos hostnamectl
 
- 	which hostnamectl > /dev/null 2>&1
 
- 	comprobarError $? 802
 
- 	which find > /dev/null 2>&1
 
- 	comprobarError $? 816
 
- 	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 2>&1)
 
- 		comprobarError $? 805 $result
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 		# Comprobamos Firewall (ufw)
 
- 		which ufw > /dev/null 2>&1
 
- 		comprobarError $? 806
 
- 		# Comprobamos tput
 
- 		which tput > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(apt-get -q -y ncurses-bin 2>&1)
 
- 			comprobarError $? 808 $result
 
- 		fi
 
- 		# Comprobar sed
 
- 		which sed > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(apt-get -q -y sed 2>&1)
 
- 			comprobarError $? 809 $result
 
- 		fi
 
- 		# Comprobar curl
 
- 		which curl > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(apt-get -q -y curl 2>&1)
 
- 			comprobarError $? 810 $result
 
- 		fi
 
- 		# Comprobamos tar, gzip, bzip2 y xz
 
- 		which tar > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(apt-get -q -y install tar 2>&1)
 
- 			comprobarError $? 811 $result
 
- 		fi
 
- 		which gzip > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(apt-get -q -y install gzip 2>&1)
 
- 			comprobarError $? 812 $result
 
- 		fi
 
- 		which bzip2 > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(apt-get -q -y install bzip2 2>&1)
 
- 			comprobarError $? 813 $result
 
- 		fi
 
- 		which xz > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(apt-get -q -y install xz-utils 2>&1)
 
- 			comprobarError $? 814 $result
 
- 		fi
 
- 		which openssl > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(apt-get -q -y install openssl 2>&1)
 
- 			comprobarError $? 815 $result
 
- 		fi
 
- 	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
 
- 		# Comprobamos tput
 
- 		which tput > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(yum -y ncurses 2>&1)
 
- 			comprobarError $? 808 $result
 
- 		fi
 
- 		# Comprobar sed
 
- 		which sed > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(yum -y sed 2>&1)
 
- 			comprobarError $? 809 $result
 
- 		fi
 
- 		# Comprobar curl
 
- 		which curl > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(yum -y curl 2>&1)
 
- 			comprobarError $? 810 $result
 
- 		fi
 
- 		# Comprobamos tar, gzip, bzip2 y xz
 
- 		which tar > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(yum -y install tar 2>&1)
 
- 			comprobarError $? 811 $result
 
- 		fi
 
- 		which gzip > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(yum -y install gzip 2>&1)
 
- 			comprobarError $? 812 $result
 
- 		fi
 
- 		which bzip2 > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(yum -y install bzip2 2>&1)
 
- 			comprobarError $? 813 $result
 
- 		fi
 
- 		which xz > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(yum -y install xz 2>&1)
 
- 			comprobarError $? 814 $result
 
- 		fi
 
- 		which openssl > /dev/null 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			result=$(yum -y install openssl 2>&1)
 
- 			comprobarError $? 815 $result
 
- 		fi
 
- 	fi
 
- }
 
- inicializarVariables() {
 
- # Inicializa las variables que necesitan de un estado previo
 
- 	debianOS=false
 
- 	rhelOS=false
 
- 	apacheOn=false
 
- 	nginxOn=false
 
- 	mySQLOn=false
 
- 	mariaDBOn=false
 
- 	phpOn=false
 
- 	sslOn=false
 
- 	letsEncryptOn=false
 
- 	mediaWikiOn=false
 
- 	moodleOn=false
 
- 	infoPHPOn=false
 
- 	backupOn=false
 
- 	hostname=""
 
- 	logFile="./."$(basename $0)".log"
 
- 	maxUpload="100M"
 
- 	webServerName=""
 
- 	webServerUser=""
 
- 	webServerGroup=""
 
- 	sqlServerName=""
 
- 	phpFPMName=""
 
- 	nombreMediaWiki=""
 
- 	dominioMediaWiki=""
 
- 	passwdMediaWiki=""
 
- 	nombreMoodle=""
 
- 	nombreCortoMoodle=""
 
- 	dominioMoodle=""
 
- 	passwdMoodle=""
 
- }
 
- instalacionExpress() {
 
- # Permite una instalación rápida, haciendo el menor número de preguntas
 
- 	apacheOn=true
 
- 	mariaDBOn=true
 
- 	phpOn=true
 
- 	sslOn=true
 
- 	letsEncryptOn=true
 
- 	mediaWikiOn=true
 
- 	moodleOn=true
 
- 	backupOn=true
 
- 	# Preguntas mínimas
 
- 	establecerFQDN
 
- 	leerSQLPasswd
 
- 	mostrarMediaWiki
 
- 	mostrarMoodle
 
- }
 
- mostrarBienvenida() {
 
- # Pantalla de bienvenida y muestra SO y estado de los discos
 
- 	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 y un CAMPUS VIRTUAL.\nPara ello instala un servidor LAMP, el software MediaWiki y configura todo lo necesario.\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() {
 
- # Pantalla de elección entre instalación express o avanzada
 
- 	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 backups automático.\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
 
- 	unset express
 
- }
 
- mostrarAvanzada() {
 
- # Pantalla que permite instalar un servidor LAMP o LEMP
 
- 	webServer=$(whiptail --title "INSTALACION AVANZADA" --radiolist "<ESPACIO>: seleccionar   <TAB>: cambiar   <FLECHAS>: 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
 
- 	mostrarComponentes
 
- 	mostrarConfirmacion
 
- 	unset webServer
 
- }
 
- mostrarComponentes() {
 
- # Pantalla de elección de componentes (SSL/TLS, MediaWiki, Moodle, InfoPHP y Backup)
 
- 	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)) 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 \
 
- 	"Backup" "Programar backups automáticos" 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
 
- 				mostrarSSL
 
- 				;;
 
- 			\"MediaWiki\")
 
- 				mediaWikiOn=true
 
- 				mostrarMediaWiki
 
- 				;;
 
- 			\"Moodle\")
 
- 				moodleOn=true
 
- 				mostrarMoodle
 
- 				;;
 
- 			\"InfoPHP\")
 
- 				infoPHPOn=true
 
- 				;;
 
- 			\"Backup\")
 
- 				BackupOn=true
 
- 				;;
 
- 			*)
 
- 				comprobarError 1 3
 
- 				;;
 
- 		esac
 
- 	done
 
- 	unset componentes
 
- }
 
- mostrarSSL() {
 
- # Pantalla que permite seleccionar el tipo de certificados
 
- 	ssl=$(whiptail --title "INSTALACION SSL/TLS" --radiolist "<ESPACIO>: seleccionar   <TAB>: cambiar   <FLECHAS>: moverse\n\nEscoge el tipo de Certificado SSL/TLS que quieres instalar:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \
 
- 	"LetsEncrypt" "Compatible con todos los navegadores" ON \
 
- 	"Auto-Firmado" "Certificados auto-firmados (sólo para pruebas)" OFF \
 
- 	--ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
 
- 	comprobarError $? 1
 
- 	for i in $ssl; do
 
- 		case $i in
 
- 			LetsEncrypt)
 
- 				sslOn=true
 
- 				letsEncryptOn=true
 
- 				;;
 
- 			Auto-Firmado)
 
- 				sslOn=true
 
- 				;;
 
- 			*)
 
- 				comprobarError 1 6
 
- 				;;
 
- 		esac
 
- 	done
 
- 	unset ssl
 
- }
 
- mostrarMediaWiki(){
 
- # Pantalla que pregunta sobre las opciones necesarias para configurar MediaWiki
 
- 	# Introducir nombre wiki
 
- 	while [ -z "$nombreMediaWiki" ]; do
 
- 		nombreMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --inputbox "Introduzca el nombre de la Wiki:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 	done
 
- 	# Introducir dominio
 
- 	while [ -z "$dominioMediaWiki" ]; do
 
- 		dominioMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --inputbox "Introduzca el dominio/subdominio de la Wiki.\nTenga en cuenta que debes apuntar este dominio a la dirección IP de esta máquina mediante un registro DNS de tipo CNAME.\nSi quiere introducir varios dominios sepárelos con espacios. El primero será el principal.\nPor ejemplo: 'www.$hostname $hostname wiki.$hostname'" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) wiki.$hostname --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 	done
 
- 	cont=1
 
- 	serverName=""
 
- 	aliasMediaWiki=""
 
- 	for dominio in $dominioMediaWiki;do
 
- 		if [ $cont -eq 1 ];then
 
- 			# Dominio Principal (ServerName)
 
- 			serverName=$dominio
 
- 		else
 
- 			# Dominios Secundarios (ServerAlias)
 
- 			aliasMediaWiki=$aliasMediaWiki" "$dominio
 
- 		fi
 
- 		cont=$((cont + 1))
 
- 	done
 
- 	dominioMediaWiki=$serverName
 
- 	# Introducir contraseña
 
- 	control=false
 
- 	error=""
 
- 	while [ $control = false ]; do
 
- 		passwdMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --passwordbox "$error""Introduzca la contraseña para el usuario administrador 'admin':" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 		passwdMediaWiki2=$(whiptail --title "CONFIGURACION MEDIAWIKI" --passwordbox "Confirme la contraseña:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 		if [ -z "$passwdMediaWiki" ] || [ -z "$passwdMediaWiki2" ]; then
 
- 			error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
 
- 		elif [ $passwdMediaWiki != $passwdMediaWiki2 ];then
 
- 			error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
 
- 		else
 
- 			control=true
 
- 		fi
 
- 	done
 
- 	unset control error passwdMediaWiki2 dominio cont serverName
 
- }
 
- mostrarMoodle() {
 
- # Pantalla que pregunta sobre las opciones necesarias para configurar Moodle
 
- 	# Introducir Nombre Moodle
 
- 	while [ -z "$nombreMoodle" ]; do
 
- 		nombreMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el NOMBRE COMPLETO del campus virtual.\nPor ejemplo: 'Campus Virtual Ejemplo'." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 	done
 
- 	# Introducir Nombre Corto Moodle
 
- 	while [ -z "$nombreCortoMoodle" ]; do
 
- 		nombreCortoMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el NOMBRE CORTO del campus virtual.\nPor ejemplo: 'Ejemplo'." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 	done
 
- 	nombreCortoMoodle=$(echo $nombreCortoMoodle | cut -d ' ' -f 1)
 
- 	# Introducir dominio
 
- 	while [ -z "$dominioMoodle" ]; do
 
- 		dominioMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el dominio/subdominio del campus virtual.\nMoodle SÓLO permite un ÚNICO DOMINIO." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) moodle.$hostname --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 	done
 
- 	cont=1
 
- 	serverName=""
 
- 	aliasMoodle=""
 
- 	for dominio in $dominioMoodle;do
 
- 		if [ $cont -eq 1 ];then
 
- 			# Dominio Principal (ServerName)
 
- 			serverName=$dominio
 
- 		else
 
- 			# Dominios Secundarios (ServerAlias)
 
- 			aliasMeoodle=$aliasMoodle" "$dominio
 
- 		fi
 
- 		cont=$((cont + 1))
 
- 	done
 
- 	dominioMoodle=$serverName
 
- 	# Introducir contraseña
 
- 	control=false
 
- 	error=""
 
- 	while [ $control = false ]; do
 
- 		passwdMoodle=$(whiptail --title "CONFIGURACION MOODLE" --passwordbox "$error""Introduzca la contraseña para el usuario administrador 'admin':" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 		passwdMoodle2=$(whiptail --title "CONFIGURACION MOODLE" --passwordbox "Confirme la contraseña:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 		if [ -z "$passwdMoodle" ] || [ -z "$passwdMoodle2" ]; then
 
- 			error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
 
- 		elif [ $passwdMoodle != $passwdMoodle2 ];then
 
- 			error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
 
- 		else
 
- 			control=true
 
- 		fi
 
- 	done
 
- 	unset control error passwdMoodle2 dominio cont serverName aliasMoodle
 
- }
 
- mostrarConfirmacion() {
 
- # Pantalla que presenta una confirmación antes de realizar la instalación
 
- 	whiptail --title "INSTALACION" --yesno "ESTA TODO LISTO PARA LA INSTALACION.\n¿DESEA CONTINUAR?" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --yes-button "Instalar" --no-button "Salir"
 
- 	comprobarError $? 1
 
- }
 
- establecerFQDN() {
 
- # Configura el FQDN (dominio principal del servidor)
 
- 	while [ -z "$hostname" ]; do
 
- 		hostname=$(whiptail --title "FQDN" --inputbox "El nombre de dominio principal (FQDN) de este servidor es:\n"$(hostname)"\n\n¿Quieres 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() {
 
- # Instala Apache2
 
- 	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
 
- 		if [ $sslOn = true ];then
 
- 			# Instalamos módulo mod_ssl (no se instala por defecto)
 
- 			result=$(yum -y install mod_ssl 2>&1)
 
- 			comprobarError $? 101 $result
 
- 		fi
 
- 	else
 
- 		comprobarError 1 104
 
- 	fi
 
- 	deshabilitarServicio $webServerName
 
- }
 
- configurarApache() {
 
- # Configura Apache2
 
- 	if [ $debianOS = true ];then
 
- 		apacheConfFile="./etc/apache2/apache2.conf"
 
- 		if [ ! -f $apacheConfFile ];then
 
- 			comprobarError 1 4 $apacheConfFile
 
- 		fi
 
- 		cp -f $apacheConfFile /etc/$webServerName/apache2.conf 2>/dev/null
 
- 		comprobarError $? 108
 
- 		webServerUser=$(grep ^User /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
 
- 		webServerGroup=$(grep ^Group /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
 
- 		if [ ! -L /etc/$webServerName/logs ];then
 
- 			ln -s /var/log/apache2 /etc/$webServerName/logs 2>/dev/null
 
- 			comprobarError $? 108
 
- 		fi
 
- 		# Activamos mod_rewrite (no viene activado por defecto)
 
- 		a2enmod rewrite >/dev/null 2>&1
 
- 		comprobarError $? 108
 
- 		# Activamos mod_ssl y mod_headers (no viene activado por defecto)
 
- 		if [ $sslOn = true ];then
 
- 			a2enmod ssl >/dev/null 2>&1
 
- 			comprobarError $? 108
 
- 			a2enmod headers >/dev/null 2>&1
 
- 			comprobarError $? 108
 
- 		fi
 
- 		unset apacheConfFile
 
- 	elif [ $rhelOS = true ];then
 
- 		apacheConfFile="./etc/apache2/conf/httpd.conf"
 
- 		sslConfFile="./etc/apache2/conf.d/ssl.conf"
 
- 		welcomeConfFile="/etc/apache2/conf.d/welcome.conf"
 
- 		if [ ! -f $apacheConfFile ];then
 
- 			comprobarError 1 4 $apacheConfFile
 
- 		fi
 
- 		cp -f $apacheConfFile /etc/$webServerName/conf/httpd.conf 2>/dev/null
 
- 		comprobarError $? 108
 
- 		# Desactivamos Mensaje de Bienvenida
 
- 		if [ -f $welcomeConfFile ];then
 
- 			sed -i -e 's/^/#/' $welcomeConfFile
 
- 			comprobarError $? 108
 
- 		fi
 
- 		# Configuramos mod_ssl
 
- 		if [ $sslOn = true ];then
 
- 			if [ ! -f $sslConfFile ];then
 
- 				comprobarError 1 4 $sslConfFile
 
- 			fi
 
- 			cp -f $sslConfFile /etc/$webServerName/conf.d/ssl.conf 2>/dev/null
 
- 			comprobarError $? 108
 
- 		fi
 
- 		webServerUser=$(grep ^User /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
 
- 		webServerGroup=$(grep ^Group /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
 
- 		unset apacheConfFile sslConfFile welcomeConfFile
 
- 	fi
 
- 	if [ ! -d "/etc/$webServerName/sites-available" ];then
 
- 		mkdir "/etc/$webServerName/sites-available" 2>/dev/null
 
- 		comprobarError $? 5 "/etc/$webServerName/sites-available"
 
- 	fi
 
- 	if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
 
- 		mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
 
- 		comprobarError $? 5 "/etc/$webServerName/sites-enabled"
 
- 	else
 
- 		# Eliminar Virtual Host por defecto
 
- 		if [ -f /etc/$webServerName/sites-enabled/000-default.conf ];then
 
- 			rm -f /etc/$webServerName/sites-enabled/000-default.conf 2>/dev/null
 
- 		fi
 
- 	fi
 
- }
 
- instalarNginx() {
 
- # Instala Nginx
 
- 	webServerName="nginx"
 
- 	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
 
- 	deshabilitarServicio $webServerName
 
- }
 
- configurarNginx() {
 
- # Configura Nginx
 
- 	rm -Rf "/etc/$webServerName/!(sites-available|sites-enabled)" 2>/dev/null
 
- 	comprobarError $? 107
 
- 	nginxConfFile="./etc/$webServerName"
 
- 	if [ -d "$nginxConfFile" ];then
 
- 		cp -Rf $nginxConfFile/* /etc/$webServerName/ 2>/dev/null
 
- 		comprobarError $? 107
 
- 	else
 
- 		comprobarError 1 5 "$nginxConfFile"
 
- 	fi
 
- 	if [ ! -d "/etc/$webServerName/sites-available" ];then
 
- 		mkdir "/etc/$webServerName/sites-available" 2>/dev/null
 
- 		comprobarError $? 5 "/etc/$webServerName/sites-available"
 
- 	fi
 
- 	if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
 
- 		mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
 
- 		comprobarError $? 5 "/etc/$webServerName/sites-enabled"
 
- 	else
 
- 		# Eliminar Virtual Host por defecto
 
- 		if [ -f /etc/$webServerName/sites-enabled/default ];then
 
- 			rm -f /etc/$webServerName/sites-enabled/default 2>/dev/null
 
- 		fi
 
- 	fi
 
- 	# Configuramos Usuario y Grupo
 
- 	if [ $debianOS = true ];then
 
- 		webServerUser="www-data"
 
- 		webServerGroup=$webServerUser
 
- 	elif [ $rhelOS = true ];then
 
- 		webServerUser="nginx"
 
- 		webServerGroup=$webServerUser
 
- 	fi
 
- 	sed -i '/user /c\user '$webServerUser';' /etc/$webServerName/nginx.conf
 
- 	comprobarError $? 107
 
- 	unset nginxConfFile
 
- }
 
- instalarVirtualHost() {
 
- # Configuramos un Virtual Host para Apache o Nginx
 
- # Uso: instalarVirtualHost $root $virtualHost $dominio $alias
 
- 	if [ $# -ge 3 ];then
 
- 		rootVirtualHost=$(realpath $1)
 
- 		shift
 
- 		virtualHostFile=$(realpath $1)
 
- 		shift
 
- 		dominioVirtualHost=$1
 
- 		virtualHostName=$dominioVirtualHost".conf"
 
- 		shift
 
- 		aliasVirtualHost=$@
 
- 	else
 
- 		comprobarError 1 908
 
- 	fi
 
- 	if [ ! -f $virtualHostFile ];then
 
- 		comprobarError 1 909 $virtualHostName
 
- 	fi
 
- 	if [ $apacheOn = true ];then
 
- 		# Configuramos root, dominio y logs
 
- 		sed -i '/ServerName /c\\tServerName '"$dominioVirtualHost" $virtualHostFile
 
- 		comprobarError $? 908
 
- 		if [ ! -z "$aliasVirtualHost" ];then
 
- 			sed -i '/ServerName /a\\tServerAlias '"$aliasVirtualHost" $virtualHostFile
 
- 			comprobarError $? 908
 
- 		fi
 
- 		sed -i '/DocumentRoot /c\\tDocumentRoot '"$rootVirtualHost" $virtualHostFile
 
- 		comprobarError $? 908
 
- 		sed -i '/ErrorLog /c\\tErrorLog logs/'"$dominioVirtualHost"'-error.log' $virtualHostFile
 
- 		comprobarError $? 908
 
- 		sed -i '/CustomLog /c\\tCustomLog logs/'"$dominioVirtualHost"'-access.log common' $virtualHostFile
 
- 		comprobarError $? 908
 
- 		if [ $sslOn = true ];then
 
- 			sed -i '/SSLCertificateFile /c\\tSSLCertificateFile ssl/'"$dominioVirtualHost"'.crt' $virtualHostFile
 
- 			comprobarError $? 908
 
- 			sed -i '/SSLCertificateKeyFile /c\\tSSLCertificateKeyFile ssl/'"$dominioVirtualHost"'.key' $virtualHostFile
 
- 			comprobarError $? 908
 
- 		fi
 
- 	elif [ $nginxOn = true ];then
 
- 		# Configuramos root, dominio, logs y php-fpm.sock (NGINX)
 
- 		sed -i '/root /c\\troot '$rootVirtualHost';' "$virtualHostFile"
 
- 		comprobarError $? 908
 
- 		sed -i '/server_name /c\\tserver_name '"$dominioVirtualHost"' '"$aliasVirtualHost"';' $virtualHostFile
 
- 		comprobarError $? 908
 
- 		sed -i '/access_log /c\\taccess_log /var/log/nginx/'"$dominioVirtualHost"'-access.log;' $virtualHostFile
 
- 		comprobarError $? 908
 
- 		sed -i '/error_log /c\\terror_log /var/log/nginx/'"$dominioVirtualHost"'-error.log;' $virtualHostFile
 
- 		comprobarError $? 908
 
- 		socket=$(find /var/run/ -type s -name 'php*.sock')
 
- 		sed -i '/fastcgi_pass /c\\t\tfastcgi_pass unix:'"$socket"';' $virtualHostFile
 
- 		comprobarError $? 908
 
- 		if [ $sslOn = true ];then
 
- 			sed -i '/ssl_certificate /c\\tssl_certificate ssl/'"$dominioVirtualHost"'.crt;' $virtualHostFile
 
- 			comprobarError $? 908
 
- 			sed -i '/ssl_certificate_key /c\\tssl_certificate_key ssl/'"$dominioVirtualHost"'.key;' $virtualHostFile
 
- 			comprobarError $? 908
 
- 		fi
 
- 	fi
 
- 	# Copiamos ficheros de configuración
 
- 	cp -f $virtualHostFile "/etc/$webServerName/sites-available/$virtualHostName" >> $logFile 2>&1
 
- 	comprobarError $? 910
 
- 	ln -s "/etc/$webServerName/sites-available/$virtualHostName" "/etc/$webServerName/sites-enabled/$virtualHostName" >> $logFile 2>&1
 
- 	comprobarError $? 911 $virtualHostName
 
- 	recargarServicio $webServerName
 
- 	unset rootVirtualHost dominioVirtualHost virtualHostFile virtualHostName aliasVirtualHost socket
 
- }
 
- mostrarDatabase() {
 
- # Pantalla que permite escoger entre instalar MariaDB o MySQL
 
- 	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 \
 
- 		"MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" ON \
 
- 		"MySQL" "Instalar la base de datos MySQL (uso no comercial)" OFF \
 
- 		--ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
 
- 		comprobarError $? 1
 
- 		case $database in
 
- 			MariaDB)
 
- 				mariaDBOn=true
 
- 				;;
 
- 			MySQL)
 
- 				mySQLOn=true
 
- 				;;
 
- 			*)
 
- 				comprobarError 1 200
 
- 				;;
 
- 		esac
 
- 		unset database
 
- 	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() {
 
- # Pantalla para leer la contraseña para el usuario root de SQL
 
- 	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 (y desactivamos posibles plugins para forzar login por contraseña)
 
- 		mysql -e "UPDATE mysql.user SET plugin = '', Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1
 
- 		if [ $? -ne 0 ];then
 
- 			# Lo intentamos de otra forma (para versiones modernas de mysql)
 
- 			mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$sqlPasswd'" >> $logFile 2>&1
 
- 			comprobarError $? 207
 
- 		fi
 
- 		# Aplicamos el cambio de contraseña
 
- 		mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
 
- 		# Desactivamos acceso root desde el exterior (solo localhost)
 
- 		mysql -u root --password=$sqlPasswd -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 -u root --password=$sqlPasswd -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1
 
- 		comprobarError $? 209
 
- 		# Eliminamos bases de datos 'test'
 
- 		mysql -u root --password=$sqlPasswd -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1
 
- 		comprobarError $? 210
 
- 		# Eliminamos privilegios de la base de datos 'test'
 
- 		mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1
 
- 		comprobarError $? 211
 
- 		# Aplicamos los cambios
 
- 		mysql -u root --password=$sqlPasswd -e "FLUSH PRIVILEGES" >> $logFile 2>&1
 
- 		comprobarError $? 212
 
- 	else
 
- 		comprobarError 1 206
 
- 	fi
 
- }
 
- instalarMySQL() {
 
- # Instala MySQL (sólo para Debian)
 
- 	sqlServerName="mysql"
 
- 	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
 
- 	deshabilitarServicio $sqlServerName
 
- }
 
- instalarMariaDB() {
 
- # Instala MariaDB
 
- 	sqlServerName="mariadb"
 
- 	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
 
- 	deshabilitarServicio $sqlServerName
 
- }
 
- configurarSQL() {
 
- # Configura BarracudaFS en mysql (necesario para Moodle)
 
- 	# Configura MariaDB o MySQL
 
- 	if [ $mariaDBOn = true ] && [ $debianOS = true ];then
 
- 		sqlConfFile="/etc/mysql/my.cnf"
 
- 	elif [ $mariaDBOn = true ] && [ $rhelOS = true ];then
 
- 		sqlConfFile="/etc/my.cnf"
 
- 	elif [ $mySQLOn = true ] && [ $debianOS = true ];then
 
- 		sqlConfFile="/etc/mysql/my.cnf"
 
- 	else
 
- 		comprobarError 1 213
 
- 	fi
 
- 	if [ ! -f $sqlConfFile ];then
 
- 		comprobarError 1 213
 
- 	fi
 
- 	grep "# Configuration for Moodle" $sqlConfFile >/dev/null 2>&1
 
- 	if [ $? -ne 0 ];then
 
- 		# Establecemos UTF8 (codificación de caracteres) y Barracuda (sistema de ficheros)
 
- 		echo -en "\n# Configuration for Moodle\n" >> $sqlConfFile
 
- 		echo -en "[client]\n" >> $sqlConfFile
 
- 		echo -en "default-character-set = utf8mb4\n\n" >> $sqlConfFile
 
- 		echo -en "[mysqld]\n" >> $sqlConfFile
 
- 		echo -en "innodb_file_format = Barracuda\n" >> $sqlConfFile
 
- 		echo -en "innodb_file_per_table = 1\n" >> $sqlConfFile
 
- 		echo -en "innodb_large_prefix\n\n" >> $sqlConfFile
 
- 		echo -en "character-set-server = utf8mb4\n" >> $sqlConfFile
 
- 		echo -en "collation-server = utf8mb4_unicode_ci\n" >> $sqlConfFile
 
- 		echo -en "skip-character-set-client-handshake\n\n" >> $sqlConfFile
 
- 		echo -en "[mysql]\n" >> $sqlConfFile
 
- 		echo -en "default-character-set = utf8mb4\n" >> $sqlConfFile
 
- 	else
 
- 		comprobarError 1 214
 
- 	fi
 
- 	unset sqlConfFile
 
- }
 
- instalarPHP() {
 
- # Instalamos PHP-7 y los módulos PHP que necesitan MediaWiki y Moodle
 
- 	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-xml php-apcu php-gd php-curl php-zip php-soap php-xmlrpc 2>&1)
 
- 			comprobarError $? 302 $result
 
- 		elif [ $nginxOn = true ];then
 
- 			phpFPMName="php7.2-fpm"
 
- 			result=$(apt-get -q -y install php-fpm php-mysql php-intl php-mbstring php-xml php-apcu php-gd php-curl php-zip php-soap php-xmlrpc 2>&1)
 
- 			comprobarError $? 302 $result
 
- 			deshabilitarServicio $phpFPMName
 
- 		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 2>&1)
 
- 		comprobarError $? 103 $result
 
- 		# Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE)
 
- 		if [ ! -f /etc/yum.repos.d/remi-php72.repo ];then
 
- 			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
 
- 		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 php-xml php-pecl-apcu php-gd php-pear-Net-Curl php-pecl-zip php-soap php-xmlrpc 2>&1)
 
- 			comprobarError $? 302 $result
 
- 		elif [ $nginxOn = true ];then
 
- 			phpFPMName="php-fpm"
 
- 			result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd php-pear-Net-Curl php-pecl-zip php-soap php-xmlrpc 2>&1)
 
- 			comprobarError $? 302 $result
 
- 			deshabilitarServicio $phpFPMName
 
- 		else
 
- 			comprobarError 1 301
 
- 		fi
 
- 	else
 
- 		comprobarError 1 300
 
- 	fi
 
- }
 
- configurarPHP() {
 
- # Configura PHP para segurizarlo y establecer máximo de subida.
 
- 	if [ $debianOS = true ];then
 
- 		phpConfFile="./etc/php/php.ini.debian"
 
- 		phpDest="/etc/php/7.2/cli/php.ini"
 
- 	elif [ $rhelOS = true ];then
 
- 		phpConfFile="./etc/php/php.ini.rhel"
 
- 		phpDest="/etc/php.ini"
 
- 	fi
 
- 	if [ ! -f $phpConfFile ];then
 
- 		comprobarError 1 4 "$phpConfFile"
 
- 	fi
 
- 	# Copiamos configuración
 
- 	cp -f $phpConfFile $phpDest 2>/dev/null
 
- 	comprobarError $? 305
 
- 	# Configuramos cgi.fix_pathinfo
 
- 	sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=0' $phpDest
 
- 	comprobarError $? 305
 
- 	# Configuramos post_max_size
 
- 	sed -i '/post_max_size =/c\post_max_size = '$maxUpload $phpDest
 
- 	comprobarError $? 305
 
- 	# Configuramos upload_max_filesize
 
- 	sed -i '/upload_max_filesize =/c\upload_max_filesize = '$maxUpload $phpDest
 
- 	comprobarError $? 305
 
- 	# Configurar php-fpm (sólo en RHEL con Nginx)
 
- 	if [ $rhelOS = true ] && [ $nginxOn = true ];then
 
- 		# Configurar Socket UNIX
 
- 		phpConfFile="./etc/php/php-fpm.d/www.conf"
 
- 		phpDest="/etc/php-fpm.d/www.conf"
 
- 		if [ ! -f $phpConfFile ];then
 
- 			comprobarError $? 4 "$phpConfFile"
 
- 		fi
 
- 		cp -f $phpConfFile $phpDest 2>/dev/null
 
- 		comprobarError $? 305
 
- 		# Configurar Permisos /var/lib/php
 
- 		chown -R $webServerUser:$webServerGroup /var/lib/php/
 
- 		comprobarError $? 305
 
- 	fi
 
- 	unset phpConfFile phpDest
 
- }
 
- establecerMaxUpload() {
 
- # Pantalla para establecer el máximo de subida al servidor (vía PHP)
 
- 	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(<K:Kilobyte>   <M:Megabyte>   <G:Gigabyte>)" $((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
 
- }
 
- instalarLetsEncrypt() {
 
- # Instala certbot (para certificados Let's Encrypt)
 
- 	# Comprobamos si cerbot está instalado
 
- 	which certbot > /dev/null 2>&1
 
- 	if [ $? -ne 0 ];then
 
- 		# Descargar Let's Encrypt, hacer ejecutable e instalar
 
- 		curl -o ./var/certbot https://dl.eff.org/certbot-auto 2>/dev/null
 
- 		comprobarError $? 401
 
- 		chmod 755 ./var/certbot 2>/dev/null
 
- 		comprobarError $? 401
 
- 		cp -f ./var/certbot /usr/bin/certbot 2>/dev/null
 
- 		comprobarError $? 401
 
- 		# Configurar /etc/cron.d/certbot para renovar automáticamente los certificados
 
- 		echo -en "# certbot autorenew of the certificates twice a day\n" > /etc/cron.d/certbot
 
- 		echo -en "SHELL=/bin/sh\n" >> /etc/cron.d/certbot
 
- 		echo -en "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n\n" >> /etc/cron.d/certbot
 
- 		echo -en "# Job start twice per day (4am & 2pm) in a random minute" >> /etc/cron.d/certbot
 
- 		echo -en "0 4,14 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew\n" >> /etc/cron.d/certbot
 
- 	fi
 
- }
 
- generarCertAutofirmado() {
 
- # Genera certificados autofirmados
 
- # Estos certificados no son seguros, pero valen para pruebas o como paso intermedio para obtener los válidos
 
- # Uso: generarCertAutofirmado $dominio
 
- 	dominio=$1
 
- 	sslDir="/etc/$webServerName/ssl"
 
- 	keyFile="$sslDir/$dominio.key"
 
- 	reqFile="$sslDir/$dominio.csr"
 
- 	certFile="$sslDir/$dominio.crt"
 
- 	if [ ! -d "$sslDir" ];then
 
- 		mkdir "$sslDir" 2>/dev/null
 
- 		comprobarError $? 5 "$sslDir"
 
- 	fi
 
- 	# Generamos clave privada RSA de 2048 bits
 
- 	openssl genrsa -out "$keyFile" 2048 >/dev/null 2>&1
 
- 	comprobarError $? 402
 
- 	# Generamos petición de firma
 
- 	echo -en "ES\nMadrid\nMadrid\n$dominio\n$dominio\n$dominio\nadmin@$dominio\n\n\n" | openssl req -new -key "$keyFile" -out "$reqFile" >/dev/null 2>&1
 
- 	comprobarError $? 402
 
- 	# Autofirmados clave para 2 años (730 días)
 
- 	openssl x509 -req -days 730 -in "$reqFile" -signkey "$keyFile" -out "$certFile" >/dev/null 2>&1
 
- 	comprobarError $? 402
 
- 	# Eliminamos petición
 
- 	rm -f $reqFile
 
- 	comprobarError $? 402
 
- 	# Cambiamos permisos
 
- 	chmod 644 $certFile
 
- 	comprobarError $? 402
 
- 	chmod 400 $keyFile
 
- 	comprobarError $? 402
 
- 	unset dominio sslDir keyFile reqFile certFile
 
- }
 
- generarDHParam() {
 
- # Genera clave de intercambio Diffie-Hellman y lo configuramos
 
- # Esto aumenta notablemente la seguridad de SSL/TLS
 
- 	sslDir="/etc/$webServerName/ssl"
 
- 	dhParamFile="$sslDir/dhparam.pem"
 
- 	apacheConfFile=""
 
- 	nginxConfFile="/etc/$webServerName/nginx.conf"
 
- 	if [ ! -d "$sslDir" ];then
 
- 		mkdir "$sslDir" 2>/dev/null
 
- 		comprobarError $? 5 "$sslDir"
 
- 	fi
 
- 	openssl dhparam -out "$dhParamFile" 2048 >/dev/null 2>&1
 
- 	comprobarError $? 403
 
- 	# Configuramos Servidor Web
 
- 	if [ $apacheOn = true ];then
 
- 		if [ $debianOS = true ];then
 
- 			apacheConfFile="/etc/$webServerName/apache2.conf"
 
- 		elif [ $rhelOS = true ];then
 
- 			apacheConfFile="/etc/$webServerName/conf/httpd.conf"
 
- 		else
 
- 			comprobarError 1 403
 
- 		fi
 
- 		echo -en "\n# Set Stronger Diffie-Hellman key exchange\n" >> $apacheConfFile
 
- 		echo -en "SSLOpenSSLConfCmd DHParameters \"$dhParamFile\"\n" >> $apacheConfFile
 
- 	elif [ $nginxOn = true ];then
 
- 		sed -i '/ssl_param /c\\tssl_dhparam '$dhParamFile';' $nginxConfFile
 
- 		comprobarError $? 403
 
- 	fi
 
- 	unset sslDir dhParamFile apacheConfFile nginxConfFile
 
- }
 
- 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á parado
 
- 	#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
 
- }
 
- 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
 
- 	esSSH $PPID
 
- 	if [ $debianOS = true ];then
 
- 		ufw allow 80/tcp >> $logFile 2>&1
 
- 		comprobarError $? 906 "80/tcp"
 
- 		if [ $sshControl = true ];then
 
- 			ufw allow 22/tcp >> $logFile 2>&1
 
- 			comprobarError $? 906 "22/tcp"
 
- 		fi
 
- 		if [ $sslOn = true ];then
 
- 			ufw allow 443/tcp >> $logFile 2>&1
 
- 			comprobarError $? 906 "443/tcp"
 
- 		fi
 
- 		ufw --force enable >> $logFile 2>&1
 
- 		comprobarError $? 907
 
- 	elif [ $rhelOS = true ];then
 
- 		firewall-cmd --add-port=80/tcp >> $logFile 2>&1
 
- 		comprobarError $? 906 "80/tcp"
 
- 		if [ $sshControl = true ];then
 
- 			firewall-cmd --add-port=22/tcp >> $logFile 2>&1
 
- 			comprobarError $? 906 "22/tcp"
 
- 		fi
 
- 		if [ $sslOn = true ];then
 
- 			firewall-cmd --add-port=443/tcp >> $logFile 2>&1
 
- 			comprobarError $? 906 "443/tcp"
 
- 		fi
 
- 		firewall-cmd --runtime-to-permanent >> $logFile 2>&1
 
- 		comprobarError $? 907
 
- 		habilitarServicio firewalld >> $logFile 2>&1
 
- 		comprobarError $? 907
 
- 	fi
 
- 	unset sshControl
 
- }
 
- esSSH() {
 
- # Comprobamos si nuestro terminal usa SSH
 
- 	p=${1:-$PPID}
 
- 	#read pid name x ppid y < <( cat /proc/$p/stat )
 
- 	read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
 
- 	[[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
 
- 	[ "$ppid" -le 1 ] && { sshControl=false; return 1; }
 
- 	esSSH $ppid
 
- }
 
- descargarMediaWiki() {
 
- # Descargar la versión 1.31.0 de MediaWiki
 
- 	if [ ! -d ./var ];then
 
- 		comprobarError 1 5 "./var"
 
- 	fi
 
- 	curl "https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz" 2>/dev/null | tar -xz -C "./var/"
 
- 	comprobarError $? 501
 
- }
 
- configurarMediaWiki() {
 
- # Configuramos MediaWiki
 
- 	if [ ! -f /var/www/$dominioMediaWiki/LocalSettings.php ];then
 
- 		# Copiamos archivos
 
- 		cp -fR ./var/mediawiki-1.31.0/ /var/www/$dominioMediaWiki
 
- 		comprobarError $? 502
 
- 		# Configuramos LocalSettings.php (y crea la base de datos por nosotros)
 
- 		nombreDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
 
- 		userDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
 
- 		php /var/www/$dominioMediaWiki/maintenance/install.php --dbname=$nombreDBMW --dbserver="localhost" --installdbuser=root --installdbpass=$sqlPasswd --dbuser=$userDBMW --dbpass=$sqlPasswd --scriptpath="" --lang=es --pass=$passwdMediaWiki --with-extensions "$nombreMediaWiki" "admin" >> $logFile 2>&1
 
- 		comprobarError $? 502
 
- 		# Configuraciones adicionales
 
- 		sed -i '/$wgLanguageCode =/c\$wgLanguageCode = "es";' /var/www/$dominioMediaWiki/LocalSettings.php
 
- 		comprobarError $? 502
 
- 		sed -i '/$wgEnableEmail =/c\$wgEnableEmail = false;' /var/www/$dominioMediaWiki/LocalSettings.php
 
- 		comprobarError $? 502
 
- 		sed -i '/$wgEnableUploads =/c\$wgEnableUploads = true;' /var/www/$dominioMediaWiki/LocalSettings.php
 
- 		comprobarError $? 502
 
- 		echo -en "\$wgArticlePath = \"/wiki/\$1\";\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
 
- 		echo -en "\$wgUsePathInfo = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
 
- 		echo -en "\$wgGroupPermissions['*']['createaccount'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
 
- 		echo -en "\$wgGroupPermissions['*']['edit'] = false;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
 
- 		echo -en "\$wgGroupPermissions['*']['read'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
 
- 		# Actualizamos permisos
 
- 		chown -R $webServerUser:$webServerGroup /var/www/$dominioMediaWiki
 
- 		comprobarError $? 502
 
- 		# Configuramos VirtualHost
 
- 		if [ $apacheOn = true ] && [ $sslOn = false ];then
 
- 			virtualHost="./etc/apache2/sites-available/mediawiki.conf"
 
- 		elif [ $nginxOn = true ] && [ $sslOn = false ];then
 
- 			virtualHost="./etc/nginx/sites-available/mediawiki.conf"
 
- 		elif [ $apacheOn = true ] && [ $sslOn = true ];then
 
- 			virtualHost="./etc/apache2/sites-available/mediawiki-ssl.conf"
 
- 		elif [ $nginxOn = true ] && [ $sslOn = true ];then
 
- 			virtualHost="./etc/nginx/sites-available/mediawiki-ssl.conf"
 
- 		else
 
- 			comprobarError 1 502
 
- 		fi
 
- 		if [ ! -f $virtualHost ];then
 
- 			comprobarError $? 502
 
- 		fi
 
- 		instalarVirtualHost "/var/www/$dominioMediaWiki" $virtualHost $dominioMediaWiki $aliasMediaWiki
 
- 		unset virtualHost
 
- 	else
 
- 		comprobarError 1 503 $dominioMediaWiki
 
- 	fi
 
- }
 
- descargarMoodle() {
 
- # Descargar la versión 1.31.0 de MediaWiki
 
- 	if [ ! -d ./var ];then
 
- 		comprobarError 1 5 "./var"
 
- 	fi
 
- 	#echo -en "Descargando Moodle-3.5-1..." | tee -a $logFile
 
- 	#curl -o "./var/moodle-3.5.1.tgz" "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" >> $logFile 2>&1
 
- 	curl "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" 2>/dev/null | tar -xz -C "./var/"
 
- 	comprobarError $? 501
 
- 	#echo -en " OK.\n" | tee -a $logFile
 
- }
 
- configurarMoodle() {
 
- # Configurar Moodle
 
- 	if [ ! -f /var/www/$dominioMoodle/config.php ];then
 
- 		# Copiamos archivos
 
- 		cp -Rf ./var/moodle/ /var/www/$dominioMoodle
 
- 		comprobarError $? 602
 
- 		# Crear carperta de datos (no online)
 
- 		if [ ! -d /var/www/moodledata ];then
 
- 			mkdir /var/www/moodledata 2>/dev/null
 
- 			comprobarError $? 602
 
- 		fi
 
- 		#Actualizamos permisos
 
- 		perm=$(stat -c %a /var/www/moodledata)
 
- 		if [ $perm -ne 777 ];then
 
- 			chmod -R 777 /var/www/moodledata 2>/dev/null
 
- 			comprobarError $? 602
 
- 		fi
 
- 		perm=$(stat -c %U /var/www/moodledata)
 
- 		if [ $perm != "$webServerUser" ];then
 
- 			chown -R $webServerUser:$webServerGroup /var/www/moodledata 2>/dev/null
 
- 			comprobarError $? 602
 
- 		fi
 
- 		unset perm
 
- 		# Creamos Base de Datos
 
- 		nombreDBMo=$(echo $dominioMoodle | sed -e 's/\./_/g')
 
- 		userDBMo=$(echo $dominioMoodle | sed -e 's/\./_/g')
 
- 		crearDBMoodle
 
- 		# Configurar SE-Linux (RHEL)
 
- 		if [ $rhelOS = true ];then
 
- 			configurarSELinux
 
- 		fi
 
- 		# Configuramos e instalamos Moodle
 
- 		if [ $sslOn = true ];then
 
- 			wwwroot="https://$dominioMoodle"
 
- 		else
 
- 			wwwroot="http://$dominioMoodle"
 
- 		fi
 
- 		if [ $mySQLOn = true ];then
 
- 			dbtype="mysqli"
 
- 		elif [ $mariaDBOn = true ];then
 
- 			dbtype="mariadb"
 
- 		else
 
- 			comprobarError 1 602
 
- 		fi
 
- 		php /var/www/$dominioMoodle/admin/cli/install.php --lang=es --wwwroot="$wwwroot" --dataroot="/var/www/moodledata" --dbtype="$dbtype" --dbname="$nombreDBMo" --dbuser="$userDBMo" --dbpass="$sqlPasswd" --fullname="$nombreMoodle" --shortname="$nombreCortoMoodle" --adminuser=admin --adminpass="$passwdMoodle" --adminemail="admin@$dominioMoodle" --agree-license --non-interactive >>$logFile 2>&1
 
- 		comprobarError $? 602
 
- 		# Actualizamos permisos
 
- 		chown -R $webServerUser:$webServerGroup /var/www/$dominioMoodle /var/www/moodledata
 
- 		# Configuramos VirtualHost
 
- 		if [ $apacheOn = true ] && [ $sslOn = false ];then
 
- 			virtualHost="./etc/apache2/sites-available/moodle.conf"
 
- 		elif [ $nginxOn = true ] && [ $sslOn = false ];then
 
- 			virtualHost="./etc/nginx/sites-available/moodle.conf"
 
- 		elif [ $apacheOn = true ] && [ $sslOn = true ];then
 
- 			virtualHost="./etc/apache2/sites-available/moodle-ssl.conf"
 
- 		elif [ $nginxOn = true ] && [ $sslOn = true ];then
 
- 			virtualHost="./etc/nginx/sites-available/moodle-ssl.conf"
 
- 		else
 
- 			comprobarError 1 602
 
- 		fi
 
- 		instalarVirtualHost "/var/www/$dominioMoodle" $virtualHost $dominioMoodle
 
- 		unset virtualHost wwwroot dbtype
 
- 	else
 
- 		comprobarError 1 603 $dominioMoodle
 
- 	fi
 
- }
 
- crearDBMoodle() {
 
- # Crear base de datos para Moodle
 
- 	dbDir="./etc/db"
 
- 	if [ ! -d $dbDir ];then
 
- 		mkdir $dbDir 2>/dev/null
 
- 		comprobarError $? 503
 
- 	fi
 
- 	dbFile=$dbDir"/moodle.sql"
 
- 	echo -en "CREATE DATABASE IF NOT EXISTS $nombreDBMo DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\n" > $dbFile
 
- 	echo -en "GRANT ALL PRIVILEGES ON $nombreDBMo.* TO '$userDBMo'@'localhost' IDENTIFIED BY '$sqlPasswd';\n" >> $dbFile
 
- 	mysql -u root --password=$sqlPasswd < $dbFile > /dev/null 2>&1
 
- 	control=$?
 
- 	rm -f $dbFile 2>/dev/null
 
- 	comprobarError $? 503
 
- 	comprobarError $control 503
 
- 	unset control dbFile dbDir
 
- }
 
- configurarSELinux() {
 
- # Configurar SELinux (Sólo para RHEL)
 
- 	which semanage >/dev/null 2>&1
 
- 	if [ $? -ne 0 ];then
 
- 		result=$(yum -y install policycoreutils-python 2>&1)
 
- 		comprobarError $? 605 $result
 
- 	fi
 
- 	semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/moodledata(/.*)?" > /dev/null 2>&1
 
- 	comprobarError $? 604
 
- 	restorecon -R /var/www/ > /dev/null 2>&1
 
- 	comprobarError $? 604
 
- }
 
- instalarPHPInfo() {
 
- # Instalar fichero info.php y su VirtualHost
 
- 	if [ ! -f /etc/$webServerName/sites-enabled/phpinfo.conf ];then
 
- 		infoFile="./var/www/info.php"
 
- 		if [ ! -f $infoFile ];then
 
- 			comprobarError 1 4 "$infoFile"
 
- 		fi
 
- 		mkdir /var/www/localhost 2>/dev/null
 
- 		comprobarError $? 106
 
- 		cp -f $infoFile /var/www/localhost/ 2>/dev/null
 
- 		comprobarError $? 106
 
- 		chown -R $webServerUser:$webServerGroup /var/www/localhost 2>/dev/null
 
- 		comprobarError $? 106
 
- 		unset infoFile
 
- 		# Instalar VirtualHost
 
- 		if [ $apacheOn = true ] && [ $sslOn = false ];then
 
- 			virtualHost="./etc/apache2/sites-available/phpinfo.conf"
 
- 		elif [ $nginxOn = true ] && [ $sslOn = false ];then
 
- 			virtualHost="./etc/nginx/sites-available/phpinfo.conf"
 
- 		elif [ $apacheOn = true ] && [ $sslOn = true ];then
 
- 			virtualHost="./etc/apache2/sites-available/phpinfo-ssl.conf"
 
- 		elif [ $nginxOn = true ] && [ $sslOn = true ];then
 
- 			virtualHost="./etc/nginx/sites-available/phpinfo-ssl.conf"
 
- 		else
 
- 			comprobarError 1 106
 
- 		fi
 
- 		instalarVirtualHost "/var/www/localhost" $virtualHost "localhost"
 
- 		unset virtualHost
 
- 		return 0
 
- 	else
 
- 		return 1
 
- 	fi
 
- }
 
- # Comprobación del sistema e inicialización
 
- 	inicializarVariables
 
- 	comprobarRoot
 
- 	OSInfo
 
- 	comprobarDependencias
 
- # Bienvenida
 
- 	mostrarBienvenida
 
- 	
 
- # Selección de componentes (express vs avanzada)
 
- 	mostrarExpress
 
- # Instalación Servidor Web
 
- 	if [ $apacheOn = true ]; then
 
- 		echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
 
- 		instalarApache
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	elif [ $nginxOn = true ]; then
 
- 		echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
 
- 		instalarNginx
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Instalación Base de Datos
 
- 	if [ $mySQLOn = true ]; then
 
- 		echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
 
- 		instalarMySQL
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	elif [ $mariaDBOn = true ]; then
 
- 		echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
 
- 		instalarMariaDB
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Instalación PHP-7.2
 
- 	if [ $phpOn = true ]; then
 
- 		echo -en "Instalando PHP-7..." | tee -a $logFile
 
- 		instalarPHP
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Instalación Let's Encrypt
 
- 	if [ $letsEncryptOn = true ];then
 
- 		echo -en "Instalando Let's Encrypt..." | tee -a $logfile
 
- 		instalarLetsEncrypt
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Configuración Web Server
 
- 	if [ $apacheOn = true ];then
 
- 		echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
 
- 		configurarApache
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	elif [ $nginxOn = true ]; then
 
- 		echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
 
- 		configurarNginx
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Configuración Database (Configurar Ficheros, Arrancar Base de Datos, establecer contraseña y configuración segura)
 
- 	if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
 
- 		echo -en "Configurando Base de Datos..." | tee -a $logFile
 
- 		configurarSQL
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 		habilitarServicio "$sqlServerName"
 
- 		echo -en "Estableciendo contraseña de la Base de Datos..." | tee -a $logFile
 
- 		establecerSQLPasswd
 
- 		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
 
- 		echo -en "Configurando PHP-7..." | tee -a $logFile
 
- 		configurarPHP
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Configuración SSL/TLS
 
- 	# Generar certificados auto-firmados
 
- 	if [ $sslOn = true ];then
 
- 		echo -en "Generando Certificados Auto-Firmados..." | tee -a $logFile
 
- 		if [ $mediaWikiOn = true ];then
 
- 			generarCertAutofirmado $dominioMediaWiki
 
- 		fi
 
- 		if [ $moodleOn = true ];then
 
- 			generarCertAutofirmado $dominioMoodle
 
- 		fi
 
- 		if [ $infoPHPOn = true ];then
 
- 			generarCertAutofirmado "localhost"
 
- 		fi
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 		echo -en "Generando claves de intercambio Diffie-Hellman (puede llevar un largo tiempo)..." | tee -a $logFile
 
- 		generarDHParam
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
 
- 	echo -en "Habilitando todos los servicios..." | tee -a $logFile
 
- 	if [ $apacheOn = true ] || [ $nginxOn = true ];then
 
- 		habilitarServicio $webServerName
 
- 	fi
 
- 	if [ $nginxOn = true ] && [ $phpOn = true ];then
 
- 		habilitarServicio $phpFPMName
 
- 	fi
 
- 	echo -en " OK.\n" | tee -a $logFile
 
- # Instalar MediaWiki
 
- 	if [ $mediaWikiOn = true ]; then
 
- 		# Descargar MediaWiki
 
- 		echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
 
- 		descargarMediaWiki
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 		# Configurar MediWiki
 
- 		echo -en "Configurando MediaWiki..." | tee -a $logFile
 
- 		configurarMediaWiki
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Instalar Moodle
 
- 	if [ $moodleOn = true ]; then
 
- 		# Descargar Moodle
 
- 		echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
 
- 		descargarMoodle
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 		# Configuración Moodle
 
- 		echo -en "Configurando Moodle (puede llevar un tiempo largo)..." | tee -a $logFile
 
- 		configurarMoodle
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Instalar info.php
 
- 	if [ $infoPHPOn = true ];then
 
- 		echo -en "Configurando 'info.php'..." | tee -a $logFile
 
- 		instalarPHPInfo
 
- 		if [ $? -eq 0 ];then
 
- 			echo -en " OK.\n" | tee -a $logFile
 
- 		else
 
- 			echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
 
- 		fi
 
- 	fi
 
- # Añadir reglas del cortafuegos
 
- 	echo -en "Configurando Cortafuegos..." | tee -a $logFile
 
- 	configurarCortafuegos
 
- 	echo -en " OK.\n" | tee -a $logFile
 
- # Generar certificados Let's Encrypt
 
- 	if [ $letsEncryptOn = true ];then
 
- 		echo -en "Generando Certificados Válidos Let's Encrypt..." | tee -a $logFile
 
- 		sleep 2
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
- # Configurar Backup
 
- 	if [ $backupOn = true ]; then
 
- 		echo -en "Configurando Backup Automático..." | tee -a $logFile
 
- 		sleep 2
 
- 		echo -en " OK.\n" | tee -a $logFile
 
- 	fi
 
 
  |