install 37 KB

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