install 64 KB

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