install 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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. infoFile="./var/www/info.php"
  787. if [ ! -f $infoFile ];then
  788. comprobarError 1 4 "$infoFile"
  789. fi
  790. cp -f $infoFile /var/www/html/ 2>/dev/null
  791. comprobarError $? 106
  792. chown -R $webServerUser:$webServerGroup /var/www/html 2>/dev/null
  793. comprobarError $? 106
  794. unset infoFile
  795. # Instalar VirtualHost
  796. if [ $debianOS = true ];then
  797. virtualHost="./etc/$webServerName-debian/sites-available/phpinfo.conf"
  798. elif [ $rhelOS = true ];then
  799. virtualHost="./etc/$webServerName-rhel/sites-available/phpinfo.conf"
  800. fi
  801. instalarVirtualHost $virtualHost
  802. unset virtualHost
  803. }
  804. habilitarServicio() {
  805. # Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
  806. # Intentamos con systemctl (SystemD)
  807. #echo -en "Habilitando Servicio '$1'" | tee -a $logFile
  808. if [ $# -le 0 ];then
  809. comprobarError 1 900
  810. fi
  811. which systemctl > /dev/null 2>&1
  812. if [ $? -eq 0 ]; then
  813. #echo -en " (SystemD)..." | tee -a $logFile
  814. systemctl start $1 > /dev/null 2>&1
  815. comprobarError $? 901 $1
  816. systemctl enable $1 > /dev/null 2>&1
  817. comprobarError $? 902 $1
  818. else
  819. # Intentamos con service (Upstart)
  820. which service > /dev/null 2>&1
  821. if [ $? -eq 0 ]; then
  822. #echo -en " (Upstart)..." | tee -a $logFile
  823. service $1 start > /dev/null 2>&1
  824. comprobarError $? 901 $1
  825. else
  826. # Intentamos con init.d (SystemV)
  827. #echo -en " (SystemV)..." | tee -a $logFile
  828. /etc/init.d/$1 start > /dev/null 2>&1
  829. comprobarError $? 901 $1
  830. fi
  831. # Intentamos habilitar en el arranque (Upstart)
  832. which update-rc.d > /dev/null 2>&1
  833. if [ $? -eq 0 ];then
  834. update-rc.d $1 enable
  835. comprobarError $? 902 $1
  836. else
  837. # Intentamos habilitar en el arranque (SystemV)
  838. which chkconfig > /dev/null 2>&1
  839. if [ $? -eq 0 ];then
  840. chkconfig $1 on
  841. comprobarError $? 902 $1
  842. else
  843. # ¿Qué mas opciones nos quedan?
  844. comprobarError 1 902 $1
  845. fi
  846. fi
  847. fi
  848. # Mejora: comprobar si el servicio está parado
  849. #echo -en " OK.\n" | tee -a $logFile
  850. }
  851. deshabilitarServicio() {
  852. # Paramos y deshabilitamos el servicio (con SystemD, Upstart o SystemV)
  853. # Intentamos con systemctl (SystemD)
  854. #echo -en "Deshabilitando Servicio '$1'" | tee -a $logFile
  855. if [ $# -le 0 ];then
  856. comprobarError 1 903
  857. fi
  858. which systemctl > /dev/null 2>&1
  859. if [ $? -eq 0 ]; then
  860. #echo -en " (SystemD)..." | tee -a $logFile
  861. systemctl stop $1 > /dev/null 2>&1
  862. comprobarError $? 904 $1
  863. systemctl disable $1 > /dev/null 2>&1
  864. comprobarError $? 905 $1
  865. else
  866. # Intentamos con service (Upstart)
  867. which service > /dev/null 2>&1
  868. if [ $? -eq 0 ]; then
  869. #echo -en " (Upstart)..." | tee -a $logFile
  870. service $1 stop > /dev/null 2>&1
  871. comprobarError $? 904 $1
  872. else
  873. # Intentamos con init.d (SystemV)
  874. #echo -en " (SystemV)..." | tee -a $logFile
  875. /etc/init.d/$1 stop > /dev/null 2>&1
  876. comprobarError $? 904 $1
  877. fi
  878. # Intentamos habilitar en el arranque (Upstart)
  879. which update-rc.d > /dev/null 2>&1
  880. if [ $? -eq 0 ];then
  881. update-rc.d $1 disable
  882. comprobarError $? 905 $1
  883. else
  884. # Intentamos habilitar en el arranque (SystemV)
  885. which chkconfig > /dev/null 2>&1
  886. if [ $? -eq 0 ];then
  887. chkconfig $1 off
  888. comprobarError $? 905 $1
  889. else
  890. # ¿Qué mas opciones nos quedan?
  891. comprobarError 1 905 $1
  892. fi
  893. fi
  894. fi
  895. # Mejora: comprobar si el servicio está funcionando
  896. #echo -en " OK.\n" | tee -a $logFile
  897. }
  898. recargarServicio() {
  899. # Recargamos el servicio (con SystemD, Upstart o SystemV)
  900. # Intentamos con systemctl (SystemD)
  901. #echo -en "Recargando Servicio '$1'" | tee -a $logFile
  902. if [ $# -le 0 ];then
  903. comprobarError 1 912
  904. fi
  905. which systemctl > /dev/null 2>&1
  906. if [ $? -eq 0 ]; then
  907. #echo -en " (SystemD)..." | tee -a $logFile
  908. systemctl reload $1 > /dev/null 2>&1
  909. comprobarError $? 913 $1
  910. else
  911. # Intentamos con service (Upstart)
  912. which service > /dev/null 2>&1
  913. if [ $? -eq 0 ]; then
  914. #echo -en " (Upstart)..." | tee -a $logFile
  915. service $1 reload > /dev/null 2>&1
  916. comprobarError $? 913 $1
  917. else
  918. # Intentamos con init.d (SystemV)
  919. #echo -en " (SystemV)..." | tee -a $logFile
  920. /etc/init.d/$1 reload > /dev/null 2>&1
  921. comprobarError $? 913 $1
  922. fi
  923. fi
  924. # Mejora: comprobar si el servicio está funcionando
  925. #echo -en " OK.\n" | tee -a $logFile
  926. }
  927. configurarCortafuegos() {
  928. # Configuramos cortafuegos (añadir reglas y encender)
  929. # Comprobamos si estamos usando SSH
  930. esSSH $PPID
  931. if [ $debianOS = true ];then
  932. ufw allow 80/tcp >> $logFile 2>&1
  933. comprobarError $? 906 "80/tcp"
  934. if [ $sshControl = true ];then
  935. ufw allow 22/tcp >> $logFile 2>&1
  936. comprobarError $? 906 "22/tcp"
  937. fi
  938. if [ $sslOn = true ];then
  939. ufw allow 443/tcp >> $logFile 2>&1
  940. comprobarError $? 906 "443/tcp"
  941. fi
  942. ufw --force enable >> $logFile 2>&1
  943. comprobarError $? 907
  944. elif [ $rhelOS = true ];then
  945. firewall-cmd --add-port=80/tcp >> $logFile 2>&1
  946. comprobarError $? 906 "80/tcp"
  947. if [ $sshControl = true ];then
  948. firewall-cmd --add-port=22/tcp >> $logFile 2>&1
  949. comprobarError $? 906 "22/tcp"
  950. fi
  951. if [ $sslOn = true ];then
  952. firewall-cmd --add-port=443/tcp >> $logFile 2>&1
  953. comprobarError $? 906 "443/tcp"
  954. fi
  955. firewall-cmd --runtime-to-permanent >> $logFile 2>&1
  956. comprobarError $? 907
  957. habilitarServicio firewalld >> $logFile 2>&1
  958. comprobarError $? 907
  959. fi
  960. unset sshControl
  961. }
  962. esSSH() {
  963. p=${1:-$PPID}
  964. #read pid name x ppid y < <( cat /proc/$p/stat )
  965. read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
  966. [[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
  967. [ "$ppid" -le 1 ] && { sshControl=false; return 1; }
  968. esSSH $ppid
  969. }
  970. # Comprobación del sistema e inicialización
  971. inicializarVariables
  972. comprobarRoot
  973. OSInfo
  974. comprobarDependencias
  975. # Bienvenida
  976. mostrarBienvenida
  977. # Selección de componentes (express vs avanzada)
  978. mostrarExpress
  979. # Instalación Servidor Web
  980. if [ $apacheOn = true ]; then
  981. echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
  982. # {
  983. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  984. instalarApache
  985. progreso=$((progreso + 1))
  986. # } > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  987. echo -en " OK.\n" | tee -a $logFile
  988. elif [ $nginxOn = true ]; then
  989. echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
  990. # {
  991. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  992. instalarNginx
  993. progreso=$((progreso + 1))
  994. # } > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  995. echo -en " OK.\n" | tee -a $logFile
  996. fi
  997. # Instalación Base de Datos
  998. if [ $mySQLOn = true ]; then
  999. echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
  1000. # {
  1001. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1002. instalarMySQL
  1003. progreso=$((progreso + 1))
  1004. # } > >(whiptail --gauge "Instalando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1005. echo -en " OK.\n" | tee -a $logFile
  1006. elif [ $mariaDBOn = true ]; then
  1007. echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
  1008. # {
  1009. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1010. instalarMariaDB
  1011. progreso=$((progreso + 1))
  1012. # } > >(whiptail --gauge "Instalando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1013. echo -en " OK.\n" | tee -a $logFile
  1014. fi
  1015. # Instalación PHP-7.2
  1016. if [ $phpOn = true ]; then
  1017. echo -en "Instalando PHP-7..." | tee -a $logFile
  1018. # {
  1019. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1020. instalarPHP
  1021. progreso=$((progreso + 1))
  1022. # } > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1023. echo -en " OK.\n" | tee -a $logFile
  1024. fi
  1025. # Instalación SSL/TLS
  1026. if [ $sslOn = true ];then
  1027. echo -en "Instalando SSL/TLS..." | tee -a $logfile
  1028. # {
  1029. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1030. sleep 2
  1031. progreso=$((progreso + 1))
  1032. # } > >(whiptail --gauge "Instalando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1033. echo -en " OK.\n" | tee -a $logFile
  1034. fi
  1035. # Configuración Web Server
  1036. if [ $apacheOn = true ];then
  1037. echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
  1038. # {
  1039. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1040. configurarApache
  1041. progreso=$((progreso + 1))
  1042. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1043. echo -en " OK.\n" | tee -a $logFile
  1044. elif [ $nginxOn = true ]; then
  1045. echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
  1046. # {
  1047. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1048. configurarNginx
  1049. progreso=$((progreso + 1))
  1050. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1051. echo -en " OK.\n" | tee -a $logFile
  1052. fi
  1053. # Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
  1054. if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
  1055. habilitarServicio "$sqlServerName"
  1056. echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile
  1057. # {
  1058. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1059. establecerSQLPasswd
  1060. progreso=$((progreso + 1))
  1061. # } > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1062. echo -en " OK.\n" | tee -a $logFile
  1063. fi
  1064. # Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
  1065. if [ $phpOn = true ];then
  1066. echo -en "Configurando PHP-7..." | tee -a $logFile
  1067. # {
  1068. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1069. configurarPHP
  1070. progreso=$((progreso + 1))
  1071. # } > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1072. echo -en " OK.\n" | tee -a $logFile
  1073. fi
  1074. # Configuración SSL/TLS
  1075. # Generar certificados
  1076. # Configurar certificados
  1077. if [ $sslOn = true ];then
  1078. echo -en "Configurando SSL/TLS..." | tee -a $logFile
  1079. # {
  1080. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1081. sleep 2
  1082. progreso=$((progreso + 1))
  1083. # } > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1084. echo -en " OK.\n" | tee -a $logFile
  1085. fi
  1086. # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
  1087. # {
  1088. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1089. if [ $apacheOn = true ];then
  1090. habilitarServicio $webServerName
  1091. elif [ $nginxOn = true ];then
  1092. habilitarServicio $webServerName
  1093. if [ $phpOn = true ];then
  1094. habilitarServicio $phpFPMName
  1095. fi
  1096. fi
  1097. progreso=$((progreso + 1))
  1098. # } > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1099. # MediaWiki
  1100. if [ $mediaWikiOn = true ]; then
  1101. # Descargar MediaWiki
  1102. echo -en "Descargando MediaWiki..." | tee -a $logFile
  1103. # {
  1104. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1105. sleep 2
  1106. progreso=$((progreso + 1))
  1107. # } > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1108. echo -en " OK.\n" | tee -a $logFile
  1109. # Configurar MediWiki
  1110. echo -en "Configurando MediaWiki..." | tee -a $logFile
  1111. # {
  1112. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1113. sleep 2
  1114. progreso=$((progreso + 1))
  1115. # } > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1116. echo -en " OK.\n" | tee -a $logFile
  1117. fi
  1118. # Moodle
  1119. if [ $moodleOn = true ]; then
  1120. # Descargar Moodle
  1121. echo -en "Descargando Moodle..." | tee -a $logFile
  1122. # {
  1123. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1124. sleep 2
  1125. progreso=$((progreso + 1))
  1126. # } > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1127. echo -en " OK.\n" | tee -a $logFile
  1128. # Configuración Moodle
  1129. echo -en "Configurando Moodle..." | tee -a $logFile
  1130. # {
  1131. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1132. sleep 2
  1133. progreso=$((progreso + 1))
  1134. # } > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1135. echo -en " OK.\n" | tee -a $logFile
  1136. fi
  1137. # Configurar Virtual Hosts
  1138. # Instalar info.php
  1139. if [ $infoPHPOn = true ];then
  1140. echo -en "Configurando 'info.php'..." | tee -a $logFile
  1141. instalarPHPInfo
  1142. echo -en " OK.\n" | tee -a $logFile
  1143. fi
  1144. # Añadir reglas del cortafuegos
  1145. echo -en "Configurando Cortafuegos..." | tee -a $logFile
  1146. # {
  1147. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1148. configurarCortafuegos
  1149. progreso=$((progreso + 1))
  1150. # } > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1151. echo -en " OK.\n" | tee -a $logFile
  1152. # Configurar actualizaciones
  1153. if [ $actualizacionesOn = true ]; then
  1154. echo -en "Configurando Actualizaciones Automáticas..." | tee -a $logFile
  1155. # {
  1156. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1157. sleep 2
  1158. progreso=$((progreso + 1))
  1159. # } > >(whiptail --gauge "Configurando actualizaciones automáticas..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1160. echo -en " OK.\n" | tee -a $logFile
  1161. fi