install 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985
  1. #!/bin/bash
  2. #################################################################
  3. # auto-elearning #
  4. # Instala automáticamente una Wiki (MediaWiki) y un Campus #
  5. # Virtual (Moodle). #
  6. # Para ello instala un entorno LEMP (GNU/Linux+Nginx+MySQL/ #
  7. # MariaDB+PHP) o LAMP (GNU/Linux+Apache+MySQL/MariaDB+PHP). #
  8. # Además instala certificados SSL/TLS válidos de Let's Encrypt #
  9. # (o auto-firmados) y genera copias de seguridad diariamente. #
  10. # #
  11. # Guzman Castanedo Villalba (guzman@castanedo.es) Junio 2018 #
  12. # GPLv3 (https://www.gnu.org/licenses/gpl.html) #
  13. #################################################################
  14. comprobarError() {
  15. # Permite comprobar si se ha producido un error y de serlo devuelve un código de error
  16. # comprobarError exitNum codeNum extraInfo
  17. # 1xx: Servidor Web
  18. # 2xx: Base de Datos
  19. # 3xx: PHP
  20. # 4xx: SSL/TLS
  21. # 5xx: MediaWiki
  22. # 6xx: Moodle
  23. # 7xx: Backup automático
  24. # 8xx: Dependencias
  25. # 9xx: Servicios & Firewall
  26. type="ERROR"
  27. exitNum=$1
  28. shift
  29. codeNum=$1
  30. shift
  31. extraInfo=$@
  32. case $codeNum in
  33. 1)
  34. error="$type $codeNum:\tInstalación interrumpida por el usuario.\n"
  35. ;;
  36. 2)
  37. error="$type $codeNum:\tError interno (selección express).\n"
  38. ;;
  39. 3)
  40. error="$type $codeNum:\tError interno (selección avanzada).\n"
  41. ;;
  42. 4)
  43. error="\n$type $codeNum:\tEl archivo '"$(realpath $extraInfo)"' no existe.\n"
  44. ;;
  45. 5)
  46. error="\n$type $codeNum:\tEl directorio '"$(realpath $extraInfo)"' no existe.\n"
  47. ;;
  48. 6)
  49. error="$type $codeNum:\tError interno (selección SSL/TLS).\n"
  50. ;;
  51. 100)
  52. error="$type $codeNum:\tError interno (selección del servidor web).\n"
  53. ;;
  54. 101)
  55. error="\n$type $codeNum:\tError al instalar Apache2.\nDetalles:\n$extraInfo\n"
  56. ;;
  57. 102)
  58. error="\n$type $codeNum:\tError al instalar Nginx.\nDetalles:\n$extraInfo\n"
  59. ;;
  60. 103)
  61. error="\n$type $codeNum:\tError al nstalar repositorio 'epel-release'.\nDetalles:\n$extraInfo\n"
  62. ;;
  63. 104)
  64. error="\n$type $codeNum:\tError interno (instalación Apache2).\n"
  65. ;;
  66. 105)
  67. error="\n$type $codeNum:\tError interno (instalación Nginx).\n"
  68. ;;
  69. 106)
  70. type="WARNING"
  71. error="\n$type $codeNum:\tImposible instalar 'info.php'.\n"
  72. ;;
  73. 107)
  74. error="\n$type $codeNum:\tError al configurar Nginx.\n"
  75. ;;
  76. 108)
  77. error="\n$type $codeNum:\tError al configurar Apache2.\n"
  78. ;;
  79. 200)
  80. error="$type $codeNum:\tError interno (selección de base de datos).\n"
  81. ;;
  82. 201)
  83. error="\n$type $codeNum:\tError al instalar MySQL.\nDetalles:\n$extraInfo\n"
  84. ;;
  85. 202)
  86. error="\n$type $codeNum:\tError al instalar MariaDB.\nDetalles:\n$extraInfo\n"
  87. ;;
  88. 203)
  89. error="\n$type $codeNum:\tError interno (instalación MySQL).\n"
  90. ;;
  91. 204)
  92. error="\n$type $codeNum:\tError interno (instalación MariaDB).\n"
  93. ;;
  94. 205)
  95. error="\n$type $codeNum:\t$DIST no incluye MySQL en sus repositorios.\n"
  96. ;;
  97. 206)
  98. type="WARNING"
  99. error="\n$type $codeNum:\tUsuario 'root' ya dispone de contraseña."
  100. ;;
  101. 207)
  102. error="\n$type $codeNum:\tImposible cambiar la contraseña de 'root'."
  103. ;;
  104. 208)
  105. error="\n$type $codeNum:\tImposible desactivar acceso 'root' desde el exterior."
  106. ;;
  107. 209)
  108. error="\n$type $codeNum:\tImposible eliminar usuarios anónimos."
  109. ;;
  110. 210)
  111. type="WARNING"
  112. error="\n$type $codeNum:\tImposible eliminar bases de datos de pruebas."
  113. ;;
  114. 211)
  115. type="WARNING"
  116. error="\n$type $codeNum:\tImposible eliminar los permisos de las bases de datos de pruebas."
  117. ;;
  118. 212)
  119. error="\n$type $codeNum:\tImposible recargar base de datos."
  120. ;;
  121. 213)
  122. error="\n$type $codeNum:\tImposible configurar SQL.\n"
  123. ;;
  124. 214)
  125. type="WARNING"
  126. error="\n$type $codeNum:\tSQL ya está configurado."
  127. ;;
  128. 300)
  129. error="\n$type $codeNum:\tError interno (instalación PHP-7.2).\n"
  130. ;;
  131. 301)
  132. error="\n$type $codeNum:\tError interno (Web Server no seleccionado).\n"
  133. ;;
  134. 302)
  135. error="\n$type $codeNum:\tError al instalar PHP-7.2.\nDetalles:\n$extraInfo\n"
  136. ;;
  137. 303)
  138. error="\n$type $codeNum:\tError al instalar Repositorio Remi.\nDetalles:\n$extraInfo\n"
  139. ;;
  140. 304)
  141. error="\n$type $codeNum:\tSistema Operativo no compatible con PHP-7.2 ($OS $DIST $REV).\n"
  142. ;;
  143. 305)
  144. error="\n$type $codeNum:\tImposible configurar PHP-7.2.\n"
  145. ;;
  146. 401)
  147. error="\n$type $codeNum:\tError al instalar 'certbot' (Let's Encrypt).\n"
  148. ;;
  149. 402)
  150. error="\n$type $codeNum:\tImposible generar Certificados Autofirmados.\n"
  151. ;;
  152. 403)
  153. error="\n$type $codeNum:\tImposible generar claves de intercambio Diffie-Hellman.\n"
  154. ;;
  155. 404)
  156. error="\n$type $codeNum:\tImposible generar Certificados Let's Encrypt.\n"
  157. ;;
  158. 501)
  159. error="\n$type $codeNum:\tImposible descargar MediaWiki-1.31.0.\n"
  160. ;;
  161. 502)
  162. error="\n$type $codeNum:\tImposible configurar MediaWiki-1.31.0.\n"
  163. ;;
  164. 503)
  165. type="WARNING"
  166. error="\n$type $codeNum:\tYa existe una copia configurada de MediaWiki en el dominio: '$extraInfo'."
  167. ;;
  168. 601)
  169. error="\n$type $codeNum:\tImposible descargar Moodle-3.5.1.\n"
  170. ;;
  171. 602)
  172. error="\n$type $codeNum:\tImposible configurar Moodle-3.5.1.\n"
  173. ;;
  174. 603)
  175. type="WARNING"
  176. error="\n$type $codeNum:\tYa existe una copia configurada de Moodle en el dominio: '$extraInfo'."
  177. ;;
  178. 604)
  179. error="\n$type $codeNum:\tImposible configurar SELinux.\n"
  180. ;;
  181. 605)
  182. error="\n$type $codeNum:\tImposible instalar 'policycoreutils-python'.Detalles:\n$extraInfo\n"
  183. ;;
  184. 701)
  185. type="WARNING"
  186. error="\n$tupe $codeNum:\tImposible configurar actualizaciones automáticas.\n"
  187. ;;
  188. 800)
  189. error="$type $codeNum:\tEs necesario ser root ('sudo $0').\n"
  190. ;;
  191. 801)
  192. error="$type $codeNum:\t'whiptail' no instalado.\n"
  193. ;;
  194. 802)
  195. error="$type $codeNum:\t'hostnamectl' no instalado.\n"
  196. ;;
  197. 803)
  198. error="$type $codeNum:\t'apt-get' no instalado.\n"
  199. ;;
  200. 804)
  201. error="$type $codeNum:\t'yum' no instalado.\n"
  202. ;;
  203. 805)
  204. error="\n$type $codeNum:\tImposible actualizar repositorio\nDetalles:\n$extraInfo.\n"
  205. ;;
  206. 806)
  207. error="$type $codeNum:\t'ufw' no instalado.\n"
  208. ;;
  209. 807)
  210. error="$type $codeNum:\t'firewall-cmd' no instalado.\n"
  211. ;;
  212. 808)
  213. error="$type $codeNum:\t'tput' no instalado.\nDetalles:\n$extraInfo\n"
  214. ;;
  215. 809)
  216. error="$type $codeNum:\t'sed' no instalado.\nDetalles:\n$extraInfo\n"
  217. ;;
  218. 810)
  219. error="$type $codeNum:\t'curl' no instalado.\nDetalles:\n$extraInfo\n"
  220. ;;
  221. 811)
  222. error="$type $codeNum:\t'tar' no instalado.\nDetalles:\n$extraInfo\n"
  223. ;;
  224. 812)
  225. error="$type $codeNum:\t'gzip' no instalado.\nDetalles:\n$extraInfo\n"
  226. ;;
  227. 813)
  228. error="$type $codeNum:\t'bzip2' no instalado.\nDetalles:\n$extraInfo\n"
  229. ;;
  230. 814)
  231. error="$type $codeNum:\t'xz' no instalado.\nDetalles:\n$extraInfo\n"
  232. ;;
  233. 815)
  234. error="$type $codeNum:\t'openssl' no instalado.\nDetalles:\n$extraInfo\n"
  235. ;;
  236. 816)
  237. error="$type $codeNum:\t'find' no instalado.\n"
  238. ;;
  239. 900)
  240. error="$type $codeNum:\tError interno (habilitar servicio).\n"
  241. ;;
  242. 901)
  243. error="$type $codeNum:\tImposible encender servicio '$extraInfo'.\n"
  244. ;;
  245. 902)
  246. error="$type $codeNum:\tImposible habilitar servicio '$extraInfo' durante el arranque.\n"
  247. ;;
  248. 903)
  249. error="$type $codeNum:\tError interno (deshabilitar servicio).\n"
  250. ;;
  251. 904)
  252. error="$type $codeNum:\tImposible parar servicio '$extraInfo'.\n"
  253. ;;
  254. 905)
  255. error="$type $codeNum:\tImposible deshabilitar servicio '$extraInfo' durante el arranque.\n"
  256. ;;
  257. 906)
  258. type="WARNING"
  259. error="\n$type $codeNum:\tImposible añadir regla al cortafuegos ('$extraInfo').\n"
  260. ;;
  261. 907)
  262. type="WARNING"
  263. error="\n$type $codeNum:\tImposible encender cortafuegos.\n"
  264. ;;
  265. 908)
  266. error="\n$type $codeNum:\tError interno (instalar Virtual Host).\n"
  267. ;;
  268. 909)
  269. error="\n$type $codeNum:\tVirtual Host '$extraInfo' no existe.\n"
  270. ;;
  271. 910)
  272. error="\n$type $codeNum:\tImposible copiar Virtual Host '$extraInfo'.\n"
  273. ;;
  274. 911)
  275. error="\n$type $codeNum:\tImposible activar Virtual Host '$extraInfo'.\n"
  276. ;;
  277. 912)
  278. error="\n$type $codeNum:\tError interno (recargar servicio).\n"
  279. ;;
  280. 913)
  281. error="\n$type $codeNum:\tImposible recargar servicio '$extraInfo'.\n"
  282. ;;
  283. *)
  284. error="ERROR 13:\tError interno (comprobación de errores)\n"
  285. exitNum=1
  286. codeNum=13
  287. ;;
  288. esac
  289. if [ $exitNum -ne 0 ];then
  290. echo -en "$error" | tee -a $logFile
  291. if [ $type = "ERROR" ];then
  292. exit $codeNum
  293. fi
  294. fi
  295. unset error exitNum codeNum type
  296. }
  297. OSInfo() {
  298. # Detecta el OS en el que se está ejecutando el programa, así como su versión
  299. echo -en "Detectando SO..." >> $logFile
  300. OS=$(uname -s)
  301. if [ $OS = "Linux" ]; then
  302. OS="GNU/Linux"
  303. if [ -f /etc/os-release ]; then
  304. DIST=$(grep ^NAME= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  305. REV=$(grep ^VERSION= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  306. ID_LIKE=$(grep ^ID_LIKE= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  307. VERSION=$(grep ^VERSION_ID= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
  308. for i in $ID_LIKE; do
  309. #echo -en "$i\n"
  310. case $i in
  311. debian|ubuntu)
  312. debianOS=true
  313. break
  314. ;;
  315. rhel|fedora)
  316. rhelOS=true
  317. break
  318. ;;
  319. *)
  320. debianOS=false
  321. rhelOS=false
  322. ;;
  323. esac
  324. done
  325. elif [ -f /etc/debian-version ]; then
  326. # Familia Debian (Debian, Ubuntu, Linux Mint, ...)
  327. DIST="Debian"
  328. REV=""
  329. ID_LIKE="debian"
  330. VERSION=""
  331. debianOS=true
  332. elif [ -f /etc/redhat-release ]; then
  333. # Familia Red-Hat (RHEL, Fedora, CentOS, ...)
  334. DIST="Red-Hat"
  335. REV=""
  336. ID_LIKE="rhel"
  337. VERSION=""
  338. rhelOS=true
  339. else
  340. # Other Linux (No Soportado)
  341. DIST=""
  342. REV=""
  343. ID_LIKE=""
  344. VERSION=""
  345. fi
  346. else
  347. # UNIX, OS X, ... (No Soportado)
  348. DIST=$OS
  349. REV=""
  350. ID_LIKE=""
  351. VERSION=""
  352. fi
  353. echo -en " $OS $DIST $REV\n" >> $logFile
  354. HDInfo=$(df -h | head -1)"\n"$(df -h | grep ^/dev/sd)"\n"$(df -h | grep ^/dev/mapper)
  355. echo -en "$HDInfo\n" >> $logFile
  356. }
  357. comprobarRoot() {
  358. # Comprueba si se está ejecutando con privilegios de root
  359. comprobarError $(id -u) 800
  360. }
  361. comprobarDependencias() {
  362. # Comprueba si están instalados todos los programas necesarios.
  363. # En la mayoría de los casos, trata de instalarlos.
  364. # Comprobamos whiptail
  365. which whiptail > /dev/null 2>&1
  366. comprobarError $? 801
  367. # Comprobamos hostnamectl
  368. which hostnamectl > /dev/null 2>&1
  369. comprobarError $? 802
  370. which find > /dev/null 2>&1
  371. comprobarError $? 816
  372. if [ $debianOS = true ];then
  373. # Comprobamos apt-get
  374. which apt-get > /dev/null 2>&1
  375. comprobarError $? 803
  376. # Actualizamos base de datos del repositorio
  377. echo -en "Actualizando repositorio APT..." | tee -a $logFile
  378. result=$(apt-get -q -y update 2>&1)
  379. comprobarError $? 805 $result
  380. echo -en " OK.\n" | tee -a $logFile
  381. # Comprobamos Firewall (ufw)
  382. which ufw > /dev/null 2>&1
  383. comprobarError $? 806
  384. # Comprobamos tput
  385. which tput > /dev/null 2>&1
  386. if [ $? -ne 0 ];then
  387. result=$(apt-get -q -y ncurses-bin 2>&1)
  388. comprobarError $? 808 $result
  389. fi
  390. # Comprobar sed
  391. which sed > /dev/null 2>&1
  392. if [ $? -ne 0 ];then
  393. result=$(apt-get -q -y sed 2>&1)
  394. comprobarError $? 809 $result
  395. fi
  396. # Comprobar curl
  397. which curl > /dev/null 2>&1
  398. if [ $? -ne 0 ];then
  399. result=$(apt-get -q -y curl 2>&1)
  400. comprobarError $? 810 $result
  401. fi
  402. # Comprobamos tar, gzip, bzip2 y xz
  403. which tar > /dev/null 2>&1
  404. if [ $? -ne 0 ];then
  405. result=$(apt-get -q -y install tar 2>&1)
  406. comprobarError $? 811 $result
  407. fi
  408. which gzip > /dev/null 2>&1
  409. if [ $? -ne 0 ];then
  410. result=$(apt-get -q -y install gzip 2>&1)
  411. comprobarError $? 812 $result
  412. fi
  413. which bzip2 > /dev/null 2>&1
  414. if [ $? -ne 0 ];then
  415. result=$(apt-get -q -y install bzip2 2>&1)
  416. comprobarError $? 813 $result
  417. fi
  418. which xz > /dev/null 2>&1
  419. if [ $? -ne 0 ];then
  420. result=$(apt-get -q -y install xz-utils 2>&1)
  421. comprobarError $? 814 $result
  422. fi
  423. which openssl > /dev/null 2>&1
  424. if [ $? -ne 0 ];then
  425. result=$(apt-get -q -y install openssl 2>&1)
  426. comprobarError $? 815 $result
  427. fi
  428. fi
  429. if [ $rhelOS = true ]; then
  430. # Comprobamos yum
  431. which yum > /dev/null 2>&1
  432. comprobarError $? 804
  433. # Actualizamos base de datos del repositorio
  434. echo -en "Actualizando repositorio YUM..." | tee -a $logFile
  435. result=$(yum -y makecache 2>&1)
  436. comprobarError $? 805 $result
  437. echo -en " OK.\n" | tee -a $logFile
  438. # Comprobamos Firewall (firewall-cmd)
  439. which firewall-cmd > /dev/null 2>&1
  440. comprobarError $? 807
  441. # Comprobamos tput
  442. which tput > /dev/null 2>&1
  443. if [ $? -ne 0 ];then
  444. result=$(yum -y ncurses 2>&1)
  445. comprobarError $? 808 $result
  446. fi
  447. # Comprobar sed
  448. which sed > /dev/null 2>&1
  449. if [ $? -ne 0 ];then
  450. result=$(yum -y sed 2>&1)
  451. comprobarError $? 809 $result
  452. fi
  453. # Comprobar curl
  454. which curl > /dev/null 2>&1
  455. if [ $? -ne 0 ];then
  456. result=$(yum -y curl 2>&1)
  457. comprobarError $? 810 $result
  458. fi
  459. # Comprobamos tar, gzip, bzip2 y xz
  460. which tar > /dev/null 2>&1
  461. if [ $? -ne 0 ];then
  462. result=$(yum -y install tar 2>&1)
  463. comprobarError $? 811 $result
  464. fi
  465. which gzip > /dev/null 2>&1
  466. if [ $? -ne 0 ];then
  467. result=$(yum -y install gzip 2>&1)
  468. comprobarError $? 812 $result
  469. fi
  470. which bzip2 > /dev/null 2>&1
  471. if [ $? -ne 0 ];then
  472. result=$(yum -y install bzip2 2>&1)
  473. comprobarError $? 813 $result
  474. fi
  475. which xz > /dev/null 2>&1
  476. if [ $? -ne 0 ];then
  477. result=$(yum -y install xz 2>&1)
  478. comprobarError $? 814 $result
  479. fi
  480. which openssl > /dev/null 2>&1
  481. if [ $? -ne 0 ];then
  482. result=$(yum -y install openssl 2>&1)
  483. comprobarError $? 815 $result
  484. fi
  485. fi
  486. }
  487. inicializarVariables() {
  488. # Inicializa las variables que necesitan de un estado previo
  489. debianOS=false
  490. rhelOS=false
  491. apacheOn=false
  492. nginxOn=false
  493. mySQLOn=false
  494. mariaDBOn=false
  495. phpOn=false
  496. sslOn=false
  497. letsEncryptOn=false
  498. mediaWikiOn=false
  499. moodleOn=false
  500. infoPHPOn=false
  501. backupOn=false
  502. hostname=""
  503. logFile="./."$(basename $0)".log"
  504. maxUpload="100M"
  505. webServerName=""
  506. webServerUser=""
  507. webServerGroup=""
  508. sqlServerName=""
  509. phpFPMName=""
  510. nombreMediaWiki=""
  511. dominioMediaWiki=""
  512. passwdMediaWiki=""
  513. nombreMoodle=""
  514. nombreCortoMoodle=""
  515. dominioMoodle=""
  516. passwdMoodle=""
  517. }
  518. instalacionExpress() {
  519. # Permite una instalación rápida, haciendo el menor número de preguntas
  520. nginxOn=true
  521. mariaDBOn=true
  522. phpOn=true
  523. sslOn=true
  524. letsEncryptOn=true
  525. mediaWikiOn=true
  526. moodleOn=true
  527. backupOn=true
  528. # Preguntas mínimas
  529. establecerFQDN
  530. leerSQLPasswd
  531. mostrarMediaWiki
  532. mostrarMoodle
  533. mostrarConfirmacion
  534. }
  535. mostrarBienvenida() {
  536. # Pantalla de bienvenida y muestra SO y estado de los discos
  537. ANCHO=$(tput cols)
  538. ALTO=$(tput lines)
  539. if [ $debianOS = false ] && [ $rhelOS = false ]; then
  540. 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"
  541. exit 1
  542. fi
  543. whiptail --title "INSTALACION MEDIAWIKI" --yesno "Este script automatiza completamente la instalación de una WIKI y un CAMPUS VIRTUAL.\nPara ello instala un servidor LAMP, el software MediaWiki y configura todo lo necesario.\n\nInformación del sistema:\nOS: $OS $DIST $REV\n$HDInfo" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --yes-button "Continuar" --no-button "Salir"
  544. comprobarError $? 1
  545. }
  546. mostrarExpress() {
  547. # Pantalla de elección entre instalación express o avanzada
  548. express=$(whiptail --title "INSTALACION EXPRESS" --radiolist "<ESPACIO>: seleccionar <TAB>: cambiar <FLECHAS>: moverse\n\nLa instalación express instala Nginx, MariaDB, PHP-7, Let's Encrypt, MediaWiki, Moodle y backups automático.\nSeleccione el tipo de instalación que desee:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \
  549. "Express" "Instalación rápida" ON \
  550. "Avanzada" "Permite escoger todas las opciones disponibles" OFF \
  551. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  552. comprobarError $? 1
  553. case $express in
  554. Express)
  555. instalacionExpress
  556. # DECIDIR QUÉ OPCIONES SON LAS MÍNIMAS
  557. ;;
  558. Avanzada)
  559. mostrarAvanzada
  560. ;;
  561. *)
  562. comprobarError 1 2
  563. ;;
  564. esac
  565. unset express
  566. }
  567. mostrarAvanzada() {
  568. # Pantalla que permite instalar un servidor LAMP o LEMP
  569. 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 \
  570. "LEMP" "GNU/Linux + (E)Nginx + MySQL/MariaDB + PHP-7" ON \
  571. "LAMP" "GNU/Linux + Apache + MySQL/MariaDB + PHP-7" OFF \
  572. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  573. comprobarError $? 1
  574. for i in $webServer; do
  575. case $i in
  576. LEMP)
  577. nginxOn=true
  578. ;;
  579. LAMP)
  580. apacheOn=true
  581. ;;
  582. *)
  583. comprobarError 1 100
  584. ;;
  585. esac
  586. done
  587. # Opciones comunes
  588. establecerFQDN
  589. mostrarDatabase
  590. phpOn=true
  591. establecerMaxUpload
  592. mostrarComponentes
  593. mostrarConfirmacion
  594. unset webServer
  595. }
  596. mostrarComponentes() {
  597. # Pantalla de elección de componentes (SSL/TLS, MediaWiki, Moodle, InfoPHP y Backup)
  598. 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 \
  599. "SSL/TLS" "Instalar certificados para activar HTTPS" ON \
  600. "MediaWiki" "Instalar wiki con MediaWiki" ON \
  601. "Moodle" "Instalar campus virtual con Moodle" ON \
  602. "InfoPHP" "Instalar info.php (sólo para pruebas)" OFF \
  603. "Backup" "Programar backups automáticos" ON \
  604. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  605. comprobarError $? 1
  606. # Mejora: autodetección de componentes ya instalados
  607. for i in $componentes; do
  608. case $i in
  609. \"SSL/TLS\")
  610. # 2 Opciones: Let's Encrypt o Autofirmado
  611. mostrarSSL
  612. ;;
  613. \"MediaWiki\")
  614. mediaWikiOn=true
  615. mostrarMediaWiki
  616. ;;
  617. \"Moodle\")
  618. moodleOn=true
  619. mostrarMoodle
  620. ;;
  621. \"InfoPHP\")
  622. infoPHPOn=true
  623. ;;
  624. \"Backup\")
  625. backupOn=true
  626. ;;
  627. *)
  628. comprobarError 1 3
  629. ;;
  630. esac
  631. done
  632. unset componentes
  633. }
  634. mostrarSSL() {
  635. # Pantalla que permite seleccionar el tipo de certificados
  636. 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 \
  637. "LetsEncrypt" "Compatible con todos los navegadores" ON \
  638. "Auto-Firmado" "Certificados auto-firmados (sólo para pruebas)" OFF \
  639. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  640. comprobarError $? 1
  641. for i in $ssl; do
  642. case $i in
  643. LetsEncrypt)
  644. sslOn=true
  645. letsEncryptOn=true
  646. ;;
  647. Auto-Firmado)
  648. sslOn=true
  649. ;;
  650. *)
  651. comprobarError 1 6
  652. ;;
  653. esac
  654. done
  655. unset ssl
  656. }
  657. mostrarMediaWiki(){
  658. # Pantalla que pregunta sobre las opciones necesarias para configurar MediaWiki
  659. # Introducir nombre wiki
  660. while [ -z "$nombreMediaWiki" ]; do
  661. 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)
  662. comprobarError $? 1
  663. done
  664. # Introducir dominio
  665. while [ -z "$dominioMediaWiki" ]; do
  666. 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)
  667. comprobarError $? 1
  668. done
  669. cont=1
  670. serverName=""
  671. aliasMediaWiki=""
  672. for dominio in $dominioMediaWiki;do
  673. if [ $cont -eq 1 ];then
  674. # Dominio Principal (ServerName)
  675. serverName=$dominio
  676. else
  677. # Dominios Secundarios (ServerAlias)
  678. aliasMediaWiki=$aliasMediaWiki" "$dominio
  679. fi
  680. cont=$((cont + 1))
  681. done
  682. dominioMediaWiki=$serverName
  683. # Introducir contraseña
  684. control=false
  685. error=""
  686. while [ $control = false ]; do
  687. 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)
  688. comprobarError $? 1
  689. passwdMediaWiki2=$(whiptail --title "CONFIGURACION MEDIAWIKI" --passwordbox "Confirme la contraseña:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
  690. comprobarError $? 1
  691. if [ -z "$passwdMediaWiki" ] || [ -z "$passwdMediaWiki2" ]; then
  692. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  693. elif [ $passwdMediaWiki != $passwdMediaWiki2 ];then
  694. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  695. else
  696. control=true
  697. fi
  698. done
  699. unset control error passwdMediaWiki2 dominio cont serverName
  700. }
  701. mostrarMoodle() {
  702. # Pantalla que pregunta sobre las opciones necesarias para configurar Moodle
  703. # Introducir Nombre Moodle
  704. while [ -z "$nombreMoodle" ]; do
  705. nombreMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el NOMBRE COMPLETO del campus virtual.\nPor ejemplo: 'Campus Virtual Ejemplo'." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  706. comprobarError $? 1
  707. done
  708. # Introducir Nombre Corto Moodle
  709. while [ -z "$nombreCortoMoodle" ]; do
  710. nombreCortoMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el NOMBRE CORTO del campus virtual.\nPor ejemplo: 'Ejemplo'." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  711. comprobarError $? 1
  712. done
  713. nombreCortoMoodle=$(echo $nombreCortoMoodle | cut -d ' ' -f 1)
  714. # Introducir dominio
  715. while [ -z "$dominioMoodle" ]; do
  716. dominioMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el dominio/subdominio del campus virtual.\nMoodle SÓLO permite un ÚNICO DOMINIO." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) moodle.$hostname --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  717. comprobarError $? 1
  718. done
  719. cont=1
  720. serverName=""
  721. aliasMoodle=""
  722. for dominio in $dominioMoodle;do
  723. if [ $cont -eq 1 ];then
  724. # Dominio Principal (ServerName)
  725. serverName=$dominio
  726. else
  727. # Dominios Secundarios (ServerAlias)
  728. aliasMeoodle=$aliasMoodle" "$dominio
  729. fi
  730. cont=$((cont + 1))
  731. done
  732. dominioMoodle=$serverName
  733. # Introducir contraseña
  734. control=false
  735. error=""
  736. while [ $control = false ]; do
  737. passwdMoodle=$(whiptail --title "CONFIGURACION MOODLE" --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)
  738. comprobarError $? 1
  739. passwdMoodle2=$(whiptail --title "CONFIGURACION MOODLE" --passwordbox "Confirme la contraseña:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
  740. comprobarError $? 1
  741. if [ -z "$passwdMoodle" ] || [ -z "$passwdMoodle2" ]; then
  742. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  743. elif [ $passwdMoodle != $passwdMoodle2 ];then
  744. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  745. else
  746. control=true
  747. fi
  748. done
  749. unset control error passwdMoodle2 dominio cont serverName aliasMoodle
  750. }
  751. mostrarConfirmacion() {
  752. # Pantalla que presenta una confirmación antes de realizar la instalación
  753. whiptail --title "INSTALACION" --yesno "ESTA TODO LISTO PARA LA INSTALACION.\n¿DESEA CONTINUAR?" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --yes-button "Instalar" --no-button "Salir"
  754. comprobarError $? 1
  755. }
  756. establecerFQDN() {
  757. # Configura el FQDN (dominio principal del servidor)
  758. while [ -z "$hostname" ]; do
  759. hostname=$(whiptail --title "FQDN" --inputbox "El nombre de dominio principal (FQDN) de este servidor es:\n"$(hostname)"\n\n¿Quieres cambiarlo por otro?" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Cambiar" --cancel-button "No Cambiar" 3>&1 1>&2 2>&3)
  760. if [ $? -eq 0 ] && [ ! -z "$hostname" ]; then
  761. hostnamectl set-hostname $hostname
  762. else
  763. hostname=$(hostname)
  764. fi
  765. done
  766. echo -en "Hostname: $hostname\n" >> $logFile
  767. }
  768. instalarApache() {
  769. # Instala Apache2
  770. if [ $debianOS = true ];then
  771. webServerName="apache2"
  772. result=$(apt-get -q -y install apache2 2>&1)
  773. comprobarError $? 101 $result
  774. elif [ $rhelOS = true ]; then
  775. webServerName="httpd"
  776. result=$(yum -y install httpd 2>&1)
  777. comprobarError $? 101 $result
  778. if [ $sslOn = true ];then
  779. # Instalamos módulo mod_ssl (no se instala por defecto)
  780. result=$(yum -y install mod_ssl 2>&1)
  781. comprobarError $? 101 $result
  782. fi
  783. else
  784. comprobarError 1 104
  785. fi
  786. deshabilitarServicio $webServerName
  787. }
  788. configurarApache() {
  789. # Configura Apache2
  790. if [ $debianOS = true ];then
  791. apacheConfFile="./etc/apache2/apache2.conf"
  792. if [ ! -f $apacheConfFile ];then
  793. comprobarError 1 4 $apacheConfFile
  794. fi
  795. cp -f $apacheConfFile /etc/$webServerName/apache2.conf 2>/dev/null
  796. comprobarError $? 108
  797. webServerUser=$(grep ^User /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
  798. webServerGroup=$(grep ^Group /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
  799. if [ ! -L /etc/$webServerName/logs ];then
  800. ln -s /var/log/apache2 /etc/$webServerName/logs 2>/dev/null
  801. comprobarError $? 108
  802. fi
  803. # Activamos mod_rewrite (no viene activado por defecto)
  804. a2enmod rewrite >/dev/null 2>&1
  805. comprobarError $? 108
  806. # Activamos mod_ssl y mod_headers (no viene activado por defecto)
  807. if [ $sslOn = true ];then
  808. a2enmod ssl >/dev/null 2>&1
  809. comprobarError $? 108
  810. a2enmod headers >/dev/null 2>&1
  811. comprobarError $? 108
  812. fi
  813. unset apacheConfFile
  814. elif [ $rhelOS = true ];then
  815. apacheConfFile="./etc/apache2/conf/httpd.conf"
  816. sslConfFile="./etc/apache2/conf.d/ssl.conf"
  817. welcomeConfFile="/etc/apache2/conf.d/welcome.conf"
  818. if [ ! -f $apacheConfFile ];then
  819. comprobarError 1 4 $apacheConfFile
  820. fi
  821. cp -f $apacheConfFile /etc/$webServerName/conf/httpd.conf 2>/dev/null
  822. comprobarError $? 108
  823. # Desactivamos Mensaje de Bienvenida
  824. if [ -f $welcomeConfFile ];then
  825. sed -i -e 's/^/#/' $welcomeConfFile
  826. comprobarError $? 108
  827. fi
  828. # Configuramos mod_ssl
  829. if [ $sslOn = true ];then
  830. if [ ! -f $sslConfFile ];then
  831. comprobarError 1 4 $sslConfFile
  832. fi
  833. cp -f $sslConfFile /etc/$webServerName/conf.d/ssl.conf 2>/dev/null
  834. comprobarError $? 108
  835. fi
  836. webServerUser=$(grep ^User /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
  837. webServerGroup=$(grep ^Group /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
  838. unset apacheConfFile sslConfFile welcomeConfFile
  839. fi
  840. if [ ! -d "/etc/$webServerName/sites-available" ];then
  841. mkdir "/etc/$webServerName/sites-available" 2>/dev/null
  842. comprobarError $? 5 "/etc/$webServerName/sites-available"
  843. fi
  844. if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
  845. mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
  846. comprobarError $? 5 "/etc/$webServerName/sites-enabled"
  847. else
  848. # Eliminar Virtual Host por defecto
  849. if [ -f /etc/$webServerName/sites-enabled/000-default.conf ];then
  850. rm -f /etc/$webServerName/sites-enabled/000-default.conf 2>/dev/null
  851. fi
  852. fi
  853. }
  854. instalarNginx() {
  855. # Instala Nginx
  856. webServerName="nginx"
  857. if [ $debianOS = true ];then
  858. result=$(apt-get -q -y install nginx 2>&1)
  859. comprobarError $? 102 $result
  860. elif [ $rhelOS = true ]; then
  861. # Hay que instalar primero otro repositorio
  862. result=$(yum -y install epel-release)
  863. comprobarError $? 103 $result
  864. result=$(yum -y install nginx 2>&1)
  865. comprobarError $? 102 $result
  866. else
  867. comprobarError 1 105
  868. fi
  869. deshabilitarServicio $webServerName
  870. }
  871. configurarNginx() {
  872. # Configura Nginx
  873. rm -Rf "/etc/$webServerName/!(sites-available|sites-enabled)" 2>/dev/null
  874. comprobarError $? 107
  875. nginxConfFile="./etc/$webServerName"
  876. if [ -d "$nginxConfFile" ];then
  877. cp -Rf $nginxConfFile/* /etc/$webServerName/ 2>/dev/null
  878. comprobarError $? 107
  879. else
  880. comprobarError 1 5 "$nginxConfFile"
  881. fi
  882. if [ ! -d "/etc/$webServerName/sites-available" ];then
  883. mkdir "/etc/$webServerName/sites-available" 2>/dev/null
  884. comprobarError $? 5 "/etc/$webServerName/sites-available"
  885. fi
  886. if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
  887. mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
  888. comprobarError $? 5 "/etc/$webServerName/sites-enabled"
  889. else
  890. # Eliminar Virtual Host por defecto
  891. if [ -f /etc/$webServerName/sites-enabled/default ];then
  892. rm -f /etc/$webServerName/sites-enabled/default 2>/dev/null
  893. fi
  894. fi
  895. # Configuramos Usuario y Grupo
  896. if [ $debianOS = true ];then
  897. webServerUser="www-data"
  898. webServerGroup=$webServerUser
  899. elif [ $rhelOS = true ];then
  900. webServerUser="nginx"
  901. webServerGroup=$webServerUser
  902. fi
  903. sed -i '/user /c\user '$webServerUser';' /etc/$webServerName/nginx.conf
  904. comprobarError $? 107
  905. unset nginxConfFile
  906. }
  907. instalarVirtualHost() {
  908. # Configuramos un Virtual Host para Apache o Nginx
  909. # Uso: instalarVirtualHost $root $virtualHost $dominio $alias
  910. if [ $# -ge 3 ];then
  911. rootVirtualHost=$(realpath $1)
  912. shift
  913. virtualHostFile=$(realpath $1)
  914. shift
  915. dominioVirtualHost=$1
  916. virtualHostName=$dominioVirtualHost".conf"
  917. shift
  918. aliasVirtualHost=$@
  919. else
  920. comprobarError 1 908
  921. fi
  922. if [ ! -f $virtualHostFile ];then
  923. comprobarError 1 909 $virtualHostName
  924. fi
  925. if [ $apacheOn = true ];then
  926. # Configuramos root, dominio y logs
  927. sed -i '/ServerName /c\\tServerName '"$dominioVirtualHost" $virtualHostFile
  928. comprobarError $? 908
  929. if [ ! -z "$aliasVirtualHost" ];then
  930. sed -i '/ServerName /a\\tServerAlias '"$aliasVirtualHost" $virtualHostFile
  931. comprobarError $? 908
  932. fi
  933. sed -i '/DocumentRoot /c\\tDocumentRoot '"$rootVirtualHost" $virtualHostFile
  934. comprobarError $? 908
  935. sed -i '/ErrorLog /c\\tErrorLog logs/'"$dominioVirtualHost"'-error.log' $virtualHostFile
  936. comprobarError $? 908
  937. sed -i '/CustomLog /c\\tCustomLog logs/'"$dominioVirtualHost"'-access.log common' $virtualHostFile
  938. comprobarError $? 908
  939. if [ $sslOn = true ];then
  940. sed -i '/SSLCertificateFile /c\\tSSLCertificateFile ssl/'"$dominioVirtualHost"'.crt' $virtualHostFile
  941. comprobarError $? 908
  942. sed -i '/SSLCertificateKeyFile /c\\tSSLCertificateKeyFile ssl/'"$dominioVirtualHost"'.key' $virtualHostFile
  943. comprobarError $? 908
  944. fi
  945. elif [ $nginxOn = true ];then
  946. # Configuramos root, dominio, logs y php-fpm.sock (NGINX)
  947. sed -i '/root /c\\troot '$rootVirtualHost';' "$virtualHostFile"
  948. comprobarError $? 908
  949. sed -i '/server_name /c\\tserver_name '"$dominioVirtualHost"' '"$aliasVirtualHost"';' $virtualHostFile
  950. comprobarError $? 908
  951. sed -i '/access_log /c\\taccess_log /var/log/nginx/'"$dominioVirtualHost"'-access.log;' $virtualHostFile
  952. comprobarError $? 908
  953. sed -i '/error_log /c\\terror_log /var/log/nginx/'"$dominioVirtualHost"'-error.log;' $virtualHostFile
  954. comprobarError $? 908
  955. socket=$(find /var/run/ -type s -name 'php*.sock')
  956. sed -i '/fastcgi_pass /c\\t\tfastcgi_pass unix:'"$socket"';' $virtualHostFile
  957. comprobarError $? 908
  958. if [ $sslOn = true ];then
  959. sed -i '/ssl_certificate /c\\tssl_certificate ssl/'"$dominioVirtualHost"'.crt;' $virtualHostFile
  960. comprobarError $? 908
  961. sed -i '/ssl_certificate_key /c\\tssl_certificate_key ssl/'"$dominioVirtualHost"'.key;' $virtualHostFile
  962. comprobarError $? 908
  963. fi
  964. fi
  965. # Copiamos ficheros de configuración
  966. cp -f $virtualHostFile "/etc/$webServerName/sites-available/$virtualHostName" >> $logFile 2>&1
  967. comprobarError $? 910
  968. if [ -f "/etc/$webServerName/sites-enabled/$virtualHostName" ];then
  969. rm -f /etc/$webServerName/sites-enabled/$virtualHostName 2>/dev/null
  970. comprobarError 911 $virtualHostName
  971. fi
  972. ln -s "/etc/$webServerName/sites-available/$virtualHostName" "/etc/$webServerName/sites-enabled/$virtualHostName" >> $logFile 2>&1
  973. comprobarError $? 911 $virtualHostName
  974. recargarServicio $webServerName
  975. unset rootVirtualHost dominioVirtualHost virtualHostFile virtualHostName aliasVirtualHost socket
  976. }
  977. mostrarDatabase() {
  978. # Pantalla que permite escoger entre instalar MariaDB o MySQL
  979. if [ $debianOS = true ]; then
  980. 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 \
  981. "MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" ON \
  982. "MySQL" "Instalar la base de datos MySQL (uso no comercial)" OFF \
  983. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  984. comprobarError $? 1
  985. case $database in
  986. MariaDB)
  987. mariaDBOn=true
  988. ;;
  989. MySQL)
  990. mySQLOn=true
  991. ;;
  992. *)
  993. comprobarError 1 200
  994. ;;
  995. esac
  996. unset database
  997. elif [ $rhelOS = true ]; then
  998. 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"
  999. comprobarError $? 1
  1000. mariaDBOn=true
  1001. else
  1002. comprobarError 1 200
  1003. fi
  1004. # Otras opciones (contraseña)
  1005. leerSQLPasswd
  1006. }
  1007. leerSQLPasswd() {
  1008. # Pantalla para leer la contraseña para el usuario root de SQL
  1009. control=false
  1010. error=""
  1011. # Leemos la contreseña (stdin) y confirmamos
  1012. while [ $control = false ]; do
  1013. 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)
  1014. comprobarError $? 1
  1015. 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)
  1016. comprobarError $? 1
  1017. #echo -en "SQL Password 1: $sqlPasswd\n"
  1018. #echo -en "SQL Password 2: $sqlPasswd2\n"
  1019. if [ -z "$sqlPasswd" ] || [ -z "$sqlPasswd2" ]; then
  1020. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  1021. elif [ $sqlPasswd != $sqlPasswd2 ];then
  1022. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  1023. else
  1024. control=true
  1025. fi
  1026. done
  1027. #echo -en "SQL Password: $sqlPasswd\n"
  1028. unset control error sqlPasswd2
  1029. }
  1030. establecerSQLPasswd() {
  1031. # Establecemos SQL root passwd y securizamos BD (mysql_secure_installation)
  1032. # Comprobamos si ya tiene una contraseña asignada
  1033. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  1034. if [ $? -eq 0 ];then
  1035. # Establecemos contraseña del usuario root (y desactivamos posibles plugins para forzar login por contraseña)
  1036. mysql -e "UPDATE mysql.user SET plugin = '', Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1
  1037. if [ $? -ne 0 ];then
  1038. # Lo intentamos de otra forma (para versiones modernas de mysql)
  1039. mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$sqlPasswd'" >> $logFile 2>&1
  1040. comprobarError $? 207
  1041. fi
  1042. # Aplicamos el cambio de contraseña
  1043. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  1044. # Desactivamos acceso root desde el exterior (solo localhost)
  1045. 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
  1046. comprobarError $? 208
  1047. # Eliminamos todos los usuarios anónimos
  1048. mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1
  1049. comprobarError $? 209
  1050. # Eliminamos bases de datos 'test'
  1051. mysql -u root --password=$sqlPasswd -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1
  1052. comprobarError $? 210
  1053. # Eliminamos privilegios de la base de datos 'test'
  1054. mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1
  1055. comprobarError $? 211
  1056. # Aplicamos los cambios
  1057. mysql -u root --password=$sqlPasswd -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  1058. comprobarError $? 212
  1059. else
  1060. comprobarError 1 206
  1061. fi
  1062. }
  1063. instalarMySQL() {
  1064. # Instala MySQL (sólo para Debian)
  1065. sqlServerName="mysql"
  1066. if [ $debianOS = true ];then
  1067. result=$(apt-get -q -y install mysql-server mysql-client 2>&1)
  1068. comprobarError $? 201 $result
  1069. elif [ $rhelOS = true ];then
  1070. # MySQL no disponible en RHEL. 2 opciones:
  1071. # 1) Instalar un repositorio adicional
  1072. # 2) No instalar MySQL en distribuciones RHEL
  1073. comprobarError 1 205
  1074. else
  1075. comprobarError 1 203
  1076. fi
  1077. deshabilitarServicio $sqlServerName
  1078. }
  1079. instalarMariaDB() {
  1080. # Instala MariaDB
  1081. sqlServerName="mariadb"
  1082. if [ $debianOS = true ];then
  1083. result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1)
  1084. comprobarError $? 202 $result
  1085. elif [ $rhelOS = true ];then
  1086. result=$(yum -y install mariadb-server mariadb 2>&1)
  1087. comprobarError $? 202 $result
  1088. else
  1089. comprobarError 1 204
  1090. fi
  1091. deshabilitarServicio $sqlServerName
  1092. }
  1093. configurarSQL() {
  1094. # Configura BarracudaFS en mysql (necesario para Moodle)
  1095. # Configura MariaDB o MySQL
  1096. if [ $mariaDBOn = true ] && [ $debianOS = true ];then
  1097. sqlConfFile="/etc/mysql/my.cnf"
  1098. elif [ $mariaDBOn = true ] && [ $rhelOS = true ];then
  1099. sqlConfFile="/etc/my.cnf"
  1100. elif [ $mySQLOn = true ] && [ $debianOS = true ];then
  1101. sqlConfFile="/etc/mysql/my.cnf"
  1102. else
  1103. comprobarError 1 213
  1104. fi
  1105. if [ ! -f $sqlConfFile ];then
  1106. comprobarError 1 213
  1107. fi
  1108. grep "# Configuration for Moodle" $sqlConfFile >/dev/null 2>&1
  1109. if [ $? -ne 0 ];then
  1110. # Establecemos UTF8 (codificación de caracteres) y Barracuda (sistema de ficheros)
  1111. echo -en "\n# Configuration for Moodle\n" >> $sqlConfFile
  1112. echo -en "[client]\n" >> $sqlConfFile
  1113. echo -en "default-character-set = utf8mb4\n\n" >> $sqlConfFile
  1114. echo -en "[mysqld]\n" >> $sqlConfFile
  1115. echo -en "innodb_file_format = Barracuda\n" >> $sqlConfFile
  1116. echo -en "innodb_file_per_table = 1\n" >> $sqlConfFile
  1117. echo -en "innodb_large_prefix\n\n" >> $sqlConfFile
  1118. echo -en "character-set-server = utf8mb4\n" >> $sqlConfFile
  1119. echo -en "collation-server = utf8mb4_unicode_ci\n" >> $sqlConfFile
  1120. echo -en "skip-character-set-client-handshake\n\n" >> $sqlConfFile
  1121. echo -en "[mysql]\n" >> $sqlConfFile
  1122. echo -en "default-character-set = utf8mb4\n" >> $sqlConfFile
  1123. else
  1124. comprobarError 1 214
  1125. fi
  1126. unset sqlConfFile
  1127. }
  1128. instalarPHP() {
  1129. # Instalamos PHP-7 y los módulos PHP que necesitan MediaWiki y Moodle
  1130. if [ $debianOS = true ];then
  1131. if [ $apacheOn = true ]; then
  1132. result=$(apt-get -q -y install php libapache2-mod-php php-mysql php-intl php-mbstring php-xml php-apcu php-gd php-curl php-zip php-soap php-xmlrpc 2>&1)
  1133. comprobarError $? 302 $result
  1134. elif [ $nginxOn = true ];then
  1135. phpFPMName="php7.2-fpm"
  1136. result=$(apt-get -q -y install php-fpm php-mysql php-intl php-mbstring php-xml php-apcu php-gd php-curl php-zip php-soap php-xmlrpc 2>&1)
  1137. comprobarError $? 302 $result
  1138. deshabilitarServicio $phpFPMName
  1139. else
  1140. comprobarError 1 301
  1141. fi
  1142. elif [ $rhelOS = true ];then
  1143. # Necesitamos un repositorio adicional para PHP-7 (EPEL-RELEASE)
  1144. result=$(yum -y install epel-release yum-utils 2>&1)
  1145. comprobarError $? 103 $result
  1146. # Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE)
  1147. if [ ! -f /etc/yum.repos.d/remi-php72.repo ];then
  1148. if [ $VERSION = "7" ];then
  1149. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-7.rpm 2>&1)
  1150. comprobarError $? 303 $result
  1151. elif [ $VERSION = "6" ];then
  1152. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-6.rpm 2>&1)
  1153. comprobarError $? 303 $result
  1154. elif [ $VERSION = "28" ];then
  1155. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-28.rpm 2>&1)
  1156. comprobarError $? 303 $result
  1157. elif [ $VERSION = "27" ];then
  1158. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-27.rpm 2>&1)
  1159. comprobarError $? 303 $result
  1160. else
  1161. comprobarError 1 304
  1162. fi
  1163. fi
  1164. # Activamos repositorio remi-php72
  1165. result=$(yum-config-manager --enable remi-php72 2>&1)
  1166. comprobarError $? 303 $result
  1167. # Instalamos PHP-7.2
  1168. if [ $apacheOn = true ];then
  1169. result=$(yum -y install php php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd php-pear-Net-Curl php-pecl-zip php-soap php-xmlrpc 2>&1)
  1170. comprobarError $? 302 $result
  1171. elif [ $nginxOn = true ];then
  1172. phpFPMName="php-fpm"
  1173. result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd php-pear-Net-Curl php-pecl-zip php-soap php-xmlrpc 2>&1)
  1174. comprobarError $? 302 $result
  1175. deshabilitarServicio $phpFPMName
  1176. else
  1177. comprobarError 1 301
  1178. fi
  1179. else
  1180. comprobarError 1 300
  1181. fi
  1182. }
  1183. configurarPHP() {
  1184. # Configura PHP para segurizarlo y establecer máximo de subida.
  1185. if [ $debianOS = true ];then
  1186. phpConfFile="./etc/php/php.ini.debian"
  1187. phpDest="/etc/php/7.2/cli/php.ini"
  1188. elif [ $rhelOS = true ];then
  1189. phpConfFile="./etc/php/php.ini.rhel"
  1190. phpDest="/etc/php.ini"
  1191. fi
  1192. if [ ! -f $phpConfFile ];then
  1193. comprobarError 1 4 "$phpConfFile"
  1194. fi
  1195. # Copiamos configuración
  1196. cp -f $phpConfFile $phpDest 2>/dev/null
  1197. comprobarError $? 305
  1198. # Configuramos cgi.fix_pathinfo
  1199. sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=0' $phpDest
  1200. comprobarError $? 305
  1201. # Configuramos post_max_size
  1202. sed -i '/post_max_size =/c\post_max_size = '$maxUpload $phpDest
  1203. comprobarError $? 305
  1204. # Configuramos upload_max_filesize
  1205. sed -i '/upload_max_filesize =/c\upload_max_filesize = '$maxUpload $phpDest
  1206. comprobarError $? 305
  1207. # Configurar php-fpm (sólo en RHEL con Nginx)
  1208. if [ $rhelOS = true ] && [ $nginxOn = true ];then
  1209. # Configurar Socket UNIX
  1210. phpConfFile="./etc/php/php-fpm.d/www.conf"
  1211. phpDest="/etc/php-fpm.d/www.conf"
  1212. if [ ! -f $phpConfFile ];then
  1213. comprobarError $? 4 "$phpConfFile"
  1214. fi
  1215. cp -f $phpConfFile $phpDest 2>/dev/null
  1216. comprobarError $? 305
  1217. # Configurar Permisos /var/lib/php
  1218. chown -R $webServerUser:$webServerGroup /var/lib/php/
  1219. comprobarError $? 305
  1220. fi
  1221. unset phpConfFile phpDest
  1222. }
  1223. establecerMaxUpload() {
  1224. # Pantalla para establecer el máximo de subida al servidor (vía PHP)
  1225. control=false
  1226. error=""
  1227. while [ $control = false ];do
  1228. 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)
  1229. comprobarError $? 1
  1230. if [ -z "$maxUpload2" ];then
  1231. error="ERROR: NO PUEDES DEJAR ESTE PARÁMETRO VACIO.\n"
  1232. else
  1233. control=true
  1234. fi
  1235. done
  1236. maxUpload=$maxUpload2
  1237. unset control maxUpload2
  1238. }
  1239. instalarLetsEncrypt() {
  1240. # Instala certbot (para certificados Let's Encrypt)
  1241. # Comprobamos si cerbot está instalado
  1242. which certbot > /dev/null 2>&1
  1243. if [ $? -ne 0 ];then
  1244. # Descargar Let's Encrypt, hacer ejecutable e instalar
  1245. curl -o ./var/certbot https://dl.eff.org/certbot-auto 2>/dev/null
  1246. comprobarError $? 401
  1247. chmod 755 ./var/certbot 2>/dev/null
  1248. comprobarError $? 401
  1249. cp -f ./var/certbot /usr/bin/certbot 2>/dev/null
  1250. comprobarError $? 401
  1251. # Configurar /etc/cron.d/certbot para renovar automáticamente los certificados
  1252. echo -en "# /etc/cron.d/certbot: certbot autorenew the certificates twice a day\n" > /etc/cron.d/certbot
  1253. echo -en "SHELL=/bin/sh\n" >> /etc/cron.d/certbot
  1254. echo -en "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n\n" >> /etc/cron.d/certbot
  1255. echo -en "# Job start twice per day (4am & 2pm) in a random minute" >> /etc/cron.d/certbot
  1256. echo -en "0 4,14 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew\n" >> /etc/cron.d/certbot
  1257. fi
  1258. }
  1259. generarCertLetsEncrypt() {
  1260. # Generar Certificados SEGUROS Let's Encrypt
  1261. dominios=""
  1262. if [ $apacheOn = true ];then
  1263. # Usamos plugin para apache
  1264. if [ $mediaWikiOn = true ];then
  1265. if [ ! -z "$aliasMediaWiki" ];then
  1266. dominios=$dominioMediaWiki$(echo "$aliasMediaWiki" | sed -e 's/ /,/g')
  1267. else
  1268. dominios=$dominioMediaWiki
  1269. fi
  1270. certbot -n --agree-tos --email "admin@$hostname" --apache --domains "$dominios" >> $logFile 2>&1
  1271. comprobarError $? 404
  1272. fi
  1273. if [ $moodleOn = true ];then
  1274. certbot -n --agree-tos --email "admin@$hostname" --apache --domains "$dominioMoodle" >> $logFile 2>&1
  1275. comprobarError $? 404
  1276. fi
  1277. elif [ $nginxOn = true ];then
  1278. # Usamos plugin para nginx
  1279. if [ $mediaWikiOn = true ];then
  1280. if [ ! -z "$aliasMediaWiki" ];then
  1281. dominios=$dominioMediaWiki$(echo "$aliasMediaWiki" | sed -e 's/ /,/g')
  1282. else
  1283. dominios=$dominioMediaWiki
  1284. fi
  1285. certbot -n --agree-tos --email "admin@$hostname" --nginx --domains "$dominios" >> $logFile 2>&1
  1286. comprobarError $? 404
  1287. fi
  1288. if [ $moodleOn = true ];then
  1289. certbot -n --agree-tos --email "admin@$hostname" --nginx --domains "$dominioMoodle" >> $logFile 2>&1
  1290. comprobarError $? 404
  1291. fi
  1292. else
  1293. comprobarError 1 404
  1294. fi
  1295. unset dominios
  1296. }
  1297. generarCertAutofirmado() {
  1298. # Genera certificados autofirmados
  1299. # Estos certificados no son seguros, pero valen para pruebas o como paso intermedio para obtener los válidos
  1300. # Uso: generarCertAutofirmado $dominio
  1301. dominio=$1
  1302. sslDir="/etc/$webServerName/ssl"
  1303. keyFile="$sslDir/$dominio.key"
  1304. reqFile="$sslDir/$dominio.csr"
  1305. certFile="$sslDir/$dominio.crt"
  1306. dhParamFile="$sslDir/dhparam.pem"
  1307. if [ ! -d "$sslDir" ];then
  1308. mkdir "$sslDir" 2>/dev/null
  1309. comprobarError $? 5 "$sslDir"
  1310. fi
  1311. # Generamos clave privada RSA de 2048 bits
  1312. openssl genrsa -out "$keyFile" 2048 >/dev/null 2>&1
  1313. comprobarError $? 402
  1314. # Generamos petición de firma
  1315. echo -en "ES\nMadrid\nMadrid\n$dominio\n$dominio\n$dominio\nadmin@$dominio\n\n\n" | openssl req -new -key "$keyFile" -out "$reqFile" >/dev/null 2>&1
  1316. comprobarError $? 402
  1317. # Autofirmados clave para 2 años (730 días)
  1318. openssl x509 -req -days 730 -in "$reqFile" -signkey "$keyFile" -out "$certFile" >/dev/null 2>&1
  1319. comprobarError $? 402
  1320. # Eliminamos petición
  1321. rm -f $reqFile
  1322. comprobarError $? 402
  1323. # Añadimos clave Diffie-Hellman al certificado
  1324. if [ -f "$dhParamFile" ];then
  1325. cat "$dhParamFile" >> $certFile
  1326. comprobarError $? 402
  1327. fi
  1328. # Cambiamos permisos
  1329. chmod 644 $certFile
  1330. comprobarError $? 402
  1331. chmod 400 $keyFile
  1332. comprobarError $? 402
  1333. unset dominio sslDir keyFile reqFile certFile dhParamFile
  1334. }
  1335. generarDHParam() {
  1336. # Genera clave de intercambio Diffie-Hellman y lo configuramos
  1337. # Esto aumenta notablemente la seguridad de SSL/TLS
  1338. sslDir="/etc/$webServerName/ssl"
  1339. dhParamFile="$sslDir/dhparam.pem"
  1340. # apacheConfFile=""
  1341. nginxConfFile="/etc/$webServerName/nginx.conf"
  1342. if [ ! -d "$sslDir" ];then
  1343. mkdir "$sslDir" 2>/dev/null
  1344. comprobarError $? 5 "$sslDir"
  1345. fi
  1346. openssl dhparam -out "$dhParamFile" 2048 >/dev/null 2>&1
  1347. comprobarError $? 403
  1348. # Configuramos Servidor Web
  1349. # if [ $apacheOn = true ];then
  1350. # if [ $debianOS = true ];then
  1351. # apacheConfFile="/etc/$webServerName/apache2.conf"
  1352. # elif [ $rhelOS = true ];then
  1353. # # La version de httpd de RHEL no acepta SSLOpenSSLConfCmd
  1354. # # Solución: añadirlo al certificado
  1355. # apacheConfFile="/etc/$webServerName/conf/httpd.conf"
  1356. # else
  1357. # comprobarError 1 403
  1358. # fi
  1359. # echo -en "\n# Set Stronger Diffie-Hellman key exchange\n" >> $apacheConfFile
  1360. # echo -en "SSLOpenSSLConfCmd DHParameters \"$dhParamFile\"\n" >> $apacheConfFile
  1361. # el
  1362. if [ $nginxOn = true ];then
  1363. sed -i '/ssl_param /c\\tssl_dhparam '$dhParamFile';' $nginxConfFile
  1364. comprobarError $? 403
  1365. fi
  1366. # unset sslDir dhParamFile apacheConfFile nginxConfFile
  1367. unset sslDir dhParamFile nginxConfFile
  1368. }
  1369. habilitarServicio() {
  1370. # Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
  1371. # Intentamos con systemctl (SystemD)
  1372. #echo -en "Habilitando Servicio '$1'" | tee -a $logFile
  1373. if [ $# -le 0 ];then
  1374. comprobarError 1 900
  1375. fi
  1376. which systemctl > /dev/null 2>&1
  1377. if [ $? -eq 0 ]; then
  1378. #echo -en " (SystemD)..." | tee -a $logFile
  1379. systemctl start $1 > /dev/null 2>&1
  1380. comprobarError $? 901 $1
  1381. systemctl enable $1 > /dev/null 2>&1
  1382. comprobarError $? 902 $1
  1383. else
  1384. # Intentamos con service (Upstart)
  1385. which service > /dev/null 2>&1
  1386. if [ $? -eq 0 ]; then
  1387. #echo -en " (Upstart)..." | tee -a $logFile
  1388. service $1 start > /dev/null 2>&1
  1389. comprobarError $? 901 $1
  1390. else
  1391. # Intentamos con init.d (SystemV)
  1392. #echo -en " (SystemV)..." | tee -a $logFile
  1393. /etc/init.d/$1 start > /dev/null 2>&1
  1394. comprobarError $? 901 $1
  1395. fi
  1396. # Intentamos habilitar en el arranque (Upstart)
  1397. which update-rc.d > /dev/null 2>&1
  1398. if [ $? -eq 0 ];then
  1399. update-rc.d $1 enable
  1400. comprobarError $? 902 $1
  1401. else
  1402. # Intentamos habilitar en el arranque (SystemV)
  1403. which chkconfig > /dev/null 2>&1
  1404. if [ $? -eq 0 ];then
  1405. chkconfig $1 on
  1406. comprobarError $? 902 $1
  1407. else
  1408. # ¿Qué mas opciones nos quedan?
  1409. comprobarError 1 902 $1
  1410. fi
  1411. fi
  1412. fi
  1413. # Mejora: comprobar si el servicio está parado
  1414. #echo -en " OK.\n" | tee -a $logFile
  1415. }
  1416. deshabilitarServicio() {
  1417. # Paramos y deshabilitamos el servicio (con SystemD, Upstart o SystemV)
  1418. # Intentamos con systemctl (SystemD)
  1419. #echo -en "Deshabilitando Servicio '$1'" | tee -a $logFile
  1420. if [ $# -le 0 ];then
  1421. comprobarError 1 903
  1422. fi
  1423. which systemctl > /dev/null 2>&1
  1424. if [ $? -eq 0 ]; then
  1425. #echo -en " (SystemD)..." | tee -a $logFile
  1426. systemctl stop $1 > /dev/null 2>&1
  1427. comprobarError $? 904 $1
  1428. systemctl disable $1 > /dev/null 2>&1
  1429. comprobarError $? 905 $1
  1430. else
  1431. # Intentamos con service (Upstart)
  1432. which service > /dev/null 2>&1
  1433. if [ $? -eq 0 ]; then
  1434. #echo -en " (Upstart)..." | tee -a $logFile
  1435. service $1 stop > /dev/null 2>&1
  1436. comprobarError $? 904 $1
  1437. else
  1438. # Intentamos con init.d (SystemV)
  1439. #echo -en " (SystemV)..." | tee -a $logFile
  1440. /etc/init.d/$1 stop > /dev/null 2>&1
  1441. comprobarError $? 904 $1
  1442. fi
  1443. # Intentamos habilitar en el arranque (Upstart)
  1444. which update-rc.d > /dev/null 2>&1
  1445. if [ $? -eq 0 ];then
  1446. update-rc.d $1 disable
  1447. comprobarError $? 905 $1
  1448. else
  1449. # Intentamos habilitar en el arranque (SystemV)
  1450. which chkconfig > /dev/null 2>&1
  1451. if [ $? -eq 0 ];then
  1452. chkconfig $1 off
  1453. comprobarError $? 905 $1
  1454. else
  1455. # ¿Qué mas opciones nos quedan?
  1456. comprobarError 1 905 $1
  1457. fi
  1458. fi
  1459. fi
  1460. # Mejora: comprobar si el servicio está funcionando
  1461. #echo -en " OK.\n" | tee -a $logFile
  1462. }
  1463. recargarServicio() {
  1464. # Recargamos el servicio (con SystemD, Upstart o SystemV)
  1465. # Intentamos con systemctl (SystemD)
  1466. #echo -en "Recargando Servicio '$1'" | tee -a $logFile
  1467. if [ $# -le 0 ];then
  1468. comprobarError 1 912
  1469. fi
  1470. which systemctl > /dev/null 2>&1
  1471. if [ $? -eq 0 ]; then
  1472. #echo -en " (SystemD)..." | tee -a $logFile
  1473. systemctl reload $1 > /dev/null 2>&1
  1474. comprobarError $? 913 $1
  1475. else
  1476. # Intentamos con service (Upstart)
  1477. which service > /dev/null 2>&1
  1478. if [ $? -eq 0 ]; then
  1479. #echo -en " (Upstart)..." | tee -a $logFile
  1480. service $1 reload > /dev/null 2>&1
  1481. comprobarError $? 913 $1
  1482. else
  1483. # Intentamos con init.d (SystemV)
  1484. #echo -en " (SystemV)..." | tee -a $logFile
  1485. /etc/init.d/$1 reload > /dev/null 2>&1
  1486. comprobarError $? 913 $1
  1487. fi
  1488. fi
  1489. # Mejora: comprobar si el servicio está funcionando
  1490. #echo -en " OK.\n" | tee -a $logFile
  1491. }
  1492. configurarCortafuegos() {
  1493. # Configuramos cortafuegos (añadir reglas y encender)
  1494. # Comprobamos si estamos usando SSH
  1495. esSSH $PPID
  1496. if [ $debianOS = true ];then
  1497. ufw allow 80/tcp >> $logFile 2>&1
  1498. comprobarError $? 906 "80/tcp"
  1499. if [ $sshControl = true ];then
  1500. ufw allow 22/tcp >> $logFile 2>&1
  1501. comprobarError $? 906 "22/tcp"
  1502. fi
  1503. if [ $sslOn = true ];then
  1504. ufw allow 443/tcp >> $logFile 2>&1
  1505. comprobarError $? 906 "443/tcp"
  1506. fi
  1507. ufw --force enable >> $logFile 2>&1
  1508. comprobarError $? 907
  1509. elif [ $rhelOS = true ];then
  1510. firewall-cmd --add-port=80/tcp >> $logFile 2>&1
  1511. comprobarError $? 906 "80/tcp"
  1512. if [ $sshControl = true ];then
  1513. firewall-cmd --add-port=22/tcp >> $logFile 2>&1
  1514. comprobarError $? 906 "22/tcp"
  1515. fi
  1516. if [ $sslOn = true ];then
  1517. firewall-cmd --add-port=443/tcp >> $logFile 2>&1
  1518. comprobarError $? 906 "443/tcp"
  1519. fi
  1520. firewall-cmd --runtime-to-permanent >> $logFile 2>&1
  1521. comprobarError $? 907
  1522. habilitarServicio firewalld >> $logFile 2>&1
  1523. comprobarError $? 907
  1524. fi
  1525. unset sshControl
  1526. }
  1527. esSSH() {
  1528. # Comprobamos si nuestro terminal usa SSH
  1529. p=${1:-$PPID}
  1530. #read pid name x ppid y < <( cat /proc/$p/stat )
  1531. read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
  1532. [[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
  1533. [ "$ppid" -le 1 ] && { sshControl=false; return 1; }
  1534. esSSH $ppid
  1535. }
  1536. descargarMediaWiki() {
  1537. # Descargar la versión 1.31.0 de MediaWiki
  1538. if [ ! -d ./var ];then
  1539. comprobarError 1 5 "./var"
  1540. fi
  1541. curl "https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz" 2>/dev/null | tar -xz -C "./var/"
  1542. comprobarError $? 501
  1543. }
  1544. configurarMediaWiki() {
  1545. # Configuramos MediaWiki
  1546. if [ ! -f /var/www/$dominioMediaWiki/LocalSettings.php ];then
  1547. # Copiamos archivos
  1548. cp -fR ./var/mediawiki-1.31.0/ /var/www/$dominioMediaWiki
  1549. comprobarError $? 502
  1550. # Configuramos LocalSettings.php (y crea la base de datos por nosotros)
  1551. nombreDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g' | sed -e 's/-/_/g')
  1552. userDBMW=$(echo "mediawiki_user" | sed -e 's/\./_/g' | sed -e 's/-/_/g')
  1553. 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
  1554. comprobarError $? 502
  1555. # Configuraciones adicionales
  1556. sed -i '/$wgLanguageCode =/c\$wgLanguageCode = "es";' /var/www/$dominioMediaWiki/LocalSettings.php
  1557. comprobarError $? 502
  1558. sed -i '/$wgEnableEmail =/c\$wgEnableEmail = false;' /var/www/$dominioMediaWiki/LocalSettings.php
  1559. comprobarError $? 502
  1560. sed -i '/$wgEnableUploads =/c\$wgEnableUploads = true;' /var/www/$dominioMediaWiki/LocalSettings.php
  1561. comprobarError $? 502
  1562. echo -en "\$wgArticlePath = \"/wiki/\$1\";\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1563. echo -en "\$wgUsePathInfo = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1564. echo -en "\$wgGroupPermissions['*']['createaccount'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1565. echo -en "\$wgGroupPermissions['*']['edit'] = false;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1566. echo -en "\$wgGroupPermissions['*']['read'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
  1567. # Actualizamos permisos
  1568. chown -R $webServerUser:$webServerGroup /var/www/$dominioMediaWiki
  1569. comprobarError $? 502
  1570. # Configuramos VirtualHost
  1571. if [ $apacheOn = true ] && [ $sslOn = false ];then
  1572. virtualHost="./etc/apache2/sites-available/mediawiki.conf"
  1573. elif [ $nginxOn = true ] && [ $sslOn = false ];then
  1574. virtualHost="./etc/nginx/sites-available/mediawiki.conf"
  1575. elif [ $apacheOn = true ] && [ $sslOn = true ];then
  1576. virtualHost="./etc/apache2/sites-available/mediawiki-ssl.conf"
  1577. elif [ $nginxOn = true ] && [ $sslOn = true ];then
  1578. virtualHost="./etc/nginx/sites-available/mediawiki-ssl.conf"
  1579. else
  1580. comprobarError 1 502
  1581. fi
  1582. if [ ! -f $virtualHost ];then
  1583. comprobarError $? 502
  1584. fi
  1585. instalarVirtualHost "/var/www/$dominioMediaWiki" $virtualHost $dominioMediaWiki $aliasMediaWiki
  1586. unset virtualHost
  1587. else
  1588. comprobarError 1 503 $dominioMediaWiki
  1589. fi
  1590. }
  1591. descargarMoodle() {
  1592. # Descargar la versión 1.31.0 de MediaWiki
  1593. if [ ! -d ./var ];then
  1594. comprobarError 1 5 "./var"
  1595. fi
  1596. #echo -en "Descargando Moodle-3.5-1..." | tee -a $logFile
  1597. #curl -o "./var/moodle-3.5.1.tgz" "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" >> $logFile 2>&1
  1598. curl "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" 2>/dev/null | tar -xz -C "./var/"
  1599. comprobarError $? 501
  1600. #echo -en " OK.\n" | tee -a $logFile
  1601. }
  1602. configurarMoodle() {
  1603. # Configurar Moodle
  1604. if [ ! -f /var/www/$dominioMoodle/config.php ];then
  1605. # Copiamos archivos
  1606. cp -Rf ./var/moodle/ /var/www/$dominioMoodle
  1607. comprobarError $? 602
  1608. # Crear carperta de datos (no online)
  1609. if [ ! -d /var/www/moodledata ];then
  1610. mkdir /var/www/moodledata 2>/dev/null
  1611. comprobarError $? 602
  1612. fi
  1613. #Actualizamos permisos
  1614. perm=$(stat -c %a /var/www/moodledata)
  1615. if [ $perm -ne 777 ];then
  1616. chmod -R 777 /var/www/moodledata 2>/dev/null
  1617. comprobarError $? 602
  1618. fi
  1619. perm=$(stat -c %U /var/www/moodledata)
  1620. if [ $perm != "$webServerUser" ];then
  1621. chown -R $webServerUser:$webServerGroup /var/www/moodledata 2>/dev/null
  1622. comprobarError $? 602
  1623. fi
  1624. unset perm
  1625. # Creamos Base de Datos
  1626. nombreDBMo=$(echo $dominioMoodle | sed -e 's/\./_/g' | sed -e 's/-/_/g')
  1627. userDBMo=$(echo "moodle_user" | sed -e 's/\./_/g' | sed -e 's/-/_/g')
  1628. crearDBMoodle
  1629. # Configurar SE-Linux (RHEL)
  1630. if [ $rhelOS = true ];then
  1631. configurarSELinux
  1632. fi
  1633. # Configuramos e instalamos Moodle
  1634. if [ $sslOn = true ];then
  1635. wwwroot="https://$dominioMoodle"
  1636. else
  1637. wwwroot="http://$dominioMoodle"
  1638. fi
  1639. if [ $mySQLOn = true ];then
  1640. dbtype="mysqli"
  1641. elif [ $mariaDBOn = true ];then
  1642. dbtype="mariadb"
  1643. else
  1644. comprobarError 1 602
  1645. fi
  1646. php /var/www/$dominioMoodle/admin/cli/install.php --lang=es --wwwroot="$wwwroot" --dataroot="/var/www/moodledata" --dbtype="$dbtype" --dbname="$nombreDBMo" --dbuser="$userDBMo" --dbpass="$sqlPasswd" --fullname="$nombreMoodle" --shortname="$nombreCortoMoodle" --adminuser=admin --adminpass="$passwdMoodle" --adminemail="admin@$dominioMoodle" --agree-license --non-interactive >>$logFile 2>&1
  1647. comprobarError $? 602
  1648. # Actualizamos permisos
  1649. chown -R $webServerUser:$webServerGroup /var/www/$dominioMoodle /var/www/moodledata
  1650. # Configuramos VirtualHost
  1651. if [ $apacheOn = true ] && [ $sslOn = false ];then
  1652. virtualHost="./etc/apache2/sites-available/moodle.conf"
  1653. elif [ $nginxOn = true ] && [ $sslOn = false ];then
  1654. virtualHost="./etc/nginx/sites-available/moodle.conf"
  1655. elif [ $apacheOn = true ] && [ $sslOn = true ];then
  1656. virtualHost="./etc/apache2/sites-available/moodle-ssl.conf"
  1657. elif [ $nginxOn = true ] && [ $sslOn = true ];then
  1658. virtualHost="./etc/nginx/sites-available/moodle-ssl.conf"
  1659. else
  1660. comprobarError 1 602
  1661. fi
  1662. instalarVirtualHost "/var/www/$dominioMoodle" $virtualHost $dominioMoodle
  1663. unset virtualHost wwwroot dbtype
  1664. else
  1665. comprobarError 1 603 $dominioMoodle
  1666. fi
  1667. }
  1668. crearDBMoodle() {
  1669. # Crear base de datos para Moodle
  1670. dbDir="./etc/db"
  1671. if [ ! -d $dbDir ];then
  1672. mkdir $dbDir 2>/dev/null
  1673. comprobarError $? 603
  1674. fi
  1675. dbFile=$dbDir"/moodle.sql"
  1676. echo -en "CREATE DATABASE IF NOT EXISTS $nombreDBMo DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\n" > $dbFile
  1677. echo -en "GRANT ALL PRIVILEGES ON $nombreDBMo.* TO '$userDBMo'@'localhost' IDENTIFIED BY '$sqlPasswd';\n" >> $dbFile
  1678. mysql -u root --password=$sqlPasswd < $dbFile > /dev/null 2>&1
  1679. control=$?
  1680. rm -f $dbFile 2>/dev/null
  1681. comprobarError $? 603
  1682. comprobarError $control 603
  1683. unset control dbFile dbDir
  1684. }
  1685. configurarSELinux() {
  1686. # Configurar SELinux (Sólo para RHEL)
  1687. which semanage >/dev/null 2>&1
  1688. if [ $? -ne 0 ];then
  1689. result=$(yum -y install policycoreutils-python 2>&1)
  1690. comprobarError $? 605 $result
  1691. fi
  1692. semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/moodledata(/.*)?" > /dev/null 2>&1
  1693. comprobarError $? 604
  1694. restorecon -R /var/www/ > /dev/null 2>&1
  1695. comprobarError $? 604
  1696. }
  1697. instalarPHPInfo() {
  1698. # Instalar fichero info.php y su VirtualHost
  1699. if [ ! -f /etc/$webServerName/sites-enabled/phpinfo.conf ];then
  1700. infoFile="./var/www/info.php"
  1701. if [ ! -f $infoFile ];then
  1702. comprobarError 1 4 "$infoFile"
  1703. fi
  1704. mkdir /var/www/localhost 2>/dev/null
  1705. comprobarError $? 106
  1706. cp -f $infoFile /var/www/localhost/ 2>/dev/null
  1707. comprobarError $? 106
  1708. chown -R $webServerUser:$webServerGroup /var/www/localhost 2>/dev/null
  1709. comprobarError $? 106
  1710. unset infoFile
  1711. # Instalar VirtualHost
  1712. if [ $apacheOn = true ] && [ $sslOn = false ];then
  1713. virtualHost="./etc/apache2/sites-available/phpinfo.conf"
  1714. elif [ $nginxOn = true ] && [ $sslOn = false ];then
  1715. virtualHost="./etc/nginx/sites-available/phpinfo.conf"
  1716. elif [ $apacheOn = true ] && [ $sslOn = true ];then
  1717. virtualHost="./etc/apache2/sites-available/phpinfo-ssl.conf"
  1718. elif [ $nginxOn = true ] && [ $sslOn = true ];then
  1719. virtualHost="./etc/nginx/sites-available/phpinfo-ssl.conf"
  1720. else
  1721. comprobarError 1 106
  1722. fi
  1723. instalarVirtualHost "/var/www/localhost" $virtualHost "localhost"
  1724. unset virtualHost
  1725. return 0
  1726. else
  1727. return 1
  1728. fi
  1729. }
  1730. configurarBackups() {
  1731. # Instala backup-server y lo configura
  1732. letsEncryptCode=""
  1733. if [ ! -d "./var" ];then
  1734. comprobarError 1 5 "./var"
  1735. fi
  1736. which backup-server > /dev/null 2>&1
  1737. if [ $? -ne 0 ];then
  1738. # Descargamos backup-server
  1739. curl "https://code.castanedo.es/guzman/backup-server/archive/2.1.tar.gz" 2>/dev/null | tar -xz -C "./var/"
  1740. if [ $? -ne 0 ];then
  1741. comprobarError 1 701
  1742. return 1
  1743. fi
  1744. # Copiamos backup-server y logrotate
  1745. cp -f ./var/backup-server/backup-server /usr/bin/backup-server
  1746. if [ $? -ne 0 ];then
  1747. comprobarError 1 701
  1748. return 1
  1749. fi
  1750. cp -f ./var/backup-server/scripts/logrotate.d/backup-server /etc/logrotate.d/backup-server
  1751. if [ $? -ne 0 ];then
  1752. comprobarError 1 701
  1753. return 1
  1754. fi
  1755. # Creamos carpeta de backups
  1756. if [ ! -d /var/backup ];then
  1757. mkdir /var/backup 2>/dev/null
  1758. comprobarError $? 5 "/var/backup"
  1759. fi
  1760. # Configuramos cron.d
  1761. if [ $letsEncryptOn = false ];then
  1762. letsEncryptCode="--no-letsencrypt "
  1763. fi
  1764. echo -en "# /etc/cron.d/backup-server: crontab for $hostname\n\n" > /etc/cron.d/backup-server
  1765. echo -en "# Backup every day at 4:00 am\n" >> /etc/cron.d/backup-server
  1766. echo -en "0 4 * * * root [ -x /usr/bin/backup-server ] && /usr/bin/backup-server --xz -u $webServerUser -g $webServerGroup --no-encryption --sql-user root --sql-pass $sqlPasswd --nginx-dir /etc/$webServerName $letsEncryptCode--no-mail --no-gogs --no-postfix --no-dovecot --no-opendkim --no-spf --no-opendmarc --no-amavis --no-spamassassin /var/backup >> /var/log/backup-server.log 2>&1" >> /etc/cron.d/backup-server
  1767. comprobarError $? 701
  1768. fi
  1769. unset letsEncryptCode
  1770. }
  1771. # Comprobación del sistema e inicialización
  1772. horaInicial=$(date +"%s")
  1773. inicializarVariables
  1774. comprobarRoot
  1775. OSInfo
  1776. comprobarDependencias
  1777. # Bienvenida
  1778. mostrarBienvenida
  1779. # Selección de componentes (express vs avanzada)
  1780. mostrarExpress
  1781. # Instalación Servidor Web
  1782. if [ $apacheOn = true ]; then
  1783. echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
  1784. instalarApache
  1785. echo -en " OK.\n" | tee -a $logFile
  1786. elif [ $nginxOn = true ]; then
  1787. echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
  1788. instalarNginx
  1789. echo -en " OK.\n" | tee -a $logFile
  1790. fi
  1791. # Instalación Base de Datos
  1792. if [ $mySQLOn = true ]; then
  1793. echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
  1794. instalarMySQL
  1795. echo -en " OK.\n" | tee -a $logFile
  1796. elif [ $mariaDBOn = true ]; then
  1797. echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
  1798. instalarMariaDB
  1799. echo -en " OK.\n" | tee -a $logFile
  1800. fi
  1801. # Instalación PHP-7.2
  1802. if [ $phpOn = true ]; then
  1803. echo -en "Instalando PHP-7..." | tee -a $logFile
  1804. instalarPHP
  1805. echo -en " OK.\n" | tee -a $logFile
  1806. fi
  1807. # Instalación Let's Encrypt
  1808. if [ $letsEncryptOn = true ];then
  1809. echo -en "Instalando Let's Encrypt..." | tee -a $logfile
  1810. instalarLetsEncrypt
  1811. echo -en " OK.\n" | tee -a $logFile
  1812. fi
  1813. # Configuración Web Server
  1814. if [ $apacheOn = true ];then
  1815. echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
  1816. configurarApache
  1817. echo -en " OK.\n" | tee -a $logFile
  1818. elif [ $nginxOn = true ]; then
  1819. echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
  1820. configurarNginx
  1821. echo -en " OK.\n" | tee -a $logFile
  1822. fi
  1823. # Configuración Database (Configurar Ficheros, Arrancar Base de Datos, establecer contraseña y configuración segura)
  1824. if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
  1825. echo -en "Configurando Base de Datos..." | tee -a $logFile
  1826. configurarSQL
  1827. echo -en " OK.\n" | tee -a $logFile
  1828. habilitarServicio "$sqlServerName"
  1829. echo -en "Estableciendo contraseña de la Base de Datos..." | tee -a $logFile
  1830. establecerSQLPasswd
  1831. echo -en " OK.\n" | tee -a $logFile
  1832. fi
  1833. # Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
  1834. if [ $phpOn = true ];then
  1835. echo -en "Configurando PHP-7..." | tee -a $logFile
  1836. configurarPHP
  1837. echo -en " OK.\n" | tee -a $logFile
  1838. fi
  1839. # Configuración SSL/TLS
  1840. # Generar certificados auto-firmados
  1841. if [ $sslOn = true ];then
  1842. echo -en "Generando claves de intercambio Diffie-Hellman (puede llevar un largo tiempo)..." | tee -a $logFile
  1843. generarDHParam
  1844. echo -en " OK.\n" | tee -a $logFile
  1845. echo -en "Generando Certificados Auto-Firmados..." | tee -a $logFile
  1846. if [ $mediaWikiOn = true ];then
  1847. generarCertAutofirmado $dominioMediaWiki
  1848. fi
  1849. if [ $moodleOn = true ];then
  1850. generarCertAutofirmado $dominioMoodle
  1851. fi
  1852. if [ $infoPHPOn = true ];then
  1853. generarCertAutofirmado "localhost"
  1854. fi
  1855. echo -en " OK.\n" | tee -a $logFile
  1856. fi
  1857. # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
  1858. echo -en "Habilitando todos los servicios..." | tee -a $logFile
  1859. if [ $apacheOn = true ] || [ $nginxOn = true ];then
  1860. habilitarServicio $webServerName
  1861. fi
  1862. if [ $nginxOn = true ] && [ $phpOn = true ];then
  1863. habilitarServicio $phpFPMName
  1864. fi
  1865. echo -en " OK.\n" | tee -a $logFile
  1866. # Instalar MediaWiki
  1867. if [ $mediaWikiOn = true ]; then
  1868. # Descargar MediaWiki
  1869. echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
  1870. descargarMediaWiki
  1871. echo -en " OK.\n" | tee -a $logFile
  1872. # Configurar MediWiki
  1873. echo -en "Configurando MediaWiki..." | tee -a $logFile
  1874. configurarMediaWiki
  1875. echo -en " OK.\n" | tee -a $logFile
  1876. fi
  1877. # Instalar Moodle
  1878. if [ $moodleOn = true ]; then
  1879. # Descargar Moodle
  1880. echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
  1881. descargarMoodle
  1882. echo -en " OK.\n" | tee -a $logFile
  1883. # Configuración Moodle
  1884. echo -en "Configurando Moodle (puede llevar un tiempo largo)..." | tee -a $logFile
  1885. configurarMoodle
  1886. echo -en " OK.\n" | tee -a $logFile
  1887. fi
  1888. # Instalar info.php
  1889. if [ $infoPHPOn = true ];then
  1890. echo -en "Configurando 'info.php'..." | tee -a $logFile
  1891. instalarPHPInfo
  1892. if [ $? -eq 0 ];then
  1893. echo -en " OK.\n" | tee -a $logFile
  1894. else
  1895. echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
  1896. fi
  1897. fi
  1898. # Añadir reglas del cortafuegos
  1899. echo -en "Configurando Cortafuegos..." | tee -a $logFile
  1900. configurarCortafuegos
  1901. echo -en " OK.\n" | tee -a $logFile
  1902. # Generar certificados Let's Encrypt
  1903. if [ $letsEncryptOn = true ];then
  1904. echo -en "Generando Certificados Válidos Let's Encrypt..." | tee -a $logFile
  1905. generarCertLetsEncrypt
  1906. echo -en " OK.\n" | tee -a $logFile
  1907. fi
  1908. # Configurar Backup
  1909. if [ $backupOn = true ]; then
  1910. echo -en "Configurando Backup Automático..." | tee -a $logFile
  1911. configurarBackups
  1912. echo -en " OK.\n" | tee -a $logFile
  1913. fi
  1914. # Finalizamos
  1915. horaFinal=$(date +"%s")
  1916. echo -en "\n--------------------------------------------------\n" | tee -a $logFile
  1917. echo -en "\t¡INSTALACION FINALIZADA CON EXITO! \n" | tee -a $logFile
  1918. echo -en "\tDuración: "$((horaFinal-horaInicial))" seg." | tee -a $logFile
  1919. echo -en "\n--------------------------------------------------\n" | tee -a $logFile