install 36 KB

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