install 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  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. # Activamos mod_rewrite (no viene activado por defecto)
  691. a2enmod rewrite >/dev/null 2>&1
  692. comprobarError $? 108
  693. elif [ $rhelOS = true ];then
  694. apacheConfFile="./etc/apache2/conf/httpd.conf"
  695. welcomeConfFile="/etc/apache2/conf.d/welcome.conf"
  696. if [ ! -f $apacheConfFile ];then
  697. comprobarError 1 4 $apacheConfFile
  698. fi
  699. cp -f $apacheConfFile /etc/$webServerName/conf/httpd.conf 2>/dev/null
  700. comprobarError $? 108
  701. if [ -f $welcomeConfFile ];then
  702. sed -i -e 's/^/#/' $welcomeConfFile
  703. comprobarError $? 108
  704. fi
  705. webServerUser=$(grep ^User /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
  706. webServerGroup=$(grep ^Group /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
  707. unset apacheConfFile welcomeConfFile
  708. fi
  709. if [ ! -d "/etc/$webServerName/sites-available" ];then
  710. mkdir "/etc/$webServerName/sites-available" 2>/dev/null
  711. comprobarError $? 5 "/etc/$webServerName/sites-available"
  712. fi
  713. if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
  714. mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
  715. comprobarError $? 5 "/etc/$webServerName/sites-enabled"
  716. else
  717. # Eliminar Virtual Host por defecto
  718. if [ -f /etc/$webServerName/sites-enabled/000-default.conf ];then
  719. rm -f /etc/$webServerName/sites-enabled/000-default.conf 2>/dev/null
  720. fi
  721. fi
  722. }
  723. instalarNginx() {
  724. webServerName="nginx"
  725. if [ $debianOS = true ];then
  726. result=$(apt-get -q -y install nginx 2>&1)
  727. comprobarError $? 102 $result
  728. elif [ $rhelOS = true ]; then
  729. # Hay que instalar primero otro repositorio
  730. result=$(yum -y install epel-release)
  731. comprobarError $? 103 $result
  732. result=$(yum -y install nginx 2>&1)
  733. comprobarError $? 102 $result
  734. else
  735. comprobarError 1 105
  736. fi
  737. deshabilitarServicio $webServerName
  738. }
  739. configurarNginx() {
  740. # Configuramos Nginx
  741. rm -Rf /etc/$webServerName/* 2>/dev/null
  742. comprobarError $? 107
  743. nginxConfFile="./etc/$webServerName"
  744. if [ -d "$nginxConfFile" ];then
  745. cp -Rf $nginxConfFile/* /etc/$webServerName/ 2>/dev/null
  746. comprobarError $? 107
  747. else
  748. comprobarError 1 5 "$nginxConfFile"
  749. fi
  750. if [ ! -d "/etc/$webServerName/sites-available" ];then
  751. mkdir "/etc/$webServerName/sites-available" 2>/dev/null
  752. comprobarError $? 5 "/etc/$webServerName/sites-available"
  753. fi
  754. if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
  755. mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
  756. comprobarError $? 5 "/etc/$webServerName/sites-enabled"
  757. fi
  758. # Configuramos Usuario y Grupo
  759. if [ $debianOS = true ];then
  760. webServerUser="www-data"
  761. webServerGroup=$webServerUser
  762. elif [ $rhelOS = true ];then
  763. webServerUser="nginx"
  764. webServerGroup=$webServerUser
  765. fi
  766. sed -i '/user /c\user '$webServerUser';' /etc/$webServerName/nginx.conf
  767. comprobarError $? 107
  768. unset nginxConfFile
  769. }
  770. instalarVirtualHost() {
  771. # Configuramos un Virtual Host para Apache o Nginx
  772. # Uso: instalarVirtualHost $root $virtualHost $dominio $alias
  773. if [ $# -ge 3 ];then
  774. rootVirtualHost=$(realpath $1)
  775. shift
  776. virtualHostFile=$(realpath $1)
  777. shift
  778. dominioVirtualHost=$1
  779. virtualHostName=$dominioVirtualHost".conf"
  780. shift
  781. aliasVirtualHost=$@
  782. else
  783. comprobarError 1 908
  784. fi
  785. if [ ! -f $virtualHostFile ];then
  786. comprobarError 1 909 $virtualHostName
  787. fi
  788. if [ $apacheOn = true ];then
  789. # Configuramos root, dominio y logs
  790. sed -i '/ServerName /c\\tServerName '"$dominioVirtualHost" $virtualHostFile
  791. comprobarError $? 908
  792. if [ ! -z "$aliasVirtualHost" ];then
  793. sed -i '/ServerName /a\\tServerAlias '"$aliasVirtualHost" $virtualHostFile
  794. comprobarError $? 908
  795. fi
  796. sed -i '/DocumentRoot /c\\tDocumentRoot '"$rootVirtualHost" $virtualHostFile
  797. comprobarError $? 908
  798. sed -i '/ErrorLog /c\\tErrorLog logs/'"$dominioVirtualHost"'-error.log' $virtualHostFile
  799. comprobarError $? 908
  800. sed -i '/CustomLog /c\\tCustomLog logs/'"$dominioVirtualHost"'-access.log common' $virtualHostFile
  801. comprobarError $? 908
  802. elif [ $nginxOn = true ];then
  803. # Configuramos root, dominio, logs y php-fpm.sock (NGINX)
  804. sed -i '/root /c\\troot '$rootVirtualHost';' "$virtualHostFile"
  805. comprobarError $? 908
  806. sed -i '/server_name /c\\tserver_name '"$dominioVirtualHost"' '"$aliasVirtualHost"';' $virtualHostFile
  807. comprobarError $? 908
  808. sed -i '/access_log /c\\taccess_log /var/log/nginx/'"$dominioVirtualHost"'-access.log;' $virtualHostFile
  809. comprobarError $? 908
  810. sed -i '/error_log /c\\terror_log /var/log/nginx/'"$dominioVirtualHost"'-error.log;' $virtualHostFile
  811. comprobarError $? 908
  812. socket=$(find /var/run/ -type s -name 'php*.sock')
  813. sed -i '/fastcgi_pass /c\\t\tfastcgi_pass unix:'"$socket"';' $virtualHostFile
  814. fi
  815. # Copiamos ficheros de configuración
  816. cp -f $virtualHostFile "/etc/$webServerName/sites-available/$virtualHostName" >> $logFile 2>&1
  817. comprobarError $? 910
  818. ln -s "/etc/$webServerName/sites-available/$virtualHostName" "/etc/$webServerName/sites-enabled/$virtualHostName" >> $logFile 2>&1
  819. comprobarError $? 911 $virtualHostName
  820. recargarServicio $webServerName
  821. unset rootVirtualHost dominioVirtualHost virtualHostFile virtualHostName aliasVirtualHost
  822. }
  823. mostrarDatabase() {
  824. if [ $debianOS = true ]; then
  825. 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 \
  826. "MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" ON \
  827. "MySQL" "Instalar la base de datos MySQL (uso no comercial)" OFF \
  828. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  829. comprobarError $? 1
  830. case $database in
  831. MariaDB)
  832. mariaDBOn=true
  833. ;;
  834. MySQL)
  835. mySQLOn=true
  836. ;;
  837. *)
  838. comprobarError 1 200
  839. ;;
  840. esac
  841. unset database
  842. elif [ $rhelOS = true ]; then
  843. 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"
  844. comprobarError $? 1
  845. mariaDBOn=true
  846. else
  847. comprobarError 1 200
  848. fi
  849. # Otras opciones (contraseña)
  850. leerSQLPasswd
  851. }
  852. leerSQLPasswd() {
  853. control=false
  854. error=""
  855. # Leemos la contreseña (stdin) y confirmamos
  856. while [ $control = false ]; do
  857. 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)
  858. comprobarError $? 1
  859. 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)
  860. comprobarError $? 1
  861. #echo -en "SQL Password 1: $sqlPasswd\n"
  862. #echo -en "SQL Password 2: $sqlPasswd2\n"
  863. if [ -z "$sqlPasswd" ] || [ -z "$sqlPasswd2" ]; then
  864. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  865. elif [ $sqlPasswd != $sqlPasswd2 ];then
  866. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  867. else
  868. control=true
  869. fi
  870. done
  871. #echo -en "SQL Password: $sqlPasswd\n"
  872. unset control error sqlPasswd2
  873. }
  874. establecerSQLPasswd() {
  875. # Establecemos SQL root passwd y securizamos BD (mysql_secure_installation)
  876. # Comprobamos si ya tiene una contraseña asignada
  877. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  878. if [ $? -eq 0 ];then
  879. # Establecemos contraseña del usuario root (y desactivamos posibles plugins para forzar login por contraseña)
  880. mysql -e "UPDATE mysql.user SET plugin = '', Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1
  881. if [ $? -ne 0 ];then
  882. # Lo intentamos de otra forma (para versiones modernas de mysql)
  883. mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$sqlPasswd'" >> $logFile 2>&1
  884. comprobarError $? 207
  885. fi
  886. # Aplicamos el cambio de contraseña
  887. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  888. # Desactivamos acceso root desde el exterior (solo localhost)
  889. 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
  890. comprobarError $? 208
  891. # Eliminamos todos los usuarios anónimos
  892. mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1
  893. comprobarError $? 209
  894. # Eliminamos bases de datos 'test'
  895. mysql -u root --password=$sqlPasswd -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1
  896. comprobarError $? 210
  897. # Eliminamos privilegios de la base de datos 'test'
  898. mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1
  899. comprobarError $? 211
  900. # Aplicamos los cambios
  901. mysql -u root --password=$sqlPasswd -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  902. comprobarError $? 212
  903. else
  904. comprobarError 1 206
  905. fi
  906. }
  907. instalarMySQL() {
  908. sqlServerName="mysql"
  909. if [ $debianOS = true ];then
  910. result=$(apt-get -q -y install mysql-server mysql-client 2>&1)
  911. comprobarError $? 201 $result
  912. elif [ $rhelOS = true ];then
  913. # MySQL no disponible en RHEL. 2 opciones:
  914. # 1) Instalar un repositorio adicional
  915. # 2) No instalar MySQL en distribuciones RHEL
  916. comprobarError 1 205
  917. else
  918. comprobarError 1 203
  919. fi
  920. }
  921. instalarMariaDB() {
  922. sqlServerName="mariadb"
  923. if [ $debianOS = true ];then
  924. result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1)
  925. comprobarError $? 202 $result
  926. elif [ $rhelOS = true ];then
  927. result=$(yum -y install mariadb-server mariadb 2>&1)
  928. comprobarError $? 202 $result
  929. else
  930. comprobarError 1 204
  931. fi
  932. }
  933. instalarPHP() {
  934. # Instalamos PHP-7 de forma diferente si es junto a Apache o con Nginx
  935. if [ $debianOS = true ];then
  936. if [ $apacheOn = true ]; then
  937. result=$(apt-get -q -y install php libapache2-mod-php php-mysql php-intl php-mbstring php-xml php-apcu php-gd 2>&1)
  938. comprobarError $? 302 $result
  939. elif [ $nginxOn = true ];then
  940. phpFPMName="php7.2-fpm"
  941. result=$(apt-get -q -y install php-fpm php-mysql php-intl php-mbstring php-xml php-apcu php-gd 2>&1)
  942. comprobarError $? 302 $result
  943. deshabilitarServicio $phpFPMName
  944. else
  945. comprobarError 1 301
  946. fi
  947. elif [ $rhelOS = true ];then
  948. # Necesitamos un repositorio adicional para PHP-7 (EPEL-RELEASE)
  949. result=$(yum -y install epel-release yum-utils 2>&1)
  950. comprobarError $? 103 $result
  951. # Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE)
  952. if [ ! -f /etc/yum.repos.d/remi-php72.repo ];then
  953. if [ $VERSION = "7" ];then
  954. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-7.rpm 2>&1)
  955. comprobarError $? 303 $result
  956. elif [ $VERSION = "6" ];then
  957. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-6.rpm 2>&1)
  958. comprobarError $? 303 $result
  959. elif [ $VERSION = "28" ];then
  960. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-28.rpm 2>&1)
  961. comprobarError $? 303 $result
  962. elif [ $VERSION = "27" ];then
  963. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-27.rpm 2>&1)
  964. comprobarError $? 303 $result
  965. else
  966. comprobarError 1 304
  967. fi
  968. fi
  969. # Activamos repositorio remi-php72
  970. result=$(yum-config-manager --enable remi-php72 2>&1)
  971. comprobarError $? 303 $result
  972. # Instalamos PHP-7.2
  973. if [ $apacheOn = true ];then
  974. result=$(yum -y install php php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd 2>&1)
  975. comprobarError $? 302 $result
  976. elif [ $nginxOn = true ];then
  977. phpFPMName="php-fpm"
  978. result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd 2>&1)
  979. comprobarError $? 302 $result
  980. deshabilitarServicio $phpFPMName
  981. else
  982. comprobarError 1 301
  983. fi
  984. else
  985. comprobarError 1 300
  986. fi
  987. }
  988. configurarPHP() {
  989. # Configura PHP para segurizarlo y establecer máximo de subida.
  990. if [ $debianOS = true ];then
  991. phpConfFile="./etc/php/php.ini.debian"
  992. phpDest="/etc/php/7.2/cli/php.ini"
  993. elif [ $rhelOS = true ];then
  994. phpConfFile="./etc/php/php.ini.rhel"
  995. phpDest="/etc/php.ini"
  996. fi
  997. if [ ! -f $phpConfFile ];then
  998. comprobarError 1 4 "$phpConfFile"
  999. fi
  1000. # Copiamos configuración
  1001. cp -f $phpConfFile $phpDest 2>/dev/null
  1002. comprobarError $? 305
  1003. # Configuramos cgi.fix_pathinfo
  1004. sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=0' $phpDest
  1005. comprobarError $? 305
  1006. # Configuramos post_max_size
  1007. sed -i '/post_max_size =/c\post_max_size = '$maxUpload $phpDest
  1008. comprobarError $? 305
  1009. # Configuramos upload_max_filesize
  1010. sed -i '/upload_max_filesize =/c\upload_max_filesize = '$maxUpload $phpDest
  1011. comprobarError $? 305
  1012. # Configurar php-fpm (sólo en RHEL con Nginx)
  1013. if [ $rhelOS = true ] && [ $nginxOn = true ];then
  1014. # Configurar Socket UNIX
  1015. phpConfFile="./etc/php/php-fpm.d/www.conf"
  1016. phpDest="/etc/php-fpm.d/www.conf"
  1017. if [ ! -f $phpConfFile ];then
  1018. comprobarError $? 4 "$phpConfFile"
  1019. fi
  1020. cp -f $phpConfFile $phpDest 2>/dev/null
  1021. comprobarError $? 305
  1022. # Configurar Permisos /var/lib/php
  1023. chown -R $webServerUser:$webServerGroup /var/lib/php/
  1024. comprobarError $? 305
  1025. fi
  1026. unset phpConfFile phpDest
  1027. }
  1028. establecerMaxUpload() {
  1029. control=false
  1030. error=""
  1031. while [ $control = false ];do
  1032. 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)
  1033. comprobarError $? 1
  1034. if [ -z "$maxUpload2" ];then
  1035. error="ERROR: NO PUEDES DEJAR ESTE PARÁMETRO VACIO.\n"
  1036. else
  1037. control=true
  1038. fi
  1039. done
  1040. maxUpload=$maxUpload2
  1041. unset control maxUpload2
  1042. }
  1043. instalarPHPInfo() {
  1044. # Instalar fichero php
  1045. if [ ! -f /etc/$webServerName/sites-enabled/phpinfo.conf ];then
  1046. infoFile="./var/www/info.php"
  1047. if [ ! -f $infoFile ];then
  1048. comprobarError 1 4 "$infoFile"
  1049. fi
  1050. mkdir /var/www/localhost 2>/dev/null
  1051. comprobarError $? 106
  1052. cp -f $infoFile /var/www/localhost/ 2>/dev/null
  1053. comprobarError $? 106
  1054. chown -R $webServerUser:$webServerGroup /var/www/localhost 2>/dev/null
  1055. comprobarError $? 106
  1056. unset infoFile
  1057. # Instalar VirtualHost
  1058. if [ $apacheOn = true ] && [ $sslOn = false ];then
  1059. virtualHost="./etc/apache2/sites-available/phpinfo.conf"
  1060. elif [ $nginxOn = true ] && [ $sslOn = false ];then
  1061. virtualHost="./etc/nginx/sites-available/phpinfo.conf"
  1062. elif [ $apacheOn = true ] && [ $sslOn = true ];then
  1063. virtualHost="./etc/apache2/sites-available/phpinfo-ssl.conf"
  1064. elif [ $nginxOn = true ] && [ $sslOn = true ];then
  1065. virtualHost="./etc/nginx/sites-available/phpinfo-ssl.conf"
  1066. else
  1067. comprobarError 1 106
  1068. fi
  1069. instalarVirtualHost "/var/www/localhost" $virtualHost "localhost"
  1070. unset virtualHost
  1071. return 0
  1072. else
  1073. return 1
  1074. fi
  1075. }
  1076. habilitarServicio() {
  1077. # Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
  1078. # Intentamos con systemctl (SystemD)
  1079. #echo -en "Habilitando Servicio '$1'" | tee -a $logFile
  1080. if [ $# -le 0 ];then
  1081. comprobarError 1 900
  1082. fi
  1083. which systemctl > /dev/null 2>&1
  1084. if [ $? -eq 0 ]; then
  1085. #echo -en " (SystemD)..." | tee -a $logFile
  1086. systemctl start $1 > /dev/null 2>&1
  1087. comprobarError $? 901 $1
  1088. systemctl enable $1 > /dev/null 2>&1
  1089. comprobarError $? 902 $1
  1090. else
  1091. # Intentamos con service (Upstart)
  1092. which service > /dev/null 2>&1
  1093. if [ $? -eq 0 ]; then
  1094. #echo -en " (Upstart)..." | tee -a $logFile
  1095. service $1 start > /dev/null 2>&1
  1096. comprobarError $? 901 $1
  1097. else
  1098. # Intentamos con init.d (SystemV)
  1099. #echo -en " (SystemV)..." | tee -a $logFile
  1100. /etc/init.d/$1 start > /dev/null 2>&1
  1101. comprobarError $? 901 $1
  1102. fi
  1103. # Intentamos habilitar en el arranque (Upstart)
  1104. which update-rc.d > /dev/null 2>&1
  1105. if [ $? -eq 0 ];then
  1106. update-rc.d $1 enable
  1107. comprobarError $? 902 $1
  1108. else
  1109. # Intentamos habilitar en el arranque (SystemV)
  1110. which chkconfig > /dev/null 2>&1
  1111. if [ $? -eq 0 ];then
  1112. chkconfig $1 on
  1113. comprobarError $? 902 $1
  1114. else
  1115. # ¿Qué mas opciones nos quedan?
  1116. comprobarError 1 902 $1
  1117. fi
  1118. fi
  1119. fi
  1120. # Mejora: comprobar si el servicio está parado
  1121. #echo -en " OK.\n" | tee -a $logFile
  1122. }
  1123. deshabilitarServicio() {
  1124. # Paramos y deshabilitamos el servicio (con SystemD, Upstart o SystemV)
  1125. # Intentamos con systemctl (SystemD)
  1126. #echo -en "Deshabilitando Servicio '$1'" | tee -a $logFile
  1127. if [ $# -le 0 ];then
  1128. comprobarError 1 903
  1129. fi
  1130. which systemctl > /dev/null 2>&1
  1131. if [ $? -eq 0 ]; then
  1132. #echo -en " (SystemD)..." | tee -a $logFile
  1133. systemctl stop $1 > /dev/null 2>&1
  1134. comprobarError $? 904 $1
  1135. systemctl disable $1 > /dev/null 2>&1
  1136. comprobarError $? 905 $1
  1137. else
  1138. # Intentamos con service (Upstart)
  1139. which service > /dev/null 2>&1
  1140. if [ $? -eq 0 ]; then
  1141. #echo -en " (Upstart)..." | tee -a $logFile
  1142. service $1 stop > /dev/null 2>&1
  1143. comprobarError $? 904 $1
  1144. else
  1145. # Intentamos con init.d (SystemV)
  1146. #echo -en " (SystemV)..." | tee -a $logFile
  1147. /etc/init.d/$1 stop > /dev/null 2>&1
  1148. comprobarError $? 904 $1
  1149. fi
  1150. # Intentamos habilitar en el arranque (Upstart)
  1151. which update-rc.d > /dev/null 2>&1
  1152. if [ $? -eq 0 ];then
  1153. update-rc.d $1 disable
  1154. comprobarError $? 905 $1
  1155. else
  1156. # Intentamos habilitar en el arranque (SystemV)
  1157. which chkconfig > /dev/null 2>&1
  1158. if [ $? -eq 0 ];then
  1159. chkconfig $1 off
  1160. comprobarError $? 905 $1
  1161. else
  1162. # ¿Qué mas opciones nos quedan?
  1163. comprobarError 1 905 $1
  1164. fi
  1165. fi
  1166. fi
  1167. # Mejora: comprobar si el servicio está funcionando
  1168. #echo -en " OK.\n" | tee -a $logFile
  1169. }
  1170. recargarServicio() {
  1171. # Recargamos el servicio (con SystemD, Upstart o SystemV)
  1172. # Intentamos con systemctl (SystemD)
  1173. #echo -en "Recargando Servicio '$1'" | tee -a $logFile
  1174. if [ $# -le 0 ];then
  1175. comprobarError 1 912
  1176. fi
  1177. which systemctl > /dev/null 2>&1
  1178. if [ $? -eq 0 ]; then
  1179. #echo -en " (SystemD)..." | tee -a $logFile
  1180. systemctl reload $1 > /dev/null 2>&1
  1181. comprobarError $? 913 $1
  1182. else
  1183. # Intentamos con service (Upstart)
  1184. which service > /dev/null 2>&1
  1185. if [ $? -eq 0 ]; then
  1186. #echo -en " (Upstart)..." | tee -a $logFile
  1187. service $1 reload > /dev/null 2>&1
  1188. comprobarError $? 913 $1
  1189. else
  1190. # Intentamos con init.d (SystemV)
  1191. #echo -en " (SystemV)..." | tee -a $logFile
  1192. /etc/init.d/$1 reload > /dev/null 2>&1
  1193. comprobarError $? 913 $1
  1194. fi
  1195. fi
  1196. # Mejora: comprobar si el servicio está funcionando
  1197. #echo -en " OK.\n" | tee -a $logFile
  1198. }
  1199. configurarCortafuegos() {
  1200. # Configuramos cortafuegos (añadir reglas y encender)
  1201. # Comprobamos si estamos usando SSH
  1202. esSSH $PPID
  1203. if [ $debianOS = true ];then
  1204. ufw allow 80/tcp >> $logFile 2>&1
  1205. comprobarError $? 906 "80/tcp"
  1206. if [ $sshControl = true ];then
  1207. ufw allow 22/tcp >> $logFile 2>&1
  1208. comprobarError $? 906 "22/tcp"
  1209. fi
  1210. if [ $sslOn = true ];then
  1211. ufw allow 443/tcp >> $logFile 2>&1
  1212. comprobarError $? 906 "443/tcp"
  1213. fi
  1214. ufw --force enable >> $logFile 2>&1
  1215. comprobarError $? 907
  1216. elif [ $rhelOS = true ];then
  1217. firewall-cmd --add-port=80/tcp >> $logFile 2>&1
  1218. comprobarError $? 906 "80/tcp"
  1219. if [ $sshControl = true ];then
  1220. firewall-cmd --add-port=22/tcp >> $logFile 2>&1
  1221. comprobarError $? 906 "22/tcp"
  1222. fi
  1223. if [ $sslOn = true ];then
  1224. firewall-cmd --add-port=443/tcp >> $logFile 2>&1
  1225. comprobarError $? 906 "443/tcp"
  1226. fi
  1227. firewall-cmd --runtime-to-permanent >> $logFile 2>&1
  1228. comprobarError $? 907
  1229. habilitarServicio firewalld >> $logFile 2>&1
  1230. comprobarError $? 907
  1231. fi
  1232. unset sshControl
  1233. }
  1234. esSSH() {
  1235. p=${1:-$PPID}
  1236. #read pid name x ppid y < <( cat /proc/$p/stat )
  1237. read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
  1238. [[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
  1239. [ "$ppid" -le 1 ] && { sshControl=false; return 1; }
  1240. esSSH $ppid
  1241. }
  1242. descargarMediaWiki() {
  1243. # Descargar la versión 1.31.0 de MediaWiki
  1244. if [ ! -d ./var ];then
  1245. comprobarError 1 5 "./var"
  1246. fi
  1247. curl "https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz" 2>/dev/null | tar -xz -C "./var/"
  1248. comprobarError $? 501
  1249. }
  1250. configurarMediaWiki() {
  1251. # Configuramos MediaWiki
  1252. # Copiamos archivos y permisos
  1253. if [ ! -f /var/www/$dominioMediaWiki/LocalSettings.php ];then
  1254. cp -R ./var/mediawiki-1.31.0/ /var/www/$dominioMediaWiki
  1255. comprobarError $? 502
  1256. # Configuramos LocalSettings.php (y crea la base de datos por nosotros)
  1257. nombreDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
  1258. userDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
  1259. 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
  1260. comprobarError $? 502
  1261. # Configuraciones adicionales
  1262. sed -i '/$wgEnableEmail =/c\$wgEnableEmail = false;' /var/www/$dominioMediaWiki/LocalSettings.php
  1263. comprobarError $? 502
  1264. sed -i '/$wgEnableUploads =/c\$wgEnableUploads = true;' /var/www/$dominioMediaWiki/LocalSettings.php
  1265. comprobarError $? 502
  1266. echo -en "\$wgArticlePath = \"/wiki/\$1\";\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1267. echo -en "\$wgUsePathInfo = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1268. echo -en "\$wgGroupPermissions['*']['createaccount'] = false;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1269. echo -en "\$wgGroupPermissions['*']['edit'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1270. echo -en "\$wgGroupPermissions['*']['read'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1271. # Actualizamos permisos
  1272. chown -R $webServerUser:$webServerGroup /var/www/$dominioMediaWiki
  1273. comprobarError $? 502
  1274. # Configuramos VirtualHost
  1275. if [ $apacheOn = true ] && [ $sslOn = false ];then
  1276. virtualHost="./etc/apache2/sites-available/mediawiki.conf"
  1277. elif [ $nginxOn = true ] && [ $sslOn = false ];then
  1278. virtualHost="./etc/nginx/sites-available/mediawiki.conf"
  1279. elif [ $apacheOn = true ] && [ $sslOn = true ];then
  1280. virtualHost="./etc/apache2/sites-available/mediawiki-ssl.conf"
  1281. elif [ $nginxOn = true ] && [ $sslOn = true ];then
  1282. virtualHost="./etc/nginx/sites-available/mediawiki-ssl.conf"
  1283. else
  1284. comprobarError 1 502
  1285. fi
  1286. if [ ! -f $virtualHost ];then
  1287. comprobarError $? 502
  1288. fi
  1289. instalarVirtualHost "/var/www/$dominioMediaWiki" $virtualHost $dominioMediaWiki $aliasMediaWiki
  1290. unset virtualHost socket
  1291. else
  1292. comprobarError 1 503 $dominioMediaWiki
  1293. fi
  1294. }
  1295. crearDBMediaWiki() {
  1296. # DEPRECATED: Borrar
  1297. # Creamos una base de datos para MediaWiki
  1298. dbDir="./etc/db"
  1299. if [ ! -d $dbDir ];then
  1300. mkdir $dbDir 2>/dev/null
  1301. comprobarError $? 503
  1302. fi
  1303. dbFile=$dbDir"/mediawiki.sql"
  1304. nombreDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
  1305. userDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g')
  1306. echo -en "CREATE DATABASE IF NOT EXISTS $nombreDBMW;\n" > $dbFile
  1307. echo -en "GRANT ALL PRIVILEGES ON $nombreDBMW.* TO '$userDBMW'@'localhost' IDENTIFIED BY '$sqlPasswd';\n" >> $dbFile
  1308. mysql -u root --password=$sqlPasswd < $dbFile
  1309. control=$?
  1310. rm -f $dbFile 2>/dev/null
  1311. comprobarError $? 503
  1312. comprobarError $control 503
  1313. unset control dbFile
  1314. }
  1315. descargarMoodle() {
  1316. # Descargar la versión 1.31.0 de MediaWiki
  1317. if [ ! -d ./var ];then
  1318. comprobarError 1 5 "./var"
  1319. fi
  1320. #echo -en "Descargando Moodle-3.5-1..." | tee -a $logFile
  1321. #curl -o "./var/moodle-3.5.1.tgz" "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" >> $logFile 2>&1
  1322. curl "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" 2>/dev/null | tar -xz -C "./var/"
  1323. comprobarError $? 501
  1324. #echo -en " OK.\n" | tee -a $logFile
  1325. }
  1326. # Comprobación del sistema e inicialización
  1327. inicializarVariables
  1328. comprobarRoot
  1329. OSInfo
  1330. comprobarDependencias
  1331. # Bienvenida
  1332. mostrarBienvenida
  1333. # Selección de componentes (express vs avanzada)
  1334. mostrarExpress
  1335. # Instalación Servidor Web
  1336. if [ $apacheOn = true ]; then
  1337. echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
  1338. # {
  1339. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1340. instalarApache
  1341. progreso=$((progreso + 1))
  1342. # } > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1343. echo -en " OK.\n" | tee -a $logFile
  1344. elif [ $nginxOn = true ]; then
  1345. echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
  1346. # {
  1347. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1348. instalarNginx
  1349. progreso=$((progreso + 1))
  1350. # } > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1351. echo -en " OK.\n" | tee -a $logFile
  1352. fi
  1353. # Instalación Base de Datos
  1354. if [ $mySQLOn = true ]; then
  1355. echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
  1356. # {
  1357. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1358. instalarMySQL
  1359. progreso=$((progreso + 1))
  1360. # } > >(whiptail --gauge "Instalando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1361. echo -en " OK.\n" | tee -a $logFile
  1362. elif [ $mariaDBOn = true ]; then
  1363. echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
  1364. # {
  1365. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1366. instalarMariaDB
  1367. progreso=$((progreso + 1))
  1368. # } > >(whiptail --gauge "Instalando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1369. echo -en " OK.\n" | tee -a $logFile
  1370. fi
  1371. # Instalación PHP-7.2
  1372. if [ $phpOn = true ]; then
  1373. echo -en "Instalando PHP-7..." | tee -a $logFile
  1374. # {
  1375. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1376. instalarPHP
  1377. progreso=$((progreso + 1))
  1378. # } > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1379. echo -en " OK.\n" | tee -a $logFile
  1380. fi
  1381. # Instalación SSL/TLS
  1382. if [ $sslOn = true ];then
  1383. echo -en "Instalando SSL/TLS..." | tee -a $logfile
  1384. # {
  1385. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1386. sleep 2
  1387. progreso=$((progreso + 1))
  1388. # } > >(whiptail --gauge "Instalando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1389. echo -en " OK.\n" | tee -a $logFile
  1390. fi
  1391. # Configuración Web Server
  1392. if [ $apacheOn = true ];then
  1393. echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
  1394. # {
  1395. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1396. configurarApache
  1397. progreso=$((progreso + 1))
  1398. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1399. echo -en " OK.\n" | tee -a $logFile
  1400. elif [ $nginxOn = true ]; then
  1401. echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
  1402. # {
  1403. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1404. configurarNginx
  1405. progreso=$((progreso + 1))
  1406. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1407. echo -en " OK.\n" | tee -a $logFile
  1408. fi
  1409. # Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
  1410. if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
  1411. habilitarServicio "$sqlServerName"
  1412. echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile
  1413. # {
  1414. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1415. establecerSQLPasswd
  1416. progreso=$((progreso + 1))
  1417. # } > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1418. echo -en " OK.\n" | tee -a $logFile
  1419. fi
  1420. # Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
  1421. if [ $phpOn = true ];then
  1422. echo -en "Configurando PHP-7..." | tee -a $logFile
  1423. # {
  1424. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1425. configurarPHP
  1426. progreso=$((progreso + 1))
  1427. # } > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1428. echo -en " OK.\n" | tee -a $logFile
  1429. fi
  1430. # Configuración SSL/TLS
  1431. # Generar certificados
  1432. # Configurar certificados
  1433. if [ $sslOn = true ];then
  1434. echo -en "Configurando SSL/TLS..." | tee -a $logFile
  1435. # {
  1436. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1437. sleep 2
  1438. progreso=$((progreso + 1))
  1439. # } > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1440. echo -en " OK.\n" | tee -a $logFile
  1441. fi
  1442. # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
  1443. # {
  1444. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1445. if [ $apacheOn = true ];then
  1446. habilitarServicio $webServerName
  1447. elif [ $nginxOn = true ];then
  1448. habilitarServicio $webServerName
  1449. if [ $phpOn = true ];then
  1450. habilitarServicio $phpFPMName
  1451. fi
  1452. fi
  1453. progreso=$((progreso + 1))
  1454. # } > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1455. # MediaWiki
  1456. if [ $mediaWikiOn = true ]; then
  1457. # Descargar MediaWiki
  1458. echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
  1459. # {
  1460. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1461. descargarMediaWiki
  1462. progreso=$((progreso + 1))
  1463. # } > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1464. echo -en " OK.\n" | tee -a $logFile
  1465. # Configurar MediWiki
  1466. echo -en "Configurando MediaWiki..." | tee -a $logFile
  1467. # {
  1468. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1469. configurarMediaWiki
  1470. progreso=$((progreso + 1))
  1471. # } > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1472. echo -en " OK.\n" | tee -a $logFile
  1473. fi
  1474. # Moodle
  1475. if [ $moodleOn = true ]; then
  1476. # Descargar Moodle
  1477. echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
  1478. # {
  1479. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1480. descargarMoodle
  1481. progreso=$((progreso + 1))
  1482. # } > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1483. echo -en " OK.\n" | tee -a $logFile
  1484. # Configuración Moodle
  1485. echo -en "Configurando Moodle..." | tee -a $logFile
  1486. # {
  1487. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1488. sleep 2
  1489. progreso=$((progreso + 1))
  1490. # } > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1491. echo -en " OK.\n" | tee -a $logFile
  1492. fi
  1493. # Configurar Virtual Hosts
  1494. # Instalar info.php
  1495. if [ $infoPHPOn = true ];then
  1496. echo -en "Configurando 'info.php'..." | tee -a $logFile
  1497. instalarPHPInfo
  1498. if [ $? -eq 0 ];then
  1499. echo -en " OK.\n" | tee -a $logFile
  1500. else
  1501. echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
  1502. fi
  1503. fi
  1504. # Añadir reglas del cortafuegos
  1505. echo -en "Configurando Cortafuegos..." | tee -a $logFile
  1506. # {
  1507. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1508. configurarCortafuegos
  1509. progreso=$((progreso + 1))
  1510. # } > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1511. echo -en " OK.\n" | tee -a $logFile
  1512. # Configurar actualizaciones
  1513. if [ $actualizacionesOn = true ]; then
  1514. echo -en "Configurando Actualizaciones Automáticas..." | tee -a $logFile
  1515. # {
  1516. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1517. sleep 2
  1518. progreso=$((progreso + 1))
  1519. # } > >(whiptail --gauge "Configurando actualizaciones automáticas..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1520. echo -en " OK.\n" | tee -a $logFile
  1521. fi