install 51 KB

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