install 33 KB

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