install 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  1. #!/bin/bash
  2. #################################################################
  3. # auto-mediawiki #
  4. # Instala un servidor LAMP (Linux+Apache+MySQL+PHP) e instala #
  5. # MediaWiki y lo configura. #
  6. # #
  7. # Guzman Castanedo Villalba (guzman@castanedo.es) Junio 2018 #
  8. # GPLv3 (https://www.gnu.org/licenses/gpl.html) #
  9. #################################################################
  10. comprobarError() {
  11. # comprobarError exitNum codeNum extraInfo
  12. # 1xx: Servidor Web
  13. # 2xx: Base de Datos
  14. # 3xx: PHP
  15. # 4xx: SSL/TLS
  16. # 5xx: MediaWiki
  17. # 6xx: Moodle
  18. # 7xx: Actualizaciones automáticas
  19. # 8xx: Dependencias
  20. # 9xx: Servicios & Firewall
  21. type="ERROR"
  22. exitNum=$1
  23. shift
  24. codeNum=$1
  25. shift
  26. extraInfo=$@
  27. case $codeNum in
  28. 1)
  29. error="$type $codeNum:\tInstalación interrumpida por el usuario.\n"
  30. ;;
  31. 2)
  32. error="$type $codeNum:\tError interno (selección express).\n"
  33. ;;
  34. 3)
  35. error="$type $codeNum:\tError interno (selección avanzada).\n"
  36. ;;
  37. 4)
  38. error="\n$type $codeNum:\tEl archivo '"$(realpath $extraInfo)"' no existe.\n"
  39. ;;
  40. 5)
  41. error="\n$type $codeNum:\tEl directorio '"$(realpath $extraInfo)"' no existe.\n"
  42. ;;
  43. 100)
  44. error="$type $codeNum:\tError interno (selección del servidor web).\n"
  45. ;;
  46. 101)
  47. error="\n$type $codeNum:\tError al instalar Apache2.\nDetalles:\n$extraInfo\n"
  48. ;;
  49. 102)
  50. error="\n$type $codeNum:\tError al instalar Nginx.\nDetalles:\n$extraInfo\n"
  51. ;;
  52. 103)
  53. error="\n$type $codeNum:\tError al nstalar repositorio 'epel-release'.\nDetalles:\n$extraInfo\n"
  54. ;;
  55. 104)
  56. error="\n$type $codeNum:\tError interno (instalación Apache2).\n"
  57. ;;
  58. 105)
  59. error="\n$type $codeNum:\tError interno (instalación Nginx).\n"
  60. ;;
  61. 106)
  62. type="WARNING"
  63. error="\n$type $codeNum:\tImposible instalar 'info.php'.\n"
  64. ;;
  65. 107)
  66. error="\n$type $codeNum:\tError al configurar Nginx.\n"
  67. ;;
  68. 108)
  69. error="\n$type $codeNum:\tError al configurar Apache2.\n"
  70. ;;
  71. 200)
  72. error="$type $codeNum:\tError interno (selección de base de datos).\n"
  73. ;;
  74. 201)
  75. error="\n$type $codeNum:\tError al instalar MySQL.\nDetalles:\n$extraInfo\n"
  76. ;;
  77. 202)
  78. error="\n$type $codeNum:\tError al instalar MariaDB.\nDetalles:\n$extraInfo\n"
  79. ;;
  80. 203)
  81. error="\n$type $codeNum:\tError interno (instalación MySQL).\n"
  82. ;;
  83. 204)
  84. error="\n$type $codeNum:\tError interno (instalación MariaDB).\n"
  85. ;;
  86. 205)
  87. error="\n$type $codeNum:\t$DIST no incluye MySQL en sus repositorios.\n"
  88. ;;
  89. 206)
  90. type="WARNING"
  91. error="\n$type $codeNum:\tUsuario 'root' ya dispone de contraseña."
  92. ;;
  93. 207)
  94. error="\n$type $codeNum:\tImposible cambiar la contraseña de 'root'."
  95. ;;
  96. 208)
  97. error="\n$type $codeNum:\tImposible desactivar acceso 'root' desde el exterior."
  98. ;;
  99. 209)
  100. error="\n$type $codeNum:\tImposible eliminar usuarios anónimos."
  101. ;;
  102. 210)
  103. type="WARNING"
  104. error="\n$type $codeNum:\tImposible eliminar bases de datos de pruebas."
  105. ;;
  106. 211)
  107. type="WARNING"
  108. error="\n$type $codeNum:\tImposible eliminar los permisos de las bases de datos de pruebas."
  109. ;;
  110. 212)
  111. error="\n$type $codeNum:\tImposible recargar base de datos."
  112. ;;
  113. 300)
  114. error="\n$type $codeNum:\tError interno (instalación PHP-7.2).\n"
  115. ;;
  116. 301)
  117. error="\n$type $codeNum:\tError interno (Web Server no seleccionado).\n"
  118. ;;
  119. 302)
  120. error="\n$type $codeNum:\tError al instalar PHP-7.2.\nDetalles:\n$extraInfo\n"
  121. ;;
  122. 303)
  123. error="\n$type $codeNum:\tError al instalar Repositorio Remi.\nDetalles:\n$extraInfo\n"
  124. ;;
  125. 304)
  126. error="\n$type $codeNum:\tSistema Operativo no compatible con PHP-7.2 ($OS $DIST $REV).\n"
  127. ;;
  128. 305)
  129. error="\n$type $codeNum:\tImposible configurar PHP-7.2.\n"
  130. ;;
  131. 800)
  132. error="$type $codeNum:\tEs necesario ser root ('sudo $0').\n"
  133. ;;
  134. 801)
  135. error="$type $codeNum:\t'whiptail' no instalado.\n"
  136. ;;
  137. 802)
  138. error="$type $codeNum:\t'hostnamectl' no instalado.\n"
  139. ;;
  140. 803)
  141. error="$type $codeNum:\t'apt-get' no instalado.\n"
  142. ;;
  143. 804)
  144. error="$type $codeNum:\t'yum' no instalado.\n"
  145. ;;
  146. 805)
  147. error="\n$type $codeNum:\tImposible actualizar repositorio\nDetalles:\n$extraInfo.\n"
  148. ;;
  149. 806)
  150. error="$type $codeNum:\t'ufw' no instalado.\n"
  151. ;;
  152. 807)
  153. error="$type $codeNum:\t'firewall-cmd' no instalado.\n"
  154. ;;
  155. 808)
  156. error="$type $codeNum:\t'tput' no instalado.\n"
  157. ;;
  158. 809)
  159. error="$type $codeNum:\t'sed' no instalado.\n"
  160. ;;
  161. 900)
  162. error="$type $codeNum:\tError interno (habilitar servicio).\n"
  163. ;;
  164. 901)
  165. error="$type $codeNum:\tImposible encender servicio '$extraInfo'.\n"
  166. ;;
  167. 902)
  168. error="$type $codeNum:\tImposible habilitar servicio '$extraInfo' durante el arranque.\n"
  169. ;;
  170. 903)
  171. error="$type $codeNum:\tError interno (deshabilitar servicio).\n"
  172. ;;
  173. 904)
  174. error="$type $codeNum:\tImposible parar servicio '$extraInfo'.\n"
  175. ;;
  176. 905)
  177. error="$type $codeNum:\tImposible deshabilitar servicio '$extraInfo' durante el arranque.\n"
  178. ;;
  179. 906)
  180. type="WARNING"
  181. error="\n$type $codeNum:\tImposible añadir regla al cortafuegos ('$extraInfo').\n"
  182. ;;
  183. 907)
  184. type="WARNING"
  185. error="\n$type $codeNum:\tImposible encender cortafuegos.\n"
  186. ;;
  187. *)
  188. error="ERROR 13:\tError interno (comprobación de errores)\n"
  189. exitNum=1
  190. codeNum=13
  191. ;;
  192. esac
  193. if [ $exitNum -ne 0 ];then
  194. echo -en "$error" | tee -a $logFile
  195. if [ $type = "ERROR" ];then
  196. exit $codeNum
  197. fi
  198. fi
  199. unset error exitNum codeNum type
  200. }
  201. OSInfo() {
  202. echo -en "Detectando SO..." >> $logFile
  203. OS=$(uname -s)
  204. if [ $OS = "Linux" ]; then
  205. OS="GNU/Linux"
  206. if [ -f /etc/os-release ]; then
  207. DIST=$(grep ^NAME= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  208. REV=$(grep ^VERSION= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  209. ID_LIKE=$(grep ^ID_LIKE= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  210. VERSION=$(grep ^VERSION_ID= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  211. for i in $ID_LIKE; do
  212. #echo -en "$i\n"
  213. case $i in
  214. debian|ubuntu)
  215. debianOS=true
  216. break
  217. ;;
  218. rhel|fedora)
  219. rhelOS=true
  220. break
  221. ;;
  222. *)
  223. debianOS=false
  224. rhelOS=false
  225. ;;
  226. esac
  227. done
  228. elif [ -f /etc/debian-version ]; then
  229. # Familia Debian (Debian, Ubuntu, Linux Mint, ...)
  230. DIST="Debian"
  231. REV=""
  232. ID_LIKE="debian"
  233. VERSION=""
  234. debianOS=true
  235. elif [ -f /etc/redhat-release ]; then
  236. # Familia Red-Hat (RHEL, Fedora, CentOS, ...)
  237. DIST="Red-Hat"
  238. REV=""
  239. ID_LIKE="rhel"
  240. VERSION=""
  241. rhelOS=true
  242. else
  243. # Other Linux (No Soportado)
  244. DIST=""
  245. REV=""
  246. ID_LIKE=""
  247. VERSION=""
  248. fi
  249. else
  250. # UNIX, OS X, ... (No Soportado)
  251. DIST=$OS
  252. REV=""
  253. ID_LIKE=""
  254. VERSION=""
  255. fi
  256. echo -en " $OS $DIST $REV\n" >> $logFile
  257. HDInfo=$(df -h | head -1)"\n"$(df -h | grep ^/dev/sd)"\n"$(df -h | grep ^/dev/mapper)
  258. echo -en "$HDInfo\n" >> $logFile
  259. }
  260. comprobarRoot() {
  261. comprobarError $(id -u) 800
  262. }
  263. comprobarDependencias() {
  264. # Comprobamos whiptail
  265. which whiptail > /dev/null 2>&1
  266. comprobarError $? 801
  267. # Comprobamos hostnamectl
  268. which hostnamectl > /dev/null 2>&1
  269. comprobarError $? 802
  270. # Comprobamos tput
  271. which tput > /dev/null 2>&1
  272. comprobarError $? 808
  273. # Comprobamso sed
  274. which sed > /dev/null 2>&1
  275. comprobarError $? 809
  276. if [ $debianOS = true ];then
  277. # Comprobamos apt-get
  278. which apt-get > /dev/null 2>&1
  279. comprobarError $? 803
  280. # Actualizamos base de datos del repositorio
  281. echo -en "Actualizando repositorio APT..." | tee -a $logFile
  282. result=$(apt-get -q -y update 2>&1)
  283. comprobarError $? 805 $result
  284. echo -en " OK.\n" | tee -a $logFile
  285. # Comprobamos Firewall (ufw)
  286. which ufw > /dev/null 2>&1
  287. comprobarError $? 806
  288. fi
  289. if [ $rhelOS = true ]; then
  290. # Comprobamos yum
  291. which yum > /dev/null 2>&1
  292. comprobarError $? 804
  293. # Actualizamos base de datos del repositorio
  294. echo -en "Actualizando repositorio YUM..." | tee -a $logFile
  295. result=$(yum -y makecache 2>&1)
  296. comprobarError $? 805 $result
  297. echo -en " OK.\n" | tee -a $logFile
  298. # Comprobamos Firewall (firewall-cmd)
  299. which firewall-cmd > /dev/null 2>&1
  300. comprobarError $? 807
  301. fi
  302. }
  303. inicializarVariables() {
  304. debianOS=false
  305. rhelOS=false
  306. apacheOn=false
  307. nginxOn=false
  308. mySQLOn=false
  309. mariaDBOn=false
  310. phpOn=false
  311. sslOn=false
  312. mediaWikiOn=false
  313. moodleOn=false
  314. infoPHPOn=false
  315. actualizacionesOn=false
  316. progreso=0
  317. progresoTotal=0
  318. logFile="./."$(basename $0)".log"
  319. maxUpload="100M"
  320. }
  321. instalacionExpress() {
  322. apacheOn=true
  323. mariaDBOn=true
  324. phpOn=true
  325. sslOn=true
  326. mediaWikiOn=true
  327. moodleOn=true
  328. actualizacionesOn=true
  329. progresoTotal=15
  330. # Preguntas mínimas
  331. establecerFQDN
  332. leerSQLPasswd
  333. }
  334. mostrarBienvenida() {
  335. ANCHO=$(tput cols)
  336. ALTO=$(tput lines)
  337. if [ $debianOS = false ] && [ $rhelOS = false ]; then
  338. 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"
  339. exit 1
  340. fi
  341. 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"
  342. comprobarError $? 1
  343. }
  344. mostrarExpress() {
  345. 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 \
  346. "Express" "Instalación rápida" ON \
  347. "Avanzada" "Permite escoger todas las opciones disponibles" OFF \
  348. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  349. comprobarError $? 1
  350. case $express in
  351. Express)
  352. instalacionExpress
  353. # DECIDIR QUÉ OPCIONES SON LAS MÍNIMAS
  354. ;;
  355. Avanzada)
  356. mostrarAvanzada
  357. ;;
  358. *)
  359. comprobarError 1 2
  360. ;;
  361. esac
  362. }
  363. mostrarAvanzada() {
  364. 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 \
  365. "LAMP" "GNU/Linux + Apache + MySQL/MariaDB + PHP-7" ON \
  366. "LEMP" "GNU/Linux + Nginx + MySQL/MariaDB + PHP-7" OFF \
  367. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  368. comprobarError $? 1
  369. for i in $webServer; do
  370. case $i in
  371. LAMP)
  372. apacheOn=true
  373. ;;
  374. LEMP)
  375. nginxOn=true
  376. ;;
  377. *)
  378. comprobarError 1 100
  379. ;;
  380. esac
  381. done
  382. # Opciones comunes
  383. establecerFQDN
  384. mostrarDatabase
  385. phpOn=true
  386. establecerMaxUpload
  387. progresoTotal=$((progresoTotal + 6))
  388. mostrarComponentes
  389. }
  390. mostrarComponentes() {
  391. 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 \
  392. "SSL/TLS" "Instalar certificados para activar HTTPS" ON \
  393. "MediaWiki" "Instalar wiki con MediaWiki" ON \
  394. "Moodle" "Instalar campus virtual con Moodle" ON \
  395. "InfoPHP" "Instalar info.php (sólo para pruebas)" OFF \
  396. "Actualizaciones" "Programar actualizaciones automáticas" ON \
  397. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  398. comprobarError $? 1
  399. # Mejora: autodetección de componentes ya instalados
  400. for i in $componentes; do
  401. case $i in
  402. \"SSL/TLS\")
  403. # 2 Opciones: Let's Encrypt o Autofirmado
  404. sslOn=true
  405. progresoTotal=$((progresoTotal + 2))
  406. ;;
  407. \"MediaWiki\")
  408. mediaWikiOn=true
  409. progresoTotal=$((progresoTotal + 2))
  410. ;;
  411. \"Moodle\")
  412. moodleOn=true
  413. progresoTotal=$((progresoTotal + 2))
  414. ;;
  415. \"InfoPHP\")
  416. infoPHPOn=true
  417. progresoTotal=$((progresoTotal + 2))
  418. ;;
  419. \"Actualizaciones\")
  420. actualizacionesOn=true
  421. progresoTotal=$((progresoTotal + 1))
  422. ;;
  423. *)
  424. comprobarError 1 3
  425. ;;
  426. esac
  427. done
  428. progresoTotal=$((progresoTotal + 2))
  429. }
  430. establecerFQDN() {
  431. while [ -z $hostname ]; do
  432. 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)
  433. if [ $? -eq 0 ] && [ ! -z $hostname ]; then
  434. hostnamectl set-hostname $hostname
  435. else
  436. hostname=$(hostname)
  437. fi
  438. done
  439. echo -en "Hostname: $hostname\n" >> $logFile
  440. }
  441. instalarApache() {
  442. if [ $debianOS = true ];then
  443. result=$(apt-get -q -y install apache2 2>&1)
  444. comprobarError $? 101 $result
  445. elif [ $rhelOS = true ]; then
  446. result=$(yum -y install httpd 2>&1)
  447. comprobarError $? 101 $result
  448. else
  449. comprobarError 1 104
  450. fi
  451. }
  452. configurarApache() {
  453. if [ $rhelOS = true ];then
  454. apacheConfFile="./etc/apache-rhel/conf/httpd.conf"
  455. welcomeConfFile="/etc/httpd/conf.d/welcome.conf"
  456. if [ ! -f $apacheConfFile ];then
  457. comprobarError 1 4 $apacheConfFile
  458. fi
  459. cp -f $apacheConfFile /etc/httpd/conf/ 2>/dev/null
  460. comprobarError $? 108
  461. if [ -f $welcomeConfFile ];then
  462. sed -i -e 's/^/#/' $welcomeConfFile
  463. comprobarError $? 108
  464. fi
  465. unset apacheConfFile welcomeConfFile
  466. fi
  467. }
  468. instalarNginx() {
  469. if [ $debianOS = true ];then
  470. result=$(apt-get -q -y install nginx 2>&1)
  471. comprobarError $? 102 $result
  472. elif [ $rhelOS = true ]; then
  473. # Hay que instalar primero otro repositorio
  474. result=$(yum -y install epel-release)
  475. comprobarError $? 103 $result
  476. result=$(yum -y install nginx 2>&1)
  477. comprobarError $? 102 $result
  478. else
  479. comprobarError 1 105
  480. fi
  481. }
  482. configurarNginx() {
  483. # Configuramos Nginx
  484. rm -Rf /etc/nginx/* 2>/dev/null
  485. comprobarError $? 107
  486. if [ $debianOS = true ];then
  487. nginxConfFile="./etc/nginx-debian"
  488. elif [ $rhelOS = true ];then
  489. nginxConfFile="./etc/nginx-rhel"
  490. fi
  491. if [ -d "$nginxConfFile" ];then
  492. cp -Rf $nginxConfFile/* /etc/nginx/ 2>/dev/null
  493. comprobarError $? 107
  494. else
  495. comprobarError 1 5 "$nginxConfFile"
  496. fi
  497. unset nginxConfFile
  498. }
  499. mostrarDatabase() {
  500. if [ $debianOS = true ]; then
  501. 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 \
  502. "MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" ON \
  503. "MySQL" "Instalar la base de datos MySQL (uso no comercial)" OFF \
  504. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  505. comprobarError $? 1
  506. case $database in
  507. MariaDB)
  508. mariaDBOn=true
  509. ;;
  510. MySQL)
  511. mySQLOn=true
  512. ;;
  513. *)
  514. comprobarError 1 200
  515. ;;
  516. esac
  517. elif [ $rhelOS = true ]; then
  518. 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"
  519. comprobarError $? 1
  520. mariaDBOn=true
  521. else
  522. comprobarError 1 200
  523. fi
  524. # Otras opciones (contraseña)
  525. leerSQLPasswd
  526. }
  527. leerSQLPasswd() {
  528. control=false
  529. error=""
  530. # Leemos la contreseña (stdin) y confirmamos
  531. while [ $control = false ]; do
  532. 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)
  533. comprobarError $? 1
  534. 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)
  535. comprobarError $? 1
  536. #echo -en "SQL Password 1: $sqlPasswd\n"
  537. #echo -en "SQL Password 2: $sqlPasswd2\n"
  538. if [ -z $sqlPasswd ] || [ -z $sqlPasswd2 ]; then
  539. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  540. elif [ $sqlPasswd != $sqlPasswd2 ];then
  541. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  542. else
  543. control=true
  544. fi
  545. done
  546. #echo -en "SQL Password: $sqlPasswd\n"
  547. unset control error sqlPasswd2
  548. }
  549. establecerSQLPasswd() {
  550. # Establecemos SQL root passwd y securizamos BD (mysql_secure_installation)
  551. # Comprobamos si ya tiene una contraseña asignada
  552. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  553. if [ $? -eq 0 ];then
  554. # Establecemos contraseña del usuario root
  555. mysql -e "UPDATE mysql.user SET Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1
  556. comprobarError $? 207
  557. # Desactivamos acceso root desde el exterior (solo localhost)
  558. mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" >> $logFile 2>&1
  559. comprobarError $? 208
  560. # Eliminamos todos los usuarios anónimos
  561. mysql -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1
  562. comprobarError $? 209
  563. # Eliminamos bases de datos 'test'
  564. mysql -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1
  565. comprobarError $? 210
  566. # Eliminamos privilegios de la base de datos 'test'
  567. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1
  568. comprobarError $? 211
  569. # Aplicamos los cambios
  570. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  571. comprobarError $? 212
  572. else
  573. comprobarError 1 206
  574. fi
  575. }
  576. instalarMySQL() {
  577. if [ $debianOS = true ];then
  578. result=$(apt-get -q -y install mysql-server mysql-client 2>&1)
  579. comprobarError $? 201 $result
  580. elif [ $rhelOS = true ];then
  581. # MySQL no disponible en RHEL. 2 opciones:
  582. # 1) Instalar un repositorio adicional
  583. # 2) No instalar MySQL en distribuciones RHEL
  584. comprobarError 1 205
  585. else
  586. comprobarError 1 203
  587. fi
  588. }
  589. instalarMariaDB() {
  590. if [ $debianOS = true ];then
  591. result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1)
  592. comprobarError $? 202 $result
  593. elif [ $rhelOS = true ];then
  594. result=$(yum -y install mariadb-server mariadb 2>&1)
  595. comprobarError $? 202 $result
  596. else
  597. comprobarError 1 204
  598. fi
  599. }
  600. instalarPHP() {
  601. # Instalamos PHP-7 de forma diferente si es junto a Apache o con Nginx
  602. if [ $debianOS = true ];then
  603. if [ $apacheOn = true ]; then
  604. result=$(apt-get -q -y install php libapache2-mod-php php-mysql php-intl php-mbstring openssl 2>&1)
  605. comprobarError $? 302 $result
  606. elif [ $nginxOn = true ];then
  607. result=$(apt-get -q -y install php-fpm libapache2-mod-php php-mysql php-intl php-mbstring openssl 2>&1)
  608. comprobarError $? 302 $result
  609. else
  610. comprobarError 1 301
  611. fi
  612. elif [ $rhelOS = true ];then
  613. # Necesitamos un repositorio adicional para PHP-7 (EPEL-RELEASE)
  614. result=$(yum -y install epel-release yum-utils 2>&1)
  615. comprobarError $? 103 $result
  616. # Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE)
  617. if [ ! -f /etc/yum.repos.d/remi-php72.repo ];then
  618. if [ $VERSION = "7" ];then
  619. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-7.rpm 2>&1)
  620. comprobarError $? 303 $result
  621. elif [ $VERSION = "6" ];then
  622. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-6.rpm 2>&1)
  623. comprobarError $? 303 $result
  624. elif [ $VERSION = "28" ];then
  625. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-28.rpm 2>&1)
  626. comprobarError $? 303 $result
  627. elif [ $VERSION = "27" ];then
  628. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-27.rpm 2>&1)
  629. comprobarError $? 303 $result
  630. else
  631. comprobarError 1 304
  632. fi
  633. fi
  634. # Activamos repositorio remi-php72
  635. result=$(yum-config-manager --enable remi-php72 2>&1)
  636. comprobarError $? 303 $result
  637. # Instalamos PHP-7.2
  638. if [ $apacheOn = true ];then
  639. result=$(yum -y install php php-mysql php-intl php-mbstring php-mcrypt openssl 2>&1)
  640. comprobarError $? 302 $result
  641. elif [ $nginxOn = true ];then
  642. result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt openssl 2>&1)
  643. comprobarError $? 302 $result
  644. else
  645. comprobarError 1 301
  646. fi
  647. else
  648. comprobarError 1 300
  649. fi
  650. }
  651. configurarPHP() {
  652. # Configura PHP para segurizarlo y establecer máximo de subida.
  653. if [ $debianOS = true ];then
  654. phpConfFile="./etc/php/php.ini.debian"
  655. phpDest="/etc/php/7.2/cli/php.ini"
  656. elif [ $rhelOS = true ];then
  657. phpConfFile="./etc/php/php.ini.rhel"
  658. phpDest="/etc/php.ini"
  659. fi
  660. if [ ! -f $phpConfFile ];then
  661. comprobarError 1 4 "$phpConfFile"
  662. fi
  663. # Copiamos configuración
  664. cp -f $phpConfFile $phpDest 2>/dev/null
  665. comprobarError $? 305
  666. # Configuramos cgi.fix_pathinfo
  667. sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=0' $phpDest
  668. comprobarError $? 305
  669. # Configuramos post_max_size
  670. sed -i '/post_max_size =/c\post_max_size = '$maxUpload $phpDest
  671. comprobarError $? 305
  672. # Configuramos upload_max_filesize
  673. sed -i '/upload_max_filesize =/c\upload_max_filesize = '$maxUpload $phpDest
  674. comprobarError $? 305
  675. # Configurar php-fpm (sólo en RHEL con Nginx)
  676. if [ $rhelOS = true ] && [ $nginxOn = true ];then
  677. phpConfFile="./etc/php/php-fpm.d/www.conf"
  678. phpDest="/etc/php-fpm.d/www.conf"
  679. if [ ! -f $phpConfFile ];then
  680. comprobarError $? 4 "$phpConfFile"
  681. fi
  682. cp -f $phpConfFile $phpDest 2>/dev/null
  683. comprobarError $? 305
  684. fi
  685. unset phpConfFile phpDest
  686. }
  687. establecerMaxUpload() {
  688. control=false
  689. error=""
  690. while [ $control = false ];do
  691. 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)
  692. comprobarError $? 1
  693. if [ -z $maxUpload2 ];then
  694. error="ERROR: NO PUEDES DEJAR ESTE PARÁMETRO VACIO.\n"
  695. else
  696. control=true
  697. fi
  698. done
  699. maxUpload=$maxUpload2
  700. unset control maxUpload2
  701. }
  702. instalarPHPInfo() {
  703. infoFile="./var/www/info.php"
  704. if [ ! -f $infoFile ];then
  705. comprobarError 1 4 "$infoFile"
  706. fi
  707. cp -f $infoFile /var/www/html/ 2>/dev/null
  708. comprobarError $? 106
  709. unset infoFile
  710. }
  711. habilitarServicio() {
  712. # Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
  713. # Intentamos con systemctl (SystemD)
  714. echo -en "Habilitando Servicio '$1'" | tee -a $logFile
  715. if [ $# -le 0 ];then
  716. comprobarError 1 900
  717. fi
  718. which systemctl > /dev/null 2>&1
  719. if [ $? -eq 0 ]; then
  720. echo -en " (SystemD)..." | tee -a $logFile
  721. systemctl start $1 > /dev/null 2>&1
  722. comprobarError $? 901 $1
  723. systemctl enable $1 > /dev/null 2>&1
  724. comprobarError $? 902 $1
  725. else
  726. # Intentamos con service (Upstart)
  727. which service > /dev/null 2>&1
  728. if [ $? -eq 0 ]; then
  729. echo -en " (Upstart)..." | tee -a $logFile
  730. service $1 start > /dev/null 2>&1
  731. comprobarError $? 901 $1
  732. else
  733. # Intentamos con init.d (SystemV)
  734. echo -en " (SystemV)..." | tee -a $logFile
  735. /etc/init.d/$1 start > /dev/null 2>&1
  736. comprobarError $? 901 $1
  737. fi
  738. # Intentamos habilitar en el arranque (Upstart)
  739. which update-rc.d > /dev/null 2>&1
  740. if [ $? -eq 0 ];then
  741. update-rc.d $1 enable
  742. comprobarError $? 902 $1
  743. else
  744. # Intentamos habilitar en el arranque (SystemV)
  745. which chkconfig > /dev/null 2>&1
  746. if [ $? -eq 0 ];then
  747. chkconfig $1 on
  748. comprobarError $? 902 $1
  749. else
  750. # ¿Qué mas opciones nos quedan?
  751. comprobarError 1 902 $1
  752. fi
  753. fi
  754. fi
  755. # Mejora: comprobar si el servicio está funcionando
  756. echo -en " OK.\n" | tee -a $logFile
  757. }
  758. deshabilitarServicio() {
  759. # Paramos y deshabilitamos el servicio (con SystemD, Upstart o SystemV)
  760. # Intentamos con systemctl (SystemD)
  761. echo -en "Deshabilitando Servicio '$1'" | tee -a $logFile
  762. if [ $# -le 0 ];then
  763. comprobarError 1 903
  764. fi
  765. which systemctl > /dev/null 2>&1
  766. if [ $? -eq 0 ]; then
  767. echo -en " (SystemD)..." | tee -a $logFile
  768. systemctl stop $1 > /dev/null 2>&1
  769. comprobarError $? 904 $1
  770. systemctl disable $1 > /dev/null 2>&1
  771. comprobarError $? 905 $1
  772. else
  773. # Intentamos con service (Upstart)
  774. which service > /dev/null 2>&1
  775. if [ $? -eq 0 ]; then
  776. echo -en " (Upstart)..." | tee -a $logFile
  777. service $1 stop > /dev/null 2>&1
  778. comprobarError $? 904 $1
  779. else
  780. # Intentamos con init.d (SystemV)
  781. echo -en " (SystemV)..." | tee -a $logFile
  782. /etc/init.d/$1 stop > /dev/null 2>&1
  783. comprobarError $? 904 $1
  784. fi
  785. # Intentamos habilitar en el arranque (Upstart)
  786. which update-rc.d > /dev/null 2>&1
  787. if [ $? -eq 0 ];then
  788. update-rc.d $1 disable
  789. comprobarError $? 905 $1
  790. else
  791. # Intentamos habilitar en el arranque (SystemV)
  792. which chkconfig > /dev/null 2>&1
  793. if [ $? -eq 0 ];then
  794. chkconfig $1 off
  795. comprobarError $? 905 $1
  796. else
  797. # ¿Qué mas opciones nos quedan?
  798. comprobarError 1 905 $1
  799. fi
  800. fi
  801. fi
  802. # Mejora: comprobar si el servicio está funcionando
  803. echo -en " OK.\n" | tee -a $logFile
  804. }
  805. configurarCortafuegos() {
  806. # Configuramos cortafuegos (añadir reglas y encender)
  807. # Comprobamos si estamos usando SSH
  808. esSSH $PPID
  809. if [ $debianOS = true ];then
  810. ufw allow 80/tcp >> $logFile 2>&1
  811. comprobarError $? 906 "80/tcp"
  812. if [ $sshControl = true ];then
  813. ufw allow 22/tcp >> $logFile 2>&1
  814. comprobarError $? 906 "22/tcp"
  815. fi
  816. if [ $sslOn = true ];then
  817. ufw allow 443/tcp >> $logFile 2>&1
  818. comprobarError $? 906 "443/tcp"
  819. fi
  820. ufw --force enable >> $logFile 2>&1
  821. comprobarError $? 907
  822. elif [ $rhelOS = true ];then
  823. firewall-cmd --add-port=80/tcp >> $logFile 2>&1
  824. comprobarError $? 906 "80/tcp"
  825. if [ $sshControl = true ];then
  826. firewall-cmd --add-port=22/tcp >> $logFile 2>&1
  827. comprobarError $? 906 "22/tcp"
  828. fi
  829. if [ $sslOn = true ];then
  830. firewall-cmd --add-port=443/tcp >> $logFile 2>&1
  831. comprobarError $? 906 "443/tcp"
  832. fi
  833. firewall-cmd --runtime-to-permanent >> $logFile 2>&1
  834. comprobarError $? 907
  835. habilitarServicio firewalld >> $logFile 2>&1
  836. comprobarError $? 907
  837. fi
  838. unset sshControl
  839. }
  840. esSSH() {
  841. p=${1:-$PPID}
  842. #read pid name x ppid y < <( cat /proc/$p/stat )
  843. read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
  844. [[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
  845. [ "$ppid" -le 1 ] && { sshControl=false; return 1; }
  846. esSSH $ppid
  847. }
  848. # Comprobación del sistema e inicialización
  849. inicializarVariables
  850. comprobarRoot
  851. OSInfo
  852. comprobarDependencias
  853. # Bienvenida
  854. mostrarBienvenida
  855. # Selección de componentes (express vs avanzada)
  856. mostrarExpress
  857. # Instalación Servidor Web
  858. if [ $apacheOn = true ]; then
  859. echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
  860. # {
  861. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  862. instalarApache
  863. progreso=$((progreso + 1))
  864. # } > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  865. echo -en " OK.\n" | tee -a $logFile
  866. elif [ $nginxOn = true ]; then
  867. echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
  868. # {
  869. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  870. instalarNginx
  871. progreso=$((progreso + 1))
  872. # } > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  873. echo -en " OK.\n" | tee -a $logFile
  874. fi
  875. # Instalación Base de Datos
  876. if [ $mySQLOn = true ]; then
  877. echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
  878. # {
  879. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  880. instalarMySQL
  881. progreso=$((progreso + 1))
  882. # } > >(whiptail --gauge "Instalando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  883. echo -en " OK.\n" | tee -a $logFile
  884. elif [ $mariaDBOn = true ]; then
  885. echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
  886. # {
  887. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  888. instalarMariaDB
  889. progreso=$((progreso + 1))
  890. # } > >(whiptail --gauge "Instalando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  891. echo -en " OK.\n" | tee -a $logFile
  892. fi
  893. # Instalación PHP-7.2
  894. if [ $phpOn = true ]; then
  895. echo -en "Instalando PHP-7..." | tee -a $logFile
  896. # {
  897. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  898. instalarPHP
  899. progreso=$((progreso + 1))
  900. # } > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  901. echo -en " OK.\n" | tee -a $logFile
  902. fi
  903. # Instalación SSL/TLS
  904. if [ $sslOn = true ];then
  905. echo -en "Instalando SSL/TLS..." | tee -a $logfile
  906. # {
  907. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  908. sleep 2
  909. progreso=$((progreso + 1))
  910. # } > >(whiptail --gauge "Instalando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  911. echo -en " OK.\n" | tee -a $logFile
  912. fi
  913. # Configuración Web Server
  914. if [ $apacheOn = true ];then
  915. echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
  916. # {
  917. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  918. configurarApache
  919. progreso=$((progreso + 1))
  920. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  921. echo -en " OK.\n" | tee -a $logFile
  922. elif [ $nginxOn = true ]; then
  923. echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
  924. # {
  925. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  926. configurarNginx
  927. progreso=$((progreso + 1))
  928. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  929. echo -en " OK.\n" | tee -a $logFile
  930. fi
  931. # Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
  932. if [ $mySQLOn = true ];then
  933. habilitarServicio mysql
  934. echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile
  935. # {
  936. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  937. establecerSQLPasswd
  938. progreso=$((progreso + 1))
  939. # } > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  940. echo -en " OK.\n" | tee -a $logFile
  941. elif [ $mariaDBOn = true ];then
  942. habilitarServicio mariadb
  943. echo -en "Configurando Base de Datos MariaDB..." | tee -a $logFile
  944. # {
  945. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  946. establecerSQLPasswd
  947. progreso=$((progreso + 1))
  948. # } > >(whiptail --gauge "Configurando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  949. echo -en " OK.\n" | tee -a $logFile
  950. fi
  951. # Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
  952. if [ $phpOn = true ];then
  953. echo -en "Configurando PHP-7..." | tee -a $logFile
  954. # {
  955. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  956. configurarPHP
  957. progreso=$((progreso + 1))
  958. # } > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  959. echo -en " OK.\n" | tee -a $logFile
  960. fi
  961. # Configuración SSL/TLS
  962. # Generar certificados
  963. # Configurar certificados
  964. if [ $sslOn = true ];then
  965. echo -en "Configurando SSL/TLS..." | tee -a $logFile
  966. # {
  967. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  968. sleep 2
  969. progreso=$((progreso + 1))
  970. # } > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  971. echo -en " OK.\n" | tee -a $logFile
  972. fi
  973. # MediaWiki
  974. if [ $mediaWikiOn = true ]; then
  975. # Descargar MediaWiki
  976. echo -en "Descargando MediaWiki..." | tee -a $logFile
  977. # {
  978. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  979. sleep 2
  980. progreso=$((progreso + 1))
  981. # } > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  982. echo -en " OK.\n" | tee -a $logFile
  983. # Configurar MediWiki
  984. echo -en "Configurando MediaWiki..." | tee -a $logFile
  985. # {
  986. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  987. sleep 2
  988. progreso=$((progreso + 1))
  989. # } > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  990. echo -en " OK.\n" | tee -a $logFile
  991. fi
  992. # Moodle
  993. if [ $moodleOn = true ]; then
  994. # Descargar Moodle
  995. echo -en "Descargando Moodle..." | tee -a $logFile
  996. # {
  997. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  998. sleep 2
  999. progreso=$((progreso + 1))
  1000. # } > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1001. echo -en " OK.\n" | tee -a $logFile
  1002. # Configuración Moodle
  1003. echo -en "Configurando Moodle..." | tee -a $logFile
  1004. # {
  1005. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1006. sleep 2
  1007. progreso=$((progreso + 1))
  1008. # } > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1009. echo -en " OK.\n" | tee -a $logFile
  1010. fi
  1011. # Configurar Virtual Hosts
  1012. # Instalar info.php
  1013. if [ $infoPHPOn = true ];then
  1014. echo -en "Configurando 'info.php'..." | tee -a $logFile
  1015. instalarPHPInfo
  1016. echo -en " OK.\n" | tee -a $logFile
  1017. fi
  1018. # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
  1019. # {
  1020. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1021. if [ $apacheOn = true ];then
  1022. if [ $debianOS = true ];then
  1023. habilitarServicio apache2
  1024. elif [ $rhelOS = true ];then
  1025. habilitarServicio httpd
  1026. fi
  1027. elif [ $nginxOn = true ];then
  1028. habilitarServicio nginx
  1029. if [ $phpOn = true ];then
  1030. if [ $debianOS = true ];then
  1031. habilitarServicio php7.2-fpm
  1032. elif [ $rhelOS = true ];then
  1033. habilitarServicio php-fpm
  1034. fi
  1035. fi
  1036. fi
  1037. progreso=$((progreso + 1))
  1038. # } > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1039. # Añadir reglas del cortafuegos
  1040. echo -en "Configurando Cortafuegos..." | tee -a $logFile
  1041. # {
  1042. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1043. configurarCortafuegos
  1044. progreso=$((progreso + 1))
  1045. # } > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1046. echo -en " OK.\n" | tee -a $logFile
  1047. # Configurar actualizaciones
  1048. if [ $actualizacionesOn = true ]; then
  1049. echo -en "Configurando Actualizaciones Automáticas..." | tee -a $logFile
  1050. # {
  1051. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1052. sleep 2
  1053. progreso=$((progreso + 1))
  1054. # } > >(whiptail --gauge "Configurando actualizaciones automáticas..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1055. echo -en " OK.\n" | tee -a $logFile
  1056. fi