install 56 KB

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