install 48 KB

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