install 55 KB

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