install 36 KB

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