install 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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/apache-rhel/conf/httpd.conf"
  479. welcomeConfFile="/etc/httpd/conf.d/welcome.conf"
  480. if [ ! -f $apacheConfFile ];then
  481. comprobarError 1 4 $apacheConfFile
  482. fi
  483. cp -f $apacheConfFile /etc/httpd/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. }
  492. instalarNginx() {
  493. webServerName="nginx"
  494. if [ $debianOS = true ];then
  495. result=$(apt-get -q -y install nginx 2>&1)
  496. comprobarError $? 102 $result
  497. elif [ $rhelOS = true ]; then
  498. # Hay que instalar primero otro repositorio
  499. result=$(yum -y install epel-release)
  500. comprobarError $? 103 $result
  501. result=$(yum -y install nginx 2>&1)
  502. comprobarError $? 102 $result
  503. else
  504. comprobarError 1 105
  505. fi
  506. deshabilitarServicio $webServerName
  507. }
  508. configurarNginx() {
  509. # Configuramos Nginx
  510. rm -Rf /etc/nginx/* 2>/dev/null
  511. comprobarError $? 107
  512. if [ $debianOS = true ];then
  513. nginxConfFile="./etc/nginx-debian"
  514. elif [ $rhelOS = true ];then
  515. nginxConfFile="./etc/nginx-rhel"
  516. fi
  517. if [ -d "$nginxConfFile" ];then
  518. cp -Rf $nginxConfFile/* /etc/nginx/ 2>/dev/null
  519. comprobarError $? 107
  520. else
  521. comprobarError 1 5 "$nginxConfFile"
  522. fi
  523. unset nginxConfFile
  524. }
  525. instalarVirtualHost() {
  526. # Configuramos un Virtual Host para Apache o Nginx
  527. # Uso: instalarVirtualHost $virtualHost
  528. if [ $# -ne 1 ];then
  529. comprobarError 1 908
  530. fi
  531. webServerRoot=$(realpath "/etc/$webServerName/")
  532. virtualHost=$(realpath $1)
  533. virtualHostName=$(basename $virtualHost)
  534. if [ ! -f $virtualHost ];then
  535. comprobarError 1 909 $virtualHostName
  536. fi
  537. if [ ! -d "$webServerRoot/sites-available" ];then
  538. mkdir "$webServerRoot/sites-available" 2>/dev/null
  539. comprobarError $? 5 "$webServerRoot/sites-available"
  540. fi
  541. if [ ! -d "$webServerRoot/sites-enabled" ]; then
  542. mkdir "$webServerRoot/sites-enabled" 2>/dev/null
  543. comprobarError $? 5 "$webServerRoot/sites-enabled"
  544. fi
  545. cp -f $virtualHost "$webServerRoot/sites-available/$virtualHostName" >> $logFile 2>&1
  546. comprobarError $? 910
  547. ln -s "$webServerRoot/sites-available/$virtualHostName" "$webServerRoot/sites-enabled/$virtualHostName" >> $logFile 2>&1
  548. comprobarError $? 911 $virtualHostName
  549. recargarServicio $webServerName
  550. unset webServerRoot virtualHost virtualHostName
  551. }
  552. mostrarDatabase() {
  553. if [ $debianOS = true ]; then
  554. 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 \
  555. "MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" ON \
  556. "MySQL" "Instalar la base de datos MySQL (uso no comercial)" OFF \
  557. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  558. comprobarError $? 1
  559. case $database in
  560. MariaDB)
  561. mariaDBOn=true
  562. ;;
  563. MySQL)
  564. mySQLOn=true
  565. ;;
  566. *)
  567. comprobarError 1 200
  568. ;;
  569. esac
  570. elif [ $rhelOS = true ]; then
  571. 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"
  572. comprobarError $? 1
  573. mariaDBOn=true
  574. else
  575. comprobarError 1 200
  576. fi
  577. # Otras opciones (contraseña)
  578. leerSQLPasswd
  579. }
  580. leerSQLPasswd() {
  581. control=false
  582. error=""
  583. # Leemos la contreseña (stdin) y confirmamos
  584. while [ $control = false ]; do
  585. 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)
  586. comprobarError $? 1
  587. 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)
  588. comprobarError $? 1
  589. #echo -en "SQL Password 1: $sqlPasswd\n"
  590. #echo -en "SQL Password 2: $sqlPasswd2\n"
  591. if [ -z $sqlPasswd ] || [ -z $sqlPasswd2 ]; then
  592. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  593. elif [ $sqlPasswd != $sqlPasswd2 ];then
  594. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  595. else
  596. control=true
  597. fi
  598. done
  599. #echo -en "SQL Password: $sqlPasswd\n"
  600. unset control error sqlPasswd2
  601. }
  602. establecerSQLPasswd() {
  603. # Establecemos SQL root passwd y securizamos BD (mysql_secure_installation)
  604. # Comprobamos si ya tiene una contraseña asignada
  605. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  606. if [ $? -eq 0 ];then
  607. # Establecemos contraseña del usuario root
  608. mysql -e "UPDATE mysql.user SET Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1
  609. comprobarError $? 207
  610. # Desactivamos acceso root desde el exterior (solo localhost)
  611. mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" >> $logFile 2>&1
  612. comprobarError $? 208
  613. # Eliminamos todos los usuarios anónimos
  614. mysql -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1
  615. comprobarError $? 209
  616. # Eliminamos bases de datos 'test'
  617. mysql -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1
  618. comprobarError $? 210
  619. # Eliminamos privilegios de la base de datos 'test'
  620. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1
  621. comprobarError $? 211
  622. # Aplicamos los cambios
  623. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  624. comprobarError $? 212
  625. else
  626. comprobarError 1 206
  627. fi
  628. }
  629. instalarMySQL() {
  630. sqlServerName="mysql"
  631. if [ $debianOS = true ];then
  632. result=$(apt-get -q -y install mysql-server mysql-client 2>&1)
  633. comprobarError $? 201 $result
  634. elif [ $rhelOS = true ];then
  635. # MySQL no disponible en RHEL. 2 opciones:
  636. # 1) Instalar un repositorio adicional
  637. # 2) No instalar MySQL en distribuciones RHEL
  638. comprobarError 1 205
  639. else
  640. comprobarError 1 203
  641. fi
  642. }
  643. instalarMariaDB() {
  644. sqlServerName="mariadb"
  645. if [ $debianOS = true ];then
  646. result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1)
  647. comprobarError $? 202 $result
  648. elif [ $rhelOS = true ];then
  649. result=$(yum -y install mariadb-server mariadb 2>&1)
  650. comprobarError $? 202 $result
  651. else
  652. comprobarError 1 204
  653. fi
  654. }
  655. instalarPHP() {
  656. # Instalamos PHP-7 de forma diferente si es junto a Apache o con Nginx
  657. if [ $debianOS = true ];then
  658. phpFPMName="php7.2-fpm"
  659. if [ $apacheOn = true ]; then
  660. result=$(apt-get -q -y install php libapache2-mod-php php-mysql php-intl php-mbstring openssl 2>&1)
  661. comprobarError $? 302 $result
  662. elif [ $nginxOn = true ];then
  663. result=$(apt-get -q -y install php-fpm libapache2-mod-php php-mysql php-intl php-mbstring openssl 2>&1)
  664. comprobarError $? 302 $result
  665. else
  666. comprobarError 1 301
  667. fi
  668. elif [ $rhelOS = true ];then
  669. phpFPMName="php-fpm"
  670. # Necesitamos un repositorio adicional para PHP-7 (EPEL-RELEASE)
  671. result=$(yum -y install epel-release yum-utils 2>&1)
  672. comprobarError $? 103 $result
  673. # Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE)
  674. if [ ! -f /etc/yum.repos.d/remi-php72.repo ];then
  675. if [ $VERSION = "7" ];then
  676. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-7.rpm 2>&1)
  677. comprobarError $? 303 $result
  678. elif [ $VERSION = "6" ];then
  679. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-6.rpm 2>&1)
  680. comprobarError $? 303 $result
  681. elif [ $VERSION = "28" ];then
  682. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-28.rpm 2>&1)
  683. comprobarError $? 303 $result
  684. elif [ $VERSION = "27" ];then
  685. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-27.rpm 2>&1)
  686. comprobarError $? 303 $result
  687. else
  688. comprobarError 1 304
  689. fi
  690. fi
  691. # Activamos repositorio remi-php72
  692. result=$(yum-config-manager --enable remi-php72 2>&1)
  693. comprobarError $? 303 $result
  694. # Instalamos PHP-7.2
  695. if [ $apacheOn = true ];then
  696. result=$(yum -y install php php-mysql php-intl php-mbstring php-mcrypt openssl 2>&1)
  697. comprobarError $? 302 $result
  698. elif [ $nginxOn = true ];then
  699. result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt openssl 2>&1)
  700. comprobarError $? 302 $result
  701. else
  702. comprobarError 1 301
  703. fi
  704. else
  705. comprobarError 1 300
  706. fi
  707. deshabilitarServicio $phpFPMName
  708. }
  709. configurarPHP() {
  710. # Configura PHP para segurizarlo y establecer máximo de subida.
  711. if [ $debianOS = true ];then
  712. phpConfFile="./etc/php/php.ini.debian"
  713. phpDest="/etc/php/7.2/cli/php.ini"
  714. elif [ $rhelOS = true ];then
  715. phpConfFile="./etc/php/php.ini.rhel"
  716. phpDest="/etc/php.ini"
  717. fi
  718. if [ ! -f $phpConfFile ];then
  719. comprobarError 1 4 "$phpConfFile"
  720. fi
  721. # Copiamos configuración
  722. cp -f $phpConfFile $phpDest 2>/dev/null
  723. comprobarError $? 305
  724. # Configuramos cgi.fix_pathinfo
  725. sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=0' $phpDest
  726. comprobarError $? 305
  727. # Configuramos post_max_size
  728. sed -i '/post_max_size =/c\post_max_size = '$maxUpload $phpDest
  729. comprobarError $? 305
  730. # Configuramos upload_max_filesize
  731. sed -i '/upload_max_filesize =/c\upload_max_filesize = '$maxUpload $phpDest
  732. comprobarError $? 305
  733. # Configurar php-fpm (sólo en RHEL con Nginx)
  734. if [ $rhelOS = true ] && [ $nginxOn = true ];then
  735. phpConfFile="./etc/php/php-fpm.d/www.conf"
  736. phpDest="/etc/php-fpm.d/www.conf"
  737. if [ ! -f $phpConfFile ];then
  738. comprobarError $? 4 "$phpConfFile"
  739. fi
  740. cp -f $phpConfFile $phpDest 2>/dev/null
  741. comprobarError $? 305
  742. fi
  743. unset phpConfFile phpDest
  744. }
  745. establecerMaxUpload() {
  746. control=false
  747. error=""
  748. while [ $control = false ];do
  749. 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)
  750. comprobarError $? 1
  751. if [ -z $maxUpload2 ];then
  752. error="ERROR: NO PUEDES DEJAR ESTE PARÁMETRO VACIO.\n"
  753. else
  754. control=true
  755. fi
  756. done
  757. maxUpload=$maxUpload2
  758. unset control maxUpload2
  759. }
  760. instalarPHPInfo() {
  761. # Instalar fichero php
  762. infoFile="./var/www/info.php"
  763. if [ ! -f $infoFile ];then
  764. comprobarError 1 4 "$infoFile"
  765. fi
  766. cp -f $infoFile /var/www/html/ 2>/dev/null
  767. comprobarError $? 106
  768. unset infoFile
  769. # Instalar VirtualHost
  770. if [ $debianOS = true ];then
  771. virtualHost="./etc/$webServerName-debian/sites-available/phpinfo.conf"
  772. elif [ $rhelOS = true ];then
  773. virtualHost="./etc/$webServerName-rhel/sites-available/phpinfo.conf"
  774. fi
  775. instalarVirtualHost $virtualHost
  776. unset virtualHost
  777. }
  778. habilitarServicio() {
  779. # Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
  780. # Intentamos con systemctl (SystemD)
  781. #echo -en "Habilitando Servicio '$1'" | tee -a $logFile
  782. if [ $# -le 0 ];then
  783. comprobarError 1 900
  784. fi
  785. which systemctl > /dev/null 2>&1
  786. if [ $? -eq 0 ]; then
  787. #echo -en " (SystemD)..." | tee -a $logFile
  788. systemctl start $1 > /dev/null 2>&1
  789. comprobarError $? 901 $1
  790. systemctl enable $1 > /dev/null 2>&1
  791. comprobarError $? 902 $1
  792. else
  793. # Intentamos con service (Upstart)
  794. which service > /dev/null 2>&1
  795. if [ $? -eq 0 ]; then
  796. #echo -en " (Upstart)..." | tee -a $logFile
  797. service $1 start > /dev/null 2>&1
  798. comprobarError $? 901 $1
  799. else
  800. # Intentamos con init.d (SystemV)
  801. #echo -en " (SystemV)..." | tee -a $logFile
  802. /etc/init.d/$1 start > /dev/null 2>&1
  803. comprobarError $? 901 $1
  804. fi
  805. # Intentamos habilitar en el arranque (Upstart)
  806. which update-rc.d > /dev/null 2>&1
  807. if [ $? -eq 0 ];then
  808. update-rc.d $1 enable
  809. comprobarError $? 902 $1
  810. else
  811. # Intentamos habilitar en el arranque (SystemV)
  812. which chkconfig > /dev/null 2>&1
  813. if [ $? -eq 0 ];then
  814. chkconfig $1 on
  815. comprobarError $? 902 $1
  816. else
  817. # ¿Qué mas opciones nos quedan?
  818. comprobarError 1 902 $1
  819. fi
  820. fi
  821. fi
  822. # Mejora: comprobar si el servicio está parado
  823. #echo -en " OK.\n" | tee -a $logFile
  824. }
  825. deshabilitarServicio() {
  826. # Paramos y deshabilitamos el servicio (con SystemD, Upstart o SystemV)
  827. # Intentamos con systemctl (SystemD)
  828. echo -en "Deshabilitando Servicio '$1'" | tee -a $logFile
  829. if [ $# -le 0 ];then
  830. comprobarError 1 903
  831. fi
  832. which systemctl > /dev/null 2>&1
  833. if [ $? -eq 0 ]; then
  834. echo -en " (SystemD)..." | tee -a $logFile
  835. systemctl stop $1 > /dev/null 2>&1
  836. comprobarError $? 904 $1
  837. systemctl disable $1 > /dev/null 2>&1
  838. comprobarError $? 905 $1
  839. else
  840. # Intentamos con service (Upstart)
  841. which service > /dev/null 2>&1
  842. if [ $? -eq 0 ]; then
  843. echo -en " (Upstart)..." | tee -a $logFile
  844. service $1 stop > /dev/null 2>&1
  845. comprobarError $? 904 $1
  846. else
  847. # Intentamos con init.d (SystemV)
  848. echo -en " (SystemV)..." | tee -a $logFile
  849. /etc/init.d/$1 stop > /dev/null 2>&1
  850. comprobarError $? 904 $1
  851. fi
  852. # Intentamos habilitar en el arranque (Upstart)
  853. which update-rc.d > /dev/null 2>&1
  854. if [ $? -eq 0 ];then
  855. update-rc.d $1 disable
  856. comprobarError $? 905 $1
  857. else
  858. # Intentamos habilitar en el arranque (SystemV)
  859. which chkconfig > /dev/null 2>&1
  860. if [ $? -eq 0 ];then
  861. chkconfig $1 off
  862. comprobarError $? 905 $1
  863. else
  864. # ¿Qué mas opciones nos quedan?
  865. comprobarError 1 905 $1
  866. fi
  867. fi
  868. fi
  869. # Mejora: comprobar si el servicio está funcionando
  870. echo -en " OK.\n" | tee -a $logFile
  871. }
  872. recargarServicio() {
  873. # Recargamos el servicio (con SystemD, Upstart o SystemV)
  874. # Intentamos con systemctl (SystemD)
  875. #echo -en "Recargando Servicio '$1'" | tee -a $logFile
  876. if [ $# -le 0 ];then
  877. comprobarError 1 912
  878. fi
  879. which systemctl > /dev/null 2>&1
  880. if [ $? -eq 0 ]; then
  881. #echo -en " (SystemD)..." | tee -a $logFile
  882. systemctl reload $1 > /dev/null 2>&1
  883. comprobarError $? 913 $1
  884. else
  885. # Intentamos con service (Upstart)
  886. which service > /dev/null 2>&1
  887. if [ $? -eq 0 ]; then
  888. #echo -en " (Upstart)..." | tee -a $logFile
  889. service $1 reload > /dev/null 2>&1
  890. comprobarError $? 913 $1
  891. else
  892. # Intentamos con init.d (SystemV)
  893. #echo -en " (SystemV)..." | tee -a $logFile
  894. /etc/init.d/$1 reload > /dev/null 2>&1
  895. comprobarError $? 913 $1
  896. fi
  897. fi
  898. # Mejora: comprobar si el servicio está funcionando
  899. #echo -en " OK.\n" | tee -a $logFile
  900. }
  901. configurarCortafuegos() {
  902. # Configuramos cortafuegos (añadir reglas y encender)
  903. # Comprobamos si estamos usando SSH
  904. esSSH $PPID
  905. if [ $debianOS = true ];then
  906. ufw allow 80/tcp >> $logFile 2>&1
  907. comprobarError $? 906 "80/tcp"
  908. if [ $sshControl = true ];then
  909. ufw allow 22/tcp >> $logFile 2>&1
  910. comprobarError $? 906 "22/tcp"
  911. fi
  912. if [ $sslOn = true ];then
  913. ufw allow 443/tcp >> $logFile 2>&1
  914. comprobarError $? 906 "443/tcp"
  915. fi
  916. ufw --force enable >> $logFile 2>&1
  917. comprobarError $? 907
  918. elif [ $rhelOS = true ];then
  919. firewall-cmd --add-port=80/tcp >> $logFile 2>&1
  920. comprobarError $? 906 "80/tcp"
  921. if [ $sshControl = true ];then
  922. firewall-cmd --add-port=22/tcp >> $logFile 2>&1
  923. comprobarError $? 906 "22/tcp"
  924. fi
  925. if [ $sslOn = true ];then
  926. firewall-cmd --add-port=443/tcp >> $logFile 2>&1
  927. comprobarError $? 906 "443/tcp"
  928. fi
  929. firewall-cmd --runtime-to-permanent >> $logFile 2>&1
  930. comprobarError $? 907
  931. habilitarServicio firewalld >> $logFile 2>&1
  932. comprobarError $? 907
  933. fi
  934. unset sshControl
  935. }
  936. esSSH() {
  937. p=${1:-$PPID}
  938. #read pid name x ppid y < <( cat /proc/$p/stat )
  939. read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
  940. [[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
  941. [ "$ppid" -le 1 ] && { sshControl=false; return 1; }
  942. esSSH $ppid
  943. }
  944. # Comprobación del sistema e inicialización
  945. inicializarVariables
  946. comprobarRoot
  947. OSInfo
  948. comprobarDependencias
  949. # Bienvenida
  950. mostrarBienvenida
  951. # Selección de componentes (express vs avanzada)
  952. mostrarExpress
  953. # Instalación Servidor Web
  954. if [ $apacheOn = true ]; then
  955. echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
  956. # {
  957. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  958. instalarApache
  959. progreso=$((progreso + 1))
  960. # } > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  961. echo -en " OK.\n" | tee -a $logFile
  962. elif [ $nginxOn = true ]; then
  963. echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
  964. # {
  965. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  966. instalarNginx
  967. progreso=$((progreso + 1))
  968. # } > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  969. echo -en " OK.\n" | tee -a $logFile
  970. fi
  971. # Instalación Base de Datos
  972. if [ $mySQLOn = true ]; then
  973. echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
  974. # {
  975. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  976. instalarMySQL
  977. progreso=$((progreso + 1))
  978. # } > >(whiptail --gauge "Instalando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  979. echo -en " OK.\n" | tee -a $logFile
  980. elif [ $mariaDBOn = true ]; then
  981. echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
  982. # {
  983. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  984. instalarMariaDB
  985. progreso=$((progreso + 1))
  986. # } > >(whiptail --gauge "Instalando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  987. echo -en " OK.\n" | tee -a $logFile
  988. fi
  989. # Instalación PHP-7.2
  990. if [ $phpOn = true ]; then
  991. echo -en "Instalando PHP-7..." | tee -a $logFile
  992. # {
  993. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  994. instalarPHP
  995. progreso=$((progreso + 1))
  996. # } > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  997. echo -en " OK.\n" | tee -a $logFile
  998. fi
  999. # Instalación SSL/TLS
  1000. if [ $sslOn = true ];then
  1001. echo -en "Instalando SSL/TLS..." | tee -a $logfile
  1002. # {
  1003. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1004. sleep 2
  1005. progreso=$((progreso + 1))
  1006. # } > >(whiptail --gauge "Instalando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1007. echo -en " OK.\n" | tee -a $logFile
  1008. fi
  1009. # Configuración Web Server
  1010. if [ $apacheOn = true ];then
  1011. echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
  1012. # {
  1013. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1014. configurarApache
  1015. progreso=$((progreso + 1))
  1016. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1017. echo -en " OK.\n" | tee -a $logFile
  1018. elif [ $nginxOn = true ]; then
  1019. echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
  1020. # {
  1021. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1022. configurarNginx
  1023. progreso=$((progreso + 1))
  1024. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1025. echo -en " OK.\n" | tee -a $logFile
  1026. fi
  1027. # Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
  1028. if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
  1029. habilitarServicio "sqlServerName"
  1030. echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile
  1031. # {
  1032. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1033. establecerSQLPasswd
  1034. progreso=$((progreso + 1))
  1035. # } > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1036. echo -en " OK.\n" | tee -a $logFile
  1037. fi
  1038. # Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
  1039. if [ $phpOn = true ];then
  1040. echo -en "Configurando PHP-7..." | tee -a $logFile
  1041. # {
  1042. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1043. configurarPHP
  1044. progreso=$((progreso + 1))
  1045. # } > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1046. echo -en " OK.\n" | tee -a $logFile
  1047. fi
  1048. # Configuración SSL/TLS
  1049. # Generar certificados
  1050. # Configurar certificados
  1051. if [ $sslOn = true ];then
  1052. echo -en "Configurando SSL/TLS..." | tee -a $logFile
  1053. # {
  1054. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1055. sleep 2
  1056. progreso=$((progreso + 1))
  1057. # } > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1058. echo -en " OK.\n" | tee -a $logFile
  1059. fi
  1060. # MediaWiki
  1061. if [ $mediaWikiOn = true ]; then
  1062. # Descargar MediaWiki
  1063. echo -en "Descargando MediaWiki..." | tee -a $logFile
  1064. # {
  1065. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1066. sleep 2
  1067. progreso=$((progreso + 1))
  1068. # } > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1069. echo -en " OK.\n" | tee -a $logFile
  1070. # Configurar MediWiki
  1071. echo -en "Configurando MediaWiki..." | tee -a $logFile
  1072. # {
  1073. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1074. sleep 2
  1075. progreso=$((progreso + 1))
  1076. # } > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1077. echo -en " OK.\n" | tee -a $logFile
  1078. fi
  1079. # Moodle
  1080. if [ $moodleOn = true ]; then
  1081. # Descargar Moodle
  1082. echo -en "Descargando Moodle..." | tee -a $logFile
  1083. # {
  1084. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1085. sleep 2
  1086. progreso=$((progreso + 1))
  1087. # } > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1088. echo -en " OK.\n" | tee -a $logFile
  1089. # Configuración Moodle
  1090. echo -en "Configurando Moodle..." | tee -a $logFile
  1091. # {
  1092. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1093. sleep 2
  1094. progreso=$((progreso + 1))
  1095. # } > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1096. echo -en " OK.\n" | tee -a $logFile
  1097. fi
  1098. # Configurar Virtual Hosts
  1099. # Instalar info.php
  1100. if [ $infoPHPOn = true ];then
  1101. echo -en "Configurando 'info.php'..." | tee -a $logFile
  1102. instalarPHPInfo
  1103. echo -en " OK.\n" | tee -a $logFile
  1104. fi
  1105. # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
  1106. # {
  1107. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1108. if [ $apacheOn = true ];then
  1109. habilitarServicio $webServerName
  1110. elif [ $nginxOn = true ];then
  1111. habilitarServicio $webServerName
  1112. if [ $phpOn = true ];then
  1113. habilitarServicio $phpFPMName
  1114. fi
  1115. fi
  1116. progreso=$((progreso + 1))
  1117. # } > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1118. # Añadir reglas del cortafuegos
  1119. echo -en "Configurando Cortafuegos..." | tee -a $logFile
  1120. # {
  1121. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1122. configurarCortafuegos
  1123. progreso=$((progreso + 1))
  1124. # } > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1125. echo -en " OK.\n" | tee -a $logFile
  1126. # Configurar actualizaciones
  1127. if [ $actualizacionesOn = true ]; then
  1128. echo -en "Configurando Actualizaciones Automáticas..." | tee -a $logFile
  1129. # {
  1130. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1131. sleep 2
  1132. progreso=$((progreso + 1))
  1133. # } > >(whiptail --gauge "Configurando actualizaciones automáticas..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1134. echo -en " OK.\n" | tee -a $logFile
  1135. fi