install 39 KB

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