install 42 KB

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