install 48 KB

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