install 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  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. 6)
  44. error="$type $codeNum:\tError interno (selección SSL/TLS).\n"
  45. ;;
  46. 100)
  47. error="$type $codeNum:\tError interno (selección del servidor web).\n"
  48. ;;
  49. 101)
  50. error="\n$type $codeNum:\tError al instalar Apache2.\nDetalles:\n$extraInfo\n"
  51. ;;
  52. 102)
  53. error="\n$type $codeNum:\tError al instalar Nginx.\nDetalles:\n$extraInfo\n"
  54. ;;
  55. 103)
  56. error="\n$type $codeNum:\tError al nstalar repositorio 'epel-release'.\nDetalles:\n$extraInfo\n"
  57. ;;
  58. 104)
  59. error="\n$type $codeNum:\tError interno (instalación Apache2).\n"
  60. ;;
  61. 105)
  62. error="\n$type $codeNum:\tError interno (instalación Nginx).\n"
  63. ;;
  64. 106)
  65. type="WARNING"
  66. error="\n$type $codeNum:\tImposible instalar 'info.php'.\n"
  67. ;;
  68. 107)
  69. error="\n$type $codeNum:\tError al configurar Nginx.\n"
  70. ;;
  71. 108)
  72. error="\n$type $codeNum:\tError al configurar Apache2.\n"
  73. ;;
  74. 200)
  75. error="$type $codeNum:\tError interno (selección de base de datos).\n"
  76. ;;
  77. 201)
  78. error="\n$type $codeNum:\tError al instalar MySQL.\nDetalles:\n$extraInfo\n"
  79. ;;
  80. 202)
  81. error="\n$type $codeNum:\tError al instalar MariaDB.\nDetalles:\n$extraInfo\n"
  82. ;;
  83. 203)
  84. error="\n$type $codeNum:\tError interno (instalación MySQL).\n"
  85. ;;
  86. 204)
  87. error="\n$type $codeNum:\tError interno (instalación MariaDB).\n"
  88. ;;
  89. 205)
  90. error="\n$type $codeNum:\t$DIST no incluye MySQL en sus repositorios.\n"
  91. ;;
  92. 206)
  93. type="WARNING"
  94. error="\n$type $codeNum:\tUsuario 'root' ya dispone de contraseña."
  95. ;;
  96. 207)
  97. error="\n$type $codeNum:\tImposible cambiar la contraseña de 'root'."
  98. ;;
  99. 208)
  100. error="\n$type $codeNum:\tImposible desactivar acceso 'root' desde el exterior."
  101. ;;
  102. 209)
  103. error="\n$type $codeNum:\tImposible eliminar usuarios anónimos."
  104. ;;
  105. 210)
  106. type="WARNING"
  107. error="\n$type $codeNum:\tImposible eliminar bases de datos de pruebas."
  108. ;;
  109. 211)
  110. type="WARNING"
  111. error="\n$type $codeNum:\tImposible eliminar los permisos de las bases de datos de pruebas."
  112. ;;
  113. 212)
  114. error="\n$type $codeNum:\tImposible recargar base de datos."
  115. ;;
  116. 300)
  117. error="\n$type $codeNum:\tError interno (instalación PHP-7.2).\n"
  118. ;;
  119. 301)
  120. error="\n$type $codeNum:\tError interno (Web Server no seleccionado).\n"
  121. ;;
  122. 302)
  123. error="\n$type $codeNum:\tError al instalar PHP-7.2.\nDetalles:\n$extraInfo\n"
  124. ;;
  125. 303)
  126. error="\n$type $codeNum:\tError al instalar Repositorio Remi.\nDetalles:\n$extraInfo\n"
  127. ;;
  128. 304)
  129. error="\n$type $codeNum:\tSistema Operativo no compatible con PHP-7.2 ($OS $DIST $REV).\n"
  130. ;;
  131. 305)
  132. error="\n$type $codeNum:\tImposible configurar PHP-7.2.\n"
  133. ;;
  134. 501)
  135. error="\n$type $codeNum:\tImposible descargar MediaWiki-1.31.0.\n"
  136. ;;
  137. 502)
  138. error="\n$type $codeNum:\tImposible configurar MediaWiki-1.31.0.\n"
  139. ;;
  140. 503)
  141. type="WARNING"
  142. error="\n$type $codeNum:\tYa existe una copia configurada de MediaWiki en el dominio: '$extraInfo'."
  143. ;;
  144. 601)
  145. error="\n$type $codeNum:\tImposible descargar Moodle-3.5.1.\n"
  146. ;;
  147. 800)
  148. error="$type $codeNum:\tEs necesario ser root ('sudo $0').\n"
  149. ;;
  150. 801)
  151. error="$type $codeNum:\t'whiptail' no instalado.\n"
  152. ;;
  153. 802)
  154. error="$type $codeNum:\t'hostnamectl' no instalado.\n"
  155. ;;
  156. 803)
  157. error="$type $codeNum:\t'apt-get' no instalado.\n"
  158. ;;
  159. 804)
  160. error="$type $codeNum:\t'yum' no instalado.\n"
  161. ;;
  162. 805)
  163. error="\n$type $codeNum:\tImposible actualizar repositorio\nDetalles:\n$extraInfo.\n"
  164. ;;
  165. 806)
  166. error="$type $codeNum:\t'ufw' no instalado.\n"
  167. ;;
  168. 807)
  169. error="$type $codeNum:\t'firewall-cmd' no instalado.\n"
  170. ;;
  171. 808)
  172. error="$type $codeNum:\t'tput' no instalado.\nDetalles:\n$extraInfo\n"
  173. ;;
  174. 809)
  175. error="$type $codeNum:\t'sed' no instalado.\nDetalles:\n$extraInfo\n"
  176. ;;
  177. 810)
  178. error="$type $codeNum:\t'curl' no instalado.\nDetalles:\n$extraInfo\n"
  179. ;;
  180. 811)
  181. error="$type $codeNum:\t'tar' no instalado.\nDetalles:\n$extraInfo\n"
  182. ;;
  183. 812)
  184. error="$type $codeNum:\t'gzip' no instalado.\nDetalles:\n$extraInfo\n"
  185. ;;
  186. 813)
  187. error="$type $codeNum:\t'bzip2' no instalado.\nDetalles:\n$extraInfo\n"
  188. ;;
  189. 814)
  190. error="$type $codeNum:\t'xz' no instalado.\nDetalles:\n$extraInfo\n"
  191. ;;
  192. 815)
  193. error="$type $codeNum:\t'openssl' no instalado.\nDetalles:\n$extraInfo\n"
  194. ;;
  195. 816)
  196. error="$type $codeNum:\t'find' no instalado.\n"
  197. ;;
  198. 900)
  199. error="$type $codeNum:\tError interno (habilitar servicio).\n"
  200. ;;
  201. 901)
  202. error="$type $codeNum:\tImposible encender servicio '$extraInfo'.\n"
  203. ;;
  204. 902)
  205. error="$type $codeNum:\tImposible habilitar servicio '$extraInfo' durante el arranque.\n"
  206. ;;
  207. 903)
  208. error="$type $codeNum:\tError interno (deshabilitar servicio).\n"
  209. ;;
  210. 904)
  211. error="$type $codeNum:\tImposible parar servicio '$extraInfo'.\n"
  212. ;;
  213. 905)
  214. error="$type $codeNum:\tImposible deshabilitar servicio '$extraInfo' durante el arranque.\n"
  215. ;;
  216. 906)
  217. type="WARNING"
  218. error="\n$type $codeNum:\tImposible añadir regla al cortafuegos ('$extraInfo').\n"
  219. ;;
  220. 907)
  221. type="WARNING"
  222. error="\n$type $codeNum:\tImposible encender cortafuegos.\n"
  223. ;;
  224. 908)
  225. error="\n$type $codeNum:\tError interno (instalar Virtual Host).\n"
  226. ;;
  227. 909)
  228. error="\n$type $codeNum:\tVirtual Host '$extraInfo' no existe.\n"
  229. ;;
  230. 910)
  231. error="\n$type $codeNum:\tImposible copiar Virtual Host '$extraInfo'.\n"
  232. ;;
  233. 911)
  234. error="\n$type $codeNum:\tImposible activar Virtual Host '$extraInfo'.\n"
  235. ;;
  236. 912)
  237. error="\n$type $codeNum:\tError interno (recargar servicio).\n"
  238. ;;
  239. 913)
  240. error="\n$type $codeNum:\tImposible recargar servicio '$extraInfo'.\n"
  241. ;;
  242. *)
  243. error="ERROR 13:\tError interno (comprobación de errores)\n"
  244. exitNum=1
  245. codeNum=13
  246. ;;
  247. esac
  248. if [ $exitNum -ne 0 ];then
  249. echo -en "$error" | tee -a $logFile
  250. if [ $type = "ERROR" ];then
  251. exit $codeNum
  252. fi
  253. fi
  254. unset error exitNum codeNum type
  255. }
  256. OSInfo() {
  257. echo -en "Detectando SO..." >> $logFile
  258. OS=$(uname -s)
  259. if [ $OS = "Linux" ]; then
  260. OS="GNU/Linux"
  261. if [ -f /etc/os-release ]; then
  262. DIST=$(grep ^NAME= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  263. REV=$(grep ^VERSION= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  264. ID_LIKE=$(grep ^ID_LIKE= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  265. VERSION=$(grep ^VERSION_ID= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  266. for i in $ID_LIKE; do
  267. #echo -en "$i\n"
  268. case $i in
  269. debian|ubuntu)
  270. debianOS=true
  271. break
  272. ;;
  273. rhel|fedora)
  274. rhelOS=true
  275. break
  276. ;;
  277. *)
  278. debianOS=false
  279. rhelOS=false
  280. ;;
  281. esac
  282. done
  283. elif [ -f /etc/debian-version ]; then
  284. # Familia Debian (Debian, Ubuntu, Linux Mint, ...)
  285. DIST="Debian"
  286. REV=""
  287. ID_LIKE="debian"
  288. VERSION=""
  289. debianOS=true
  290. elif [ -f /etc/redhat-release ]; then
  291. # Familia Red-Hat (RHEL, Fedora, CentOS, ...)
  292. DIST="Red-Hat"
  293. REV=""
  294. ID_LIKE="rhel"
  295. VERSION=""
  296. rhelOS=true
  297. else
  298. # Other Linux (No Soportado)
  299. DIST=""
  300. REV=""
  301. ID_LIKE=""
  302. VERSION=""
  303. fi
  304. else
  305. # UNIX, OS X, ... (No Soportado)
  306. DIST=$OS
  307. REV=""
  308. ID_LIKE=""
  309. VERSION=""
  310. fi
  311. echo -en " $OS $DIST $REV\n" >> $logFile
  312. HDInfo=$(df -h | head -1)"\n"$(df -h | grep ^/dev/sd)"\n"$(df -h | grep ^/dev/mapper)
  313. echo -en "$HDInfo\n" >> $logFile
  314. }
  315. comprobarRoot() {
  316. comprobarError $(id -u) 800
  317. }
  318. comprobarDependencias() {
  319. # Comprobamos whiptail
  320. which whiptail > /dev/null 2>&1
  321. comprobarError $? 801
  322. # Comprobamos hostnamectl
  323. which hostnamectl > /dev/null 2>&1
  324. comprobarError $? 802
  325. which find > /dev/null 2>&1
  326. comprobarError $? 816
  327. if [ $debianOS = true ];then
  328. # Comprobamos apt-get
  329. which apt-get > /dev/null 2>&1
  330. comprobarError $? 803
  331. # Actualizamos base de datos del repositorio
  332. echo -en "Actualizando repositorio APT..." | tee -a $logFile
  333. result=$(apt-get -q -y update 2>&1)
  334. comprobarError $? 805 $result
  335. echo -en " OK.\n" | tee -a $logFile
  336. # Comprobamos Firewall (ufw)
  337. which ufw > /dev/null 2>&1
  338. comprobarError $? 806
  339. # Comprobamos tput
  340. which tput > /dev/null 2>&1
  341. if [ $? -ne 0 ];then
  342. result=$(apt-get -q -y ncurses-bin 2>&1)
  343. comprobarError $? 808 $result
  344. fi
  345. # Comprobar sed
  346. which sed > /dev/null 2>&1
  347. if [ $? -ne 0 ];then
  348. result=$(apt-get -q -y sed 2>&1)
  349. comprobarError $? 809 $result
  350. fi
  351. # Comprobar curl
  352. which curl > /dev/null 2>&1
  353. if [ $? -ne 0 ];then
  354. result=$(apt-get -q -y curl 2>&1)
  355. comprobarError $? 810 $result
  356. fi
  357. # Comprobamos tar, gzip, bzip2 y xz
  358. which tar > /dev/null 2>&1
  359. if [ $? -ne 0 ];then
  360. result=$(apt-get -q -y install tar 2>&1)
  361. comprobarError $? 811 $result
  362. fi
  363. which gzip > /dev/null 2>&1
  364. if [ $? -ne 0 ];then
  365. result=$(apt-get -q -y install gzip 2>&1)
  366. comprobarError $? 812 $result
  367. fi
  368. which bzip2 > /dev/null 2>&1
  369. if [ $? -ne 0 ];then
  370. result=$(apt-get -q -y install bzip2 2>&1)
  371. comprobarError $? 813 $result
  372. fi
  373. which xz > /dev/null 2>&1
  374. if [ $? -ne 0 ];then
  375. result=$(apt-get -q -y install xz-utils 2>&1)
  376. comprobarError $? 814 $result
  377. fi
  378. which openssl > /dev/null 2>&1
  379. if [ $? -ne 0 ];then
  380. result=$(apt-get -q -y install openssl 2>&1)
  381. comprobarError $? 815 $result
  382. fi
  383. fi
  384. if [ $rhelOS = true ]; then
  385. # Comprobamos yum
  386. which yum > /dev/null 2>&1
  387. comprobarError $? 804
  388. # Actualizamos base de datos del repositorio
  389. echo -en "Actualizando repositorio YUM..." | tee -a $logFile
  390. result=$(yum -y makecache 2>&1)
  391. comprobarError $? 805 $result
  392. echo -en " OK.\n" | tee -a $logFile
  393. # Comprobamos Firewall (firewall-cmd)
  394. which firewall-cmd > /dev/null 2>&1
  395. comprobarError $? 807
  396. # Comprobamos tput
  397. which tput > /dev/null 2>&1
  398. if [ $? -ne 0 ];then
  399. result=$(yum -y ncurses 2>&1)
  400. comprobarError $? 808 $result
  401. fi
  402. # Comprobar sed
  403. which sed > /dev/null 2>&1
  404. if [ $? -ne 0 ];then
  405. result=$(yum -y sed 2>&1)
  406. comprobarError $? 809 $result
  407. fi
  408. # Comprobar curl
  409. which curl > /dev/null 2>&1
  410. if [ $? -ne 0 ];then
  411. result=$(yum -y curl 2>&1)
  412. comprobarError $? 810 $result
  413. fi
  414. # Comprobamos tar, gzip, bzip2 y xz
  415. which tar > /dev/null 2>&1
  416. if [ $? -ne 0 ];then
  417. result=$(yum -y install tar 2>&1)
  418. comprobarError $? 811 $result
  419. fi
  420. which gzip > /dev/null 2>&1
  421. if [ $? -ne 0 ];then
  422. result=$(yum -y install gzip 2>&1)
  423. comprobarError $? 812 $result
  424. fi
  425. which bzip2 > /dev/null 2>&1
  426. if [ $? -ne 0 ];then
  427. result=$(yum -y install bzip2 2>&1)
  428. comprobarError $? 813 $result
  429. fi
  430. which xz > /dev/null 2>&1
  431. if [ $? -ne 0 ];then
  432. result=$(yum -y install xz 2>&1)
  433. comprobarError $? 814 $result
  434. fi
  435. which openssl > /dev/null 2>&1
  436. if [ $? -ne 0 ];then
  437. result=$(yum -y install openssl 2>&1)
  438. comprobarError $? 815 $result
  439. fi
  440. fi
  441. }
  442. inicializarVariables() {
  443. debianOS=false
  444. rhelOS=false
  445. apacheOn=false
  446. nginxOn=false
  447. mySQLOn=false
  448. mariaDBOn=false
  449. phpOn=false
  450. sslOn=false
  451. letsEncryptOn=false
  452. mediaWikiOn=false
  453. moodleOn=false
  454. infoPHPOn=false
  455. actualizacionesOn=false
  456. progreso=0
  457. progresoTotal=0
  458. hostname=""
  459. logFile="./."$(basename $0)".log"
  460. maxUpload="100M"
  461. webServerName=""
  462. webServerUser=""
  463. webServerGroup=""
  464. sqlServerName=""
  465. phpFPMName=""
  466. nombreMediaWiki=""
  467. dominioMediaWiki=""
  468. }
  469. instalacionExpress() {
  470. apacheOn=true
  471. mariaDBOn=true
  472. phpOn=true
  473. sslOn=true
  474. letsEncryptOn=true
  475. mediaWikiOn=true
  476. moodleOn=true
  477. actualizacionesOn=true
  478. progresoTotal=15
  479. # Preguntas mínimas
  480. establecerFQDN
  481. leerSQLPasswd
  482. mostrarMediaWiki
  483. }
  484. mostrarBienvenida() {
  485. ANCHO=$(tput cols)
  486. ALTO=$(tput lines)
  487. if [ $debianOS = false ] && [ $rhelOS = false ]; then
  488. 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"
  489. exit 1
  490. fi
  491. 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"
  492. comprobarError $? 1
  493. }
  494. mostrarExpress() {
  495. 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 \
  496. "Express" "Instalación rápida" ON \
  497. "Avanzada" "Permite escoger todas las opciones disponibles" OFF \
  498. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  499. comprobarError $? 1
  500. case $express in
  501. Express)
  502. instalacionExpress
  503. # DECIDIR QUÉ OPCIONES SON LAS MÍNIMAS
  504. ;;
  505. Avanzada)
  506. mostrarAvanzada
  507. ;;
  508. *)
  509. comprobarError 1 2
  510. ;;
  511. esac
  512. unset express
  513. }
  514. mostrarAvanzada() {
  515. 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 \
  516. "LAMP" "GNU/Linux + Apache + MySQL/MariaDB + PHP-7" ON \
  517. "LEMP" "GNU/Linux + Nginx + MySQL/MariaDB + PHP-7" OFF \
  518. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  519. comprobarError $? 1
  520. for i in $webServer; do
  521. case $i in
  522. LAMP)
  523. apacheOn=true
  524. ;;
  525. LEMP)
  526. nginxOn=true
  527. ;;
  528. *)
  529. comprobarError 1 100
  530. ;;
  531. esac
  532. done
  533. # Opciones comunes
  534. establecerFQDN
  535. mostrarDatabase
  536. phpOn=true
  537. establecerMaxUpload
  538. progresoTotal=$((progresoTotal + 6))
  539. mostrarComponentes
  540. unset webServer
  541. }
  542. mostrarComponentes() {
  543. 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 \
  544. "SSL/TLS" "Instalar certificados para activar HTTPS" ON \
  545. "MediaWiki" "Instalar wiki con MediaWiki" ON \
  546. "Moodle" "Instalar campus virtual con Moodle" ON \
  547. "InfoPHP" "Instalar info.php (sólo para pruebas)" OFF \
  548. "Actualizaciones" "Programar actualizaciones automáticas" ON \
  549. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  550. comprobarError $? 1
  551. # Mejora: autodetección de componentes ya instalados
  552. for i in $componentes; do
  553. case $i in
  554. \"SSL/TLS\")
  555. # 2 Opciones: Let's Encrypt o Autofirmado
  556. mostrarSSL
  557. progresoTotal=$((progresoTotal + 2))
  558. ;;
  559. \"MediaWiki\")
  560. mediaWikiOn=true
  561. mostrarMediaWiki
  562. progresoTotal=$((progresoTotal + 2))
  563. ;;
  564. \"Moodle\")
  565. moodleOn=true
  566. progresoTotal=$((progresoTotal + 2))
  567. ;;
  568. \"InfoPHP\")
  569. infoPHPOn=true
  570. progresoTotal=$((progresoTotal + 2))
  571. ;;
  572. \"Actualizaciones\")
  573. actualizacionesOn=true
  574. progresoTotal=$((progresoTotal + 1))
  575. ;;
  576. *)
  577. comprobarError 1 3
  578. ;;
  579. esac
  580. done
  581. progresoTotal=$((progresoTotal + 2))
  582. unset componentes
  583. }
  584. mostrarSSL() {
  585. ssl=$(whiptail --title "INSTALACION SSL/TLS" --radiolist "<ESPACIO>: seleccionar <TAB>: cambiar <FLECHAS>: moverse\n\nEscoge el tipo de Certificado SSL/TLS que quieres instalar:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \
  586. "LetsEncrypt" "Compatible con todos los navegadores" ON \
  587. "Auto-Firmado" "Certificados auto-firmados (sólo para pruebas)" OFF \
  588. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  589. comprobarError $? 1
  590. for i in $ssl; do
  591. case $i in
  592. LetsEncrypt)
  593. sslOn=true
  594. letsEcnryptOn=true
  595. ;;
  596. Auto-Firmados)
  597. sslOn=true
  598. ;;
  599. *)
  600. comprobarError 1 6
  601. ;;
  602. esac
  603. done
  604. unset ssl
  605. }
  606. mostrarMediaWiki(){
  607. # Introducir nombre wiki
  608. while [ -z "$nombreMediaWiki" ]; do
  609. nombreMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --inputbox "Introduzca el nombre de la Wiki:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  610. comprobarError $? 1
  611. # Mejora: comprobar si el dominio ya está en uso
  612. done
  613. # Introducir dominio
  614. while [ -z "$dominioMediaWiki" ]; do
  615. dominioMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --inputbox "Introduzca el dominio/subdominio de la Wiki.\nTenga en cuenta que debes apuntar este dominio a la dirección IP de esta máquina mediante un registro DNS de tipo CNAME.\nSi quiere introducir varios dominios sepárelos con espacios. El primero será el principal.\nPor ejemplo: 'www.$hostname $hostname wiki.$hostname'" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) wiki.$hostname --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  616. comprobarError $? 1
  617. # Mejora: comprobar si el dominio ya está en uso
  618. done
  619. cont=1
  620. serverName=""
  621. aliasMediaWiki=""
  622. for dominio in $dominioMediaWiki;do
  623. if [ $cont -eq 1 ];then
  624. # Dominio Principal (ServerName)
  625. serverName=$dominio
  626. else
  627. # Dominios Secundarios (ServerAlias)
  628. aliasMediaWiki=$aliasMediaWiki" "$dominio
  629. fi
  630. cont=$((cont + 1))
  631. done
  632. dominioMediaWiki=$serverName
  633. # Introducir contraseña
  634. control=false
  635. error=""
  636. while [ $control = false ]; do
  637. passwdMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --passwordbox "$error""Introduzca la contraseña para el usuario administrador 'admin':" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
  638. comprobarError $? 1
  639. passwdMediaWiki2=$(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)
  640. comprobarError $? 1
  641. if [ -z "$passwdMediaWiki" ] || [ -z "$passwdMediaWiki2" ]; then
  642. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  643. elif [ $passwdMediaWiki != $passwdMediaWiki2 ];then
  644. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  645. else
  646. control=true
  647. fi
  648. done
  649. unset control error passwdMediaWiki2 cont serverName
  650. }
  651. establecerFQDN() {
  652. while [ -z "$hostname" ]; do
  653. 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)
  654. if [ $? -eq 0 ] && [ ! -z "$hostname" ]; then
  655. hostnamectl set-hostname $hostname
  656. else
  657. hostname=$(hostname)
  658. fi
  659. done
  660. echo -en "Hostname: $hostname\n" >> $logFile
  661. }
  662. instalarApache() {
  663. if [ $debianOS = true ];then
  664. webServerName="apache2"
  665. result=$(apt-get -q -y install apache2 2>&1)
  666. comprobarError $? 101 $result
  667. elif [ $rhelOS = true ]; then
  668. webServerName="httpd"
  669. result=$(yum -y install httpd 2>&1)
  670. comprobarError $? 101 $result
  671. else
  672. comprobarError 1 104
  673. fi
  674. deshabilitarServicio $webServerName
  675. }
  676. configurarApache() {
  677. if [ $debianOS = true ];then
  678. apacheConfFile="./etc/apache2/apache2.conf"
  679. if [ ! -f $apacheConfFile ];then
  680. comprobarError 1 4 $apacheConfFile
  681. fi
  682. cp -f $apacheConfFile /etc/$webServerName/apache2.conf 2>/dev/null
  683. comprobarError $? 108
  684. webServerUser=$(grep ^User /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
  685. webServerGroup=$(grep ^Group /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
  686. if [ ! -L /etc/$webServerName/logs ];then
  687. ln -s /var/log/apache2 /etc/$webServerName/logs 2>/dev/null
  688. comprobarError $? 108
  689. fi
  690. elif [ $rhelOS = true ];then
  691. apacheConfFile="./etc/apache2/conf/httpd.conf"
  692. welcomeConfFile="/etc/apache2/conf.d/welcome.conf"
  693. if [ ! -f $apacheConfFile ];then
  694. comprobarError 1 4 $apacheConfFile
  695. fi
  696. cp -f $apacheConfFile /etc/$webServerName/conf/httpd.conf 2>/dev/null
  697. comprobarError $? 108
  698. if [ -f $welcomeConfFile ];then
  699. sed -i -e 's/^/#/' $welcomeConfFile
  700. comprobarError $? 108
  701. fi
  702. webServerUser=$(grep ^User /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
  703. webServerGroup=$(grep ^Group /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
  704. unset apacheConfFile welcomeConfFile
  705. fi
  706. if [ ! -d "/etc/$webServerName/sites-available" ];then
  707. mkdir "/etc/$webServerName/sites-available" 2>/dev/null
  708. comprobarError $? 5 "/etc/$webServerName/sites-available"
  709. fi
  710. if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
  711. mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
  712. comprobarError $? 5 "/etc/$webServerName/sites-enabled"
  713. else
  714. # Eliminar Virtual Host por defecto
  715. if [ -f /etc/$webServerName/sites-enabled/000-default.conf ];then
  716. rm -f /etc/$webServerName/sites-enabled/000-default.conf 2>/dev/null
  717. fi
  718. fi
  719. }
  720. instalarNginx() {
  721. webServerName="nginx"
  722. if [ $debianOS = true ];then
  723. result=$(apt-get -q -y install nginx 2>&1)
  724. comprobarError $? 102 $result
  725. elif [ $rhelOS = true ]; then
  726. # Hay que instalar primero otro repositorio
  727. result=$(yum -y install epel-release)
  728. comprobarError $? 103 $result
  729. result=$(yum -y install nginx 2>&1)
  730. comprobarError $? 102 $result
  731. else
  732. comprobarError 1 105
  733. fi
  734. deshabilitarServicio $webServerName
  735. }
  736. configurarNginx() {
  737. # Configuramos Nginx
  738. rm -Rf /etc/$webServerName/* 2>/dev/null
  739. comprobarError $? 107
  740. nginxConfFile="./etc/$webServerName"
  741. if [ -d "$nginxConfFile" ];then
  742. cp -Rf $nginxConfFile/* /etc/$webServerName/ 2>/dev/null
  743. comprobarError $? 107
  744. else
  745. comprobarError 1 5 "$nginxConfFile"
  746. fi
  747. if [ ! -d "/etc/$webServerName/sites-available" ];then
  748. mkdir "/etc/$webServerName/sites-available" 2>/dev/null
  749. comprobarError $? 5 "/etc/$webServerName/sites-available"
  750. fi
  751. if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
  752. mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
  753. comprobarError $? 5 "/etc/$webServerName/sites-enabled"
  754. fi
  755. # Configuramos Usuario y Grupo
  756. if [ $debianOS = true ];then
  757. webServerUser="www-data"
  758. webServerGroup=$webServerUser
  759. elif [ $rhelOS = true ];then
  760. webServerUser="nginx"
  761. webServerGroup=$webServerUser
  762. fi
  763. sed -i '/user /c\user '$webServerUser';' /etc/$webServerName/nginx.conf
  764. comprobarError $? 107
  765. unset nginxConfFile
  766. }
  767. instalarVirtualHost() {
  768. # Configuramos un Virtual Host para Apache o Nginx
  769. # Uso: instalarVirtualHost $root $virtualHost $dominio $alias
  770. if [ $# -ge 3 ];then
  771. rootVirtualHost=$(realpath $1)
  772. shift
  773. virtualHostFile=$(realpath $1)
  774. shift
  775. dominioVirtualHost=$1
  776. virtualHostName=$dominioVirtualHost".conf"
  777. shift
  778. aliasVirtualHost=$@
  779. else
  780. comprobarError 1 908
  781. fi
  782. if [ ! -f $virtualHostFile ];then
  783. comprobarError 1 909 $virtualHostName
  784. fi
  785. if [ $apacheOn = true ];then
  786. # Configuramos root, dominio y logs
  787. sed -i '/ServerName /c\\tServerName '"$dominioVirtualHost" $virtualHostFile
  788. comprobarError $? 908
  789. if [ ! -z "$aliasVirtualHost" ];then
  790. sed -i '/ServerName /a\\tServerAlias '"$aliasVirtualHost" $virtualHostFile
  791. comprobarError $? 908
  792. fi
  793. sed -i '/DocumentRoot /c\\tDocumentRoot '"$rootVirtualHost" $virtualHostFile
  794. comprobarError $? 908
  795. sed -i '/ErrorLog /c\\tErrorLog logs/'"$dominioVirtualHost"'-error.log' $virtualHostFile
  796. comprobarError $? 908
  797. sed -i '/CustomLog /c\\tCustomLog logs/'"$dominioVirtualHost"'-access.log common' $virtualHostFile
  798. comprobarError $? 908
  799. elif [ $nginxOn = true ];then
  800. # Configuramos root, dominio, logs y php-fpm.sock (NGINX)
  801. sed -i '/root /c\\troot '$rootVirtualHost';' "$virtualHostFile"
  802. comprobarError $? 908
  803. sed -i '/server_name /c\\tserver_name '"$dominioVirtualHost"' '"$aliasVirtualHost"';' $virtualHostFile
  804. comprobarError $? 908
  805. sed -i '/access_log /c\\taccess_log /var/log/nginx/'"$dominioVirtualHost"'-access.log;' $virtualHostFile
  806. comprobarError $? 908
  807. sed -i '/error_log /c\\terror_log /var/log/nginx/'"$dominioVirtualHost"'-error.log;' $virtualHostFile
  808. comprobarError $? 908
  809. socket=$(find /var/run/ -type s -name 'php*.sock')
  810. sed -i '/fastcgi_pass /c\\t\tfastcgi_pass unix:'"$socket"';' $virtualHostFile
  811. fi
  812. # Copiamos ficheros de configuración
  813. cp -f $virtualHostFile "/etc/$webServerName/sites-available/$virtualHostName" >> $logFile 2>&1
  814. comprobarError $? 910
  815. ln -s "/etc/$webServerName/sites-available/$virtualHostName" "/etc/$webServerName/sites-enabled/$virtualHostName" >> $logFile 2>&1
  816. comprobarError $? 911 $virtualHostName
  817. recargarServicio $webServerName
  818. unset rootVirtualHost dominioVirtualHost virtualHostFile virtualHostName aliasVirtualHost
  819. }
  820. mostrarDatabase() {
  821. if [ $debianOS = true ]; then
  822. 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 \
  823. "MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" ON \
  824. "MySQL" "Instalar la base de datos MySQL (uso no comercial)" OFF \
  825. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  826. comprobarError $? 1
  827. case $database in
  828. MariaDB)
  829. mariaDBOn=true
  830. ;;
  831. MySQL)
  832. mySQLOn=true
  833. ;;
  834. *)
  835. comprobarError 1 200
  836. ;;
  837. esac
  838. unset database
  839. elif [ $rhelOS = true ]; then
  840. 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"
  841. comprobarError $? 1
  842. mariaDBOn=true
  843. else
  844. comprobarError 1 200
  845. fi
  846. # Otras opciones (contraseña)
  847. leerSQLPasswd
  848. }
  849. leerSQLPasswd() {
  850. control=false
  851. error=""
  852. # Leemos la contreseña (stdin) y confirmamos
  853. while [ $control = false ]; do
  854. 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)
  855. comprobarError $? 1
  856. 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)
  857. comprobarError $? 1
  858. #echo -en "SQL Password 1: $sqlPasswd\n"
  859. #echo -en "SQL Password 2: $sqlPasswd2\n"
  860. if [ -z "$sqlPasswd" ] || [ -z "$sqlPasswd2" ]; then
  861. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  862. elif [ $sqlPasswd != $sqlPasswd2 ];then
  863. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  864. else
  865. control=true
  866. fi
  867. done
  868. #echo -en "SQL Password: $sqlPasswd\n"
  869. unset control error sqlPasswd2
  870. }
  871. establecerSQLPasswd() {
  872. # Establecemos SQL root passwd y securizamos BD (mysql_secure_installation)
  873. # Comprobamos si ya tiene una contraseña asignada
  874. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  875. if [ $? -eq 0 ];then
  876. # Establecemos contraseña del usuario root (y desactivamos posibles plugins para forzar login por contraseña)
  877. mysql -e "UPDATE mysql.user SET plugin = '', Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1
  878. if [ $? -ne 0 ];then
  879. # Lo intentamos de otra forma (para versiones modernas de mysql)
  880. mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$sqlPasswd'" >> $logFile 2>&1
  881. comprobarError $? 207
  882. fi
  883. # Aplicamos el cambio de contraseña
  884. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  885. # Desactivamos acceso root desde el exterior (solo localhost)
  886. mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" >> $logFile 2>&1
  887. comprobarError $? 208
  888. # Eliminamos todos los usuarios anónimos
  889. mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1
  890. comprobarError $? 209
  891. # Eliminamos bases de datos 'test'
  892. mysql -u root --password=$sqlPasswd -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1
  893. comprobarError $? 210
  894. # Eliminamos privilegios de la base de datos 'test'
  895. mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1
  896. comprobarError $? 211
  897. # Aplicamos los cambios
  898. mysql -u root --password=$sqlPasswd -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  899. comprobarError $? 212
  900. else
  901. comprobarError 1 206
  902. fi
  903. }
  904. instalarMySQL() {
  905. sqlServerName="mysql"
  906. if [ $debianOS = true ];then
  907. result=$(apt-get -q -y install mysql-server mysql-client 2>&1)
  908. comprobarError $? 201 $result
  909. elif [ $rhelOS = true ];then
  910. # MySQL no disponible en RHEL. 2 opciones:
  911. # 1) Instalar un repositorio adicional
  912. # 2) No instalar MySQL en distribuciones RHEL
  913. comprobarError 1 205
  914. else
  915. comprobarError 1 203
  916. fi
  917. }
  918. instalarMariaDB() {
  919. sqlServerName="mariadb"
  920. if [ $debianOS = true ];then
  921. result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1)
  922. comprobarError $? 202 $result
  923. elif [ $rhelOS = true ];then
  924. result=$(yum -y install mariadb-server mariadb 2>&1)
  925. comprobarError $? 202 $result
  926. else
  927. comprobarError 1 204
  928. fi
  929. }
  930. instalarPHP() {
  931. # Instalamos PHP-7 de forma diferente si es junto a Apache o con Nginx
  932. if [ $debianOS = true ];then
  933. if [ $apacheOn = true ]; then
  934. result=$(apt-get -q -y install php libapache2-mod-php php-mysql php-intl php-mbstring php-xml php-apcu php-gd 2>&1)
  935. comprobarError $? 302 $result
  936. elif [ $nginxOn = true ];then
  937. phpFPMName="php7.2-fpm"
  938. result=$(apt-get -q -y install php-fpm php-mysql php-intl php-mbstring php-xml php-apcu php-gd 2>&1)
  939. comprobarError $? 302 $result
  940. deshabilitarServicio $phpFPMName
  941. else
  942. comprobarError 1 301
  943. fi
  944. elif [ $rhelOS = true ];then
  945. # Necesitamos un repositorio adicional para PHP-7 (EPEL-RELEASE)
  946. result=$(yum -y install epel-release yum-utils 2>&1)
  947. comprobarError $? 103 $result
  948. # Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE)
  949. if [ ! -f /etc/yum.repos.d/remi-php72.repo ];then
  950. if [ $VERSION = "7" ];then
  951. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-7.rpm 2>&1)
  952. comprobarError $? 303 $result
  953. elif [ $VERSION = "6" ];then
  954. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-6.rpm 2>&1)
  955. comprobarError $? 303 $result
  956. elif [ $VERSION = "28" ];then
  957. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-28.rpm 2>&1)
  958. comprobarError $? 303 $result
  959. elif [ $VERSION = "27" ];then
  960. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-27.rpm 2>&1)
  961. comprobarError $? 303 $result
  962. else
  963. comprobarError 1 304
  964. fi
  965. fi
  966. # Activamos repositorio remi-php72
  967. result=$(yum-config-manager --enable remi-php72 2>&1)
  968. comprobarError $? 303 $result
  969. # Instalamos PHP-7.2
  970. if [ $apacheOn = true ];then
  971. result=$(yum -y install php php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd 2>&1)
  972. comprobarError $? 302 $result
  973. elif [ $nginxOn = true ];then
  974. phpFPMName="php-fpm"
  975. result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd 2>&1)
  976. comprobarError $? 302 $result
  977. deshabilitarServicio $phpFPMName
  978. else
  979. comprobarError 1 301
  980. fi
  981. else
  982. comprobarError 1 300
  983. fi
  984. }
  985. configurarPHP() {
  986. # Configura PHP para segurizarlo y establecer máximo de subida.
  987. if [ $debianOS = true ];then
  988. phpConfFile="./etc/php/php.ini.debian"
  989. phpDest="/etc/php/7.2/cli/php.ini"
  990. elif [ $rhelOS = true ];then
  991. phpConfFile="./etc/php/php.ini.rhel"
  992. phpDest="/etc/php.ini"
  993. fi
  994. if [ ! -f $phpConfFile ];then
  995. comprobarError 1 4 "$phpConfFile"
  996. fi
  997. # Copiamos configuración
  998. cp -f $phpConfFile $phpDest 2>/dev/null
  999. comprobarError $? 305
  1000. # Configuramos cgi.fix_pathinfo
  1001. sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=0' $phpDest
  1002. comprobarError $? 305
  1003. # Configuramos post_max_size
  1004. sed -i '/post_max_size =/c\post_max_size = '$maxUpload $phpDest
  1005. comprobarError $? 305
  1006. # Configuramos upload_max_filesize
  1007. sed -i '/upload_max_filesize =/c\upload_max_filesize = '$maxUpload $phpDest
  1008. comprobarError $? 305
  1009. # Configurar php-fpm (sólo en RHEL con Nginx)
  1010. if [ $rhelOS = true ] && [ $nginxOn = true ];then
  1011. # Configurar Socket UNIX
  1012. phpConfFile="./etc/php/php-fpm.d/www.conf"
  1013. phpDest="/etc/php-fpm.d/www.conf"
  1014. if [ ! -f $phpConfFile ];then
  1015. comprobarError $? 4 "$phpConfFile"
  1016. fi
  1017. cp -f $phpConfFile $phpDest 2>/dev/null
  1018. comprobarError $? 305
  1019. # Configurar Permisos /var/lib/php
  1020. chown -R $webServerUser:$webServerGroup /var/lib/php/
  1021. comprobarError $? 305
  1022. fi
  1023. unset phpConfFile phpDest
  1024. }
  1025. establecerMaxUpload() {
  1026. control=false
  1027. error=""
  1028. while [ $control = false ];do
  1029. 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)
  1030. comprobarError $? 1
  1031. if [ -z "$maxUpload2" ];then
  1032. error="ERROR: NO PUEDES DEJAR ESTE PARÁMETRO VACIO.\n"
  1033. else
  1034. control=true
  1035. fi
  1036. done
  1037. maxUpload=$maxUpload2
  1038. unset control maxUpload2
  1039. }
  1040. instalarPHPInfo() {
  1041. # Instalar fichero php
  1042. if [ ! -f /etc/$webServerName/sites-enabled/phpinfo.conf ];then
  1043. infoFile="./var/www/info.php"
  1044. if [ ! -f $infoFile ];then
  1045. comprobarError 1 4 "$infoFile"
  1046. fi
  1047. mkdir /var/www/localhost 2>/dev/null
  1048. comprobarError $? 106
  1049. cp -f $infoFile /var/www/localhost/ 2>/dev/null
  1050. comprobarError $? 106
  1051. chown -R $webServerUser:$webServerGroup /var/www/localhost 2>/dev/null
  1052. comprobarError $? 106
  1053. unset infoFile
  1054. # Instalar VirtualHost
  1055. if [ $apacheOn = true ] && [ $sslOn = false ];then
  1056. virtualHost="./etc/apache2/sites-available/phpinfo.conf"
  1057. elif [ $nginxOn = true ] && [ $sslOn = false ];then
  1058. virtualHost="./etc/nginx/sites-available/phpinfo.conf"
  1059. elif [ $apacheOn = true ] && [ $sslOn = true ];then
  1060. virtualHost="./etc/apache2/sites-available/phpinfo-ssl.conf"
  1061. elif [ $nginxOn = true ] && [ $sslOn = true ];then
  1062. virtualHost="./etc/nginx/sites-available/phpinfo-ssl.conf"
  1063. else
  1064. comprobarError 1 106
  1065. fi
  1066. instalarVirtualHost "/var/www/localhost" $virtualHost "localhost"
  1067. unset virtualHost
  1068. return 0
  1069. else
  1070. return 1
  1071. fi
  1072. }
  1073. habilitarServicio() {
  1074. # Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
  1075. # Intentamos con systemctl (SystemD)
  1076. #echo -en "Habilitando Servicio '$1'" | tee -a $logFile
  1077. if [ $# -le 0 ];then
  1078. comprobarError 1 900
  1079. fi
  1080. which systemctl > /dev/null 2>&1
  1081. if [ $? -eq 0 ]; then
  1082. #echo -en " (SystemD)..." | tee -a $logFile
  1083. systemctl start $1 > /dev/null 2>&1
  1084. comprobarError $? 901 $1
  1085. systemctl enable $1 > /dev/null 2>&1
  1086. comprobarError $? 902 $1
  1087. else
  1088. # Intentamos con service (Upstart)
  1089. which service > /dev/null 2>&1
  1090. if [ $? -eq 0 ]; then
  1091. #echo -en " (Upstart)..." | tee -a $logFile
  1092. service $1 start > /dev/null 2>&1
  1093. comprobarError $? 901 $1
  1094. else
  1095. # Intentamos con init.d (SystemV)
  1096. #echo -en " (SystemV)..." | tee -a $logFile
  1097. /etc/init.d/$1 start > /dev/null 2>&1
  1098. comprobarError $? 901 $1
  1099. fi
  1100. # Intentamos habilitar en el arranque (Upstart)
  1101. which update-rc.d > /dev/null 2>&1
  1102. if [ $? -eq 0 ];then
  1103. update-rc.d $1 enable
  1104. comprobarError $? 902 $1
  1105. else
  1106. # Intentamos habilitar en el arranque (SystemV)
  1107. which chkconfig > /dev/null 2>&1
  1108. if [ $? -eq 0 ];then
  1109. chkconfig $1 on
  1110. comprobarError $? 902 $1
  1111. else
  1112. # ¿Qué mas opciones nos quedan?
  1113. comprobarError 1 902 $1
  1114. fi
  1115. fi
  1116. fi
  1117. # Mejora: comprobar si el servicio está parado
  1118. #echo -en " OK.\n" | tee -a $logFile
  1119. }
  1120. deshabilitarServicio() {
  1121. # Paramos y deshabilitamos el servicio (con SystemD, Upstart o SystemV)
  1122. # Intentamos con systemctl (SystemD)
  1123. #echo -en "Deshabilitando Servicio '$1'" | tee -a $logFile
  1124. if [ $# -le 0 ];then
  1125. comprobarError 1 903
  1126. fi
  1127. which systemctl > /dev/null 2>&1
  1128. if [ $? -eq 0 ]; then
  1129. #echo -en " (SystemD)..." | tee -a $logFile
  1130. systemctl stop $1 > /dev/null 2>&1
  1131. comprobarError $? 904 $1
  1132. systemctl disable $1 > /dev/null 2>&1
  1133. comprobarError $? 905 $1
  1134. else
  1135. # Intentamos con service (Upstart)
  1136. which service > /dev/null 2>&1
  1137. if [ $? -eq 0 ]; then
  1138. #echo -en " (Upstart)..." | tee -a $logFile
  1139. service $1 stop > /dev/null 2>&1
  1140. comprobarError $? 904 $1
  1141. else
  1142. # Intentamos con init.d (SystemV)
  1143. #echo -en " (SystemV)..." | tee -a $logFile
  1144. /etc/init.d/$1 stop > /dev/null 2>&1
  1145. comprobarError $? 904 $1
  1146. fi
  1147. # Intentamos habilitar en el arranque (Upstart)
  1148. which update-rc.d > /dev/null 2>&1
  1149. if [ $? -eq 0 ];then
  1150. update-rc.d $1 disable
  1151. comprobarError $? 905 $1
  1152. else
  1153. # Intentamos habilitar en el arranque (SystemV)
  1154. which chkconfig > /dev/null 2>&1
  1155. if [ $? -eq 0 ];then
  1156. chkconfig $1 off
  1157. comprobarError $? 905 $1
  1158. else
  1159. # ¿Qué mas opciones nos quedan?
  1160. comprobarError 1 905 $1
  1161. fi
  1162. fi
  1163. fi
  1164. # Mejora: comprobar si el servicio está funcionando
  1165. #echo -en " OK.\n" | tee -a $logFile
  1166. }
  1167. recargarServicio() {
  1168. # Recargamos el servicio (con SystemD, Upstart o SystemV)
  1169. # Intentamos con systemctl (SystemD)
  1170. #echo -en "Recargando Servicio '$1'" | tee -a $logFile
  1171. if [ $# -le 0 ];then
  1172. comprobarError 1 912
  1173. fi
  1174. which systemctl > /dev/null 2>&1
  1175. if [ $? -eq 0 ]; then
  1176. #echo -en " (SystemD)..." | tee -a $logFile
  1177. systemctl reload $1 > /dev/null 2>&1
  1178. comprobarError $? 913 $1
  1179. else
  1180. # Intentamos con service (Upstart)
  1181. which service > /dev/null 2>&1
  1182. if [ $? -eq 0 ]; then
  1183. #echo -en " (Upstart)..." | tee -a $logFile
  1184. service $1 reload > /dev/null 2>&1
  1185. comprobarError $? 913 $1
  1186. else
  1187. # Intentamos con init.d (SystemV)
  1188. #echo -en " (SystemV)..." | tee -a $logFile
  1189. /etc/init.d/$1 reload > /dev/null 2>&1
  1190. comprobarError $? 913 $1
  1191. fi
  1192. fi
  1193. # Mejora: comprobar si el servicio está funcionando
  1194. #echo -en " OK.\n" | tee -a $logFile
  1195. }
  1196. configurarCortafuegos() {
  1197. # Configuramos cortafuegos (añadir reglas y encender)
  1198. # Comprobamos si estamos usando SSH
  1199. esSSH $PPID
  1200. if [ $debianOS = true ];then
  1201. ufw allow 80/tcp >> $logFile 2>&1
  1202. comprobarError $? 906 "80/tcp"
  1203. if [ $sshControl = true ];then
  1204. ufw allow 22/tcp >> $logFile 2>&1
  1205. comprobarError $? 906 "22/tcp"
  1206. fi
  1207. if [ $sslOn = true ];then
  1208. ufw allow 443/tcp >> $logFile 2>&1
  1209. comprobarError $? 906 "443/tcp"
  1210. fi
  1211. ufw --force enable >> $logFile 2>&1
  1212. comprobarError $? 907
  1213. elif [ $rhelOS = true ];then
  1214. firewall-cmd --add-port=80/tcp >> $logFile 2>&1
  1215. comprobarError $? 906 "80/tcp"
  1216. if [ $sshControl = true ];then
  1217. firewall-cmd --add-port=22/tcp >> $logFile 2>&1
  1218. comprobarError $? 906 "22/tcp"
  1219. fi
  1220. if [ $sslOn = true ];then
  1221. firewall-cmd --add-port=443/tcp >> $logFile 2>&1
  1222. comprobarError $? 906 "443/tcp"
  1223. fi
  1224. firewall-cmd --runtime-to-permanent >> $logFile 2>&1
  1225. comprobarError $? 907
  1226. habilitarServicio firewalld >> $logFile 2>&1
  1227. comprobarError $? 907
  1228. fi
  1229. unset sshControl
  1230. }
  1231. esSSH() {
  1232. p=${1:-$PPID}
  1233. #read pid name x ppid y < <( cat /proc/$p/stat )
  1234. read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
  1235. [[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
  1236. [ "$ppid" -le 1 ] && { sshControl=false; return 1; }
  1237. esSSH $ppid
  1238. }
  1239. descargarMediaWiki() {
  1240. # Descargar la versión 1.31.0 de MediaWiki
  1241. if [ ! -d ./var ];then
  1242. comprobarError 1 5 "./var"
  1243. fi
  1244. curl "https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz" 2>/dev/null | tar -xz -C "./var/"
  1245. comprobarError $? 501
  1246. }
  1247. configurarMediaWiki() {
  1248. # Configuramos MediaWiki
  1249. # Copiamos archivos y permisos
  1250. if [ ! -f /var/www/$dominioMediaWiki/LocalSettings.php ];then
  1251. cp -R ./var/mediawiki-1.31.0/ /var/www/$dominioMediaWiki
  1252. comprobarError $? 502
  1253. # Configuramos LocalSettings.php (y crea la base de datos por nosotros)
  1254. nombreDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
  1255. userDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
  1256. php /var/www/$dominioMediaWiki/maintenance/install.php --dbname=$nombreDBMW --dbserver="localhost" --installdbuser=root --installdbpass=$sqlPasswd --dbuser=$userDBMW --dbpass=$sqlPasswd --scriptpath="" --lang=es --pass=$passwdMediaWiki --with-extensions "$nombreMediaWiki" "admin" >> $logFile 2>&1
  1257. comprobarError $? 502
  1258. # Configuraciones adicionales
  1259. sed -i '/$wgEnableEmail =/c\$wgEnableEmail = false;' /var/www/$dominioMediaWiki/LocalSettings.php
  1260. comprobarError $? 502
  1261. sed -i '/$wgEnableUploads =/c\$wgEnableUploads = true;' /var/www/$dominioMediaWiki/LocalSettings.php
  1262. comprobarError $? 502
  1263. echo -en "\$wgArticlePath = \"/wiki/\$1\";\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1264. echo -en "\$wgUsePathInfo = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1265. echo -en "\$wgGroupPermissions['*']['createaccount'] = false;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1266. echo -en "\$wgGroupPermissions['*']['edit'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1267. echo -en "\$wgGroupPermissions['*']['read'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1268. # Actualizamos permisos
  1269. chown -R $webServerUser:$webServerGroup /var/www/$dominioMediaWiki
  1270. comprobarError $? 502
  1271. # Configuramos VirtualHost
  1272. if [ $apacheOn = true ] && [ $sslOn = false ];then
  1273. virtualHost="./etc/apache2/sites-available/mediawiki.conf"
  1274. elif [ $nginxOn = true ] && [ $sslOn = false ];then
  1275. virtualHost="./etc/nginx/sites-available/mediawiki.conf"
  1276. elif [ $apacheOn = true ] && [ $sslOn = true ];then
  1277. virtualHost="./etc/apache2/sites-available/mediawiki-ssl.conf"
  1278. elif [ $nginxOn = true ] && [ $sslOn = true ];then
  1279. virtualHost="./etc/nginx/sites-available/mediawiki-ssl.conf"
  1280. else
  1281. comprobarError 1 502
  1282. fi
  1283. if [ ! -f $virtualHost ];then
  1284. comprobarError $? 502
  1285. fi
  1286. instalarVirtualHost "/var/www/$dominioMediaWiki" $virtualHost $dominioMediaWiki $aliasMediaWiki
  1287. unset virtualHost socket
  1288. else
  1289. comprobarError 1 503 $dominioMediaWiki
  1290. fi
  1291. }
  1292. crearDBMediaWiki() {
  1293. # DEPRECATED: Borrar
  1294. # Creamos una base de datos para MediaWiki
  1295. dbDir="./etc/db"
  1296. if [ ! -d $dbDir ];then
  1297. mkdir $dbDir 2>/dev/null
  1298. comprobarError $? 503
  1299. fi
  1300. dbFile=$dbDir"/mediawiki.sql"
  1301. nombreDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
  1302. userDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
  1303. echo -en "CREATE DATABASE IF NOT EXISTS $nombreDBMW;\n" > $dbFile
  1304. echo -en "GRANT ALL PRIVILEGES ON $nombreDBMW.* TO '$userDBMW'@'localhost' IDENTIFIED BY '$sqlPasswd';\n" >> $dbFile
  1305. mysql -u root --password=$sqlPasswd < $dbFile
  1306. control=$?
  1307. rm -f $dbFile 2>/dev/null
  1308. comprobarError $? 503
  1309. comprobarError $control 503
  1310. unset control dbFile
  1311. }
  1312. descargarMoodle() {
  1313. # Descargar la versión 1.31.0 de MediaWiki
  1314. if [ ! -d ./var ];then
  1315. comprobarError 1 5 "./var"
  1316. fi
  1317. #echo -en "Descargando Moodle-3.5-1..." | tee -a $logFile
  1318. #curl -o "./var/moodle-3.5.1.tgz" "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" >> $logFile 2>&1
  1319. curl "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" 2>/dev/null | tar -xz -C "./var/"
  1320. comprobarError $? 501
  1321. #echo -en " OK.\n" | tee -a $logFile
  1322. }
  1323. # Comprobación del sistema e inicialización
  1324. inicializarVariables
  1325. comprobarRoot
  1326. OSInfo
  1327. comprobarDependencias
  1328. # Bienvenida
  1329. mostrarBienvenida
  1330. # Selección de componentes (express vs avanzada)
  1331. mostrarExpress
  1332. # Instalación Servidor Web
  1333. if [ $apacheOn = true ]; then
  1334. echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
  1335. # {
  1336. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1337. instalarApache
  1338. progreso=$((progreso + 1))
  1339. # } > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1340. echo -en " OK.\n" | tee -a $logFile
  1341. elif [ $nginxOn = true ]; then
  1342. echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
  1343. # {
  1344. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1345. instalarNginx
  1346. progreso=$((progreso + 1))
  1347. # } > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1348. echo -en " OK.\n" | tee -a $logFile
  1349. fi
  1350. # Instalación Base de Datos
  1351. if [ $mySQLOn = true ]; then
  1352. echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
  1353. # {
  1354. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1355. instalarMySQL
  1356. progreso=$((progreso + 1))
  1357. # } > >(whiptail --gauge "Instalando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1358. echo -en " OK.\n" | tee -a $logFile
  1359. elif [ $mariaDBOn = true ]; then
  1360. echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
  1361. # {
  1362. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1363. instalarMariaDB
  1364. progreso=$((progreso + 1))
  1365. # } > >(whiptail --gauge "Instalando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1366. echo -en " OK.\n" | tee -a $logFile
  1367. fi
  1368. # Instalación PHP-7.2
  1369. if [ $phpOn = true ]; then
  1370. echo -en "Instalando PHP-7..." | tee -a $logFile
  1371. # {
  1372. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1373. instalarPHP
  1374. progreso=$((progreso + 1))
  1375. # } > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1376. echo -en " OK.\n" | tee -a $logFile
  1377. fi
  1378. # Instalación SSL/TLS
  1379. if [ $sslOn = true ];then
  1380. echo -en "Instalando SSL/TLS..." | tee -a $logfile
  1381. # {
  1382. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1383. sleep 2
  1384. progreso=$((progreso + 1))
  1385. # } > >(whiptail --gauge "Instalando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1386. echo -en " OK.\n" | tee -a $logFile
  1387. fi
  1388. # Configuración Web Server
  1389. if [ $apacheOn = true ];then
  1390. echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
  1391. # {
  1392. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1393. configurarApache
  1394. progreso=$((progreso + 1))
  1395. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1396. echo -en " OK.\n" | tee -a $logFile
  1397. elif [ $nginxOn = true ]; then
  1398. echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
  1399. # {
  1400. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1401. configurarNginx
  1402. progreso=$((progreso + 1))
  1403. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1404. echo -en " OK.\n" | tee -a $logFile
  1405. fi
  1406. # Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
  1407. if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
  1408. habilitarServicio "$sqlServerName"
  1409. echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile
  1410. # {
  1411. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1412. establecerSQLPasswd
  1413. progreso=$((progreso + 1))
  1414. # } > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1415. echo -en " OK.\n" | tee -a $logFile
  1416. fi
  1417. # Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
  1418. if [ $phpOn = true ];then
  1419. echo -en "Configurando PHP-7..." | tee -a $logFile
  1420. # {
  1421. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1422. configurarPHP
  1423. progreso=$((progreso + 1))
  1424. # } > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1425. echo -en " OK.\n" | tee -a $logFile
  1426. fi
  1427. # Configuración SSL/TLS
  1428. # Generar certificados
  1429. # Configurar certificados
  1430. if [ $sslOn = true ];then
  1431. echo -en "Configurando SSL/TLS..." | tee -a $logFile
  1432. # {
  1433. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1434. sleep 2
  1435. progreso=$((progreso + 1))
  1436. # } > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1437. echo -en " OK.\n" | tee -a $logFile
  1438. fi
  1439. # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
  1440. # {
  1441. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1442. if [ $apacheOn = true ];then
  1443. habilitarServicio $webServerName
  1444. elif [ $nginxOn = true ];then
  1445. habilitarServicio $webServerName
  1446. if [ $phpOn = true ];then
  1447. habilitarServicio $phpFPMName
  1448. fi
  1449. fi
  1450. progreso=$((progreso + 1))
  1451. # } > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1452. # MediaWiki
  1453. if [ $mediaWikiOn = true ]; then
  1454. # Descargar MediaWiki
  1455. echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
  1456. # {
  1457. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1458. descargarMediaWiki
  1459. progreso=$((progreso + 1))
  1460. # } > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1461. echo -en " OK.\n" | tee -a $logFile
  1462. # Configurar MediWiki
  1463. echo -en "Configurando MediaWiki..." | tee -a $logFile
  1464. # {
  1465. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1466. configurarMediaWiki
  1467. progreso=$((progreso + 1))
  1468. # } > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1469. echo -en " OK.\n" | tee -a $logFile
  1470. fi
  1471. # Moodle
  1472. if [ $moodleOn = true ]; then
  1473. # Descargar Moodle
  1474. echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
  1475. # {
  1476. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1477. descargarMoodle
  1478. progreso=$((progreso + 1))
  1479. # } > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1480. echo -en " OK.\n" | tee -a $logFile
  1481. # Configuración Moodle
  1482. echo -en "Configurando Moodle..." | tee -a $logFile
  1483. # {
  1484. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1485. sleep 2
  1486. progreso=$((progreso + 1))
  1487. # } > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1488. echo -en " OK.\n" | tee -a $logFile
  1489. fi
  1490. # Configurar Virtual Hosts
  1491. # Instalar info.php
  1492. if [ $infoPHPOn = true ];then
  1493. echo -en "Configurando 'info.php'..." | tee -a $logFile
  1494. instalarPHPInfo
  1495. if [ $? -eq 0 ];then
  1496. echo -en " OK.\n" | tee -a $logFile
  1497. else
  1498. echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
  1499. fi
  1500. fi
  1501. # Añadir reglas del cortafuegos
  1502. echo -en "Configurando Cortafuegos..." | tee -a $logFile
  1503. # {
  1504. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1505. configurarCortafuegos
  1506. progreso=$((progreso + 1))
  1507. # } > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1508. echo -en " OK.\n" | tee -a $logFile
  1509. # Configurar actualizaciones
  1510. if [ $actualizacionesOn = true ]; then
  1511. echo -en "Configurando Actualizaciones Automáticas..." | tee -a $logFile
  1512. # {
  1513. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1514. sleep 2
  1515. progreso=$((progreso + 1))
  1516. # } > >(whiptail --gauge "Configurando actualizaciones automáticas..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1517. echo -en " OK.\n" | tee -a $logFile
  1518. fi