install 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  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. configurarMediaWiki() {
  1119. # Configuramos MediaWiki
  1120. # Copiamos archivos y permisos
  1121. cp -R ./var/mediawiki-1.31.0/ /var/www/wiki
  1122. comprobarError $? 502
  1123. chown -R $webServerUser:$webServerGroup /var/www/wiki
  1124. comprobarError $? 502
  1125. # Creamos DataBase
  1126. # Configuramos VirtualHost
  1127. }
  1128. descargarMoodle() {
  1129. # Descargar la versión 1.31.0 de MediaWiki
  1130. if [ ! -d ./var ];then
  1131. comprobarError 1 5 "./var"
  1132. fi
  1133. #echo -en "Descargando Moodle-3.5-1..." | tee -a $logFile
  1134. #curl -o "./var/moodle-3.5.1.tgz" "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" >> $logFile 2>&1
  1135. curl "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" 2>$logFile | tar -xz -C "./var/"
  1136. comprobarError $? 501
  1137. #echo -en " OK.\n" | tee -a $logFile
  1138. }
  1139. # Comprobación del sistema e inicialización
  1140. inicializarVariables
  1141. comprobarRoot
  1142. OSInfo
  1143. comprobarDependencias
  1144. # Bienvenida
  1145. mostrarBienvenida
  1146. # Selección de componentes (express vs avanzada)
  1147. mostrarExpress
  1148. # Instalación Servidor Web
  1149. if [ $apacheOn = true ]; then
  1150. echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
  1151. # {
  1152. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1153. instalarApache
  1154. progreso=$((progreso + 1))
  1155. # } > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1156. echo -en " OK.\n" | tee -a $logFile
  1157. elif [ $nginxOn = true ]; then
  1158. echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
  1159. # {
  1160. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1161. instalarNginx
  1162. progreso=$((progreso + 1))
  1163. # } > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1164. echo -en " OK.\n" | tee -a $logFile
  1165. fi
  1166. # Instalación Base de Datos
  1167. if [ $mySQLOn = true ]; then
  1168. echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
  1169. # {
  1170. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1171. instalarMySQL
  1172. progreso=$((progreso + 1))
  1173. # } > >(whiptail --gauge "Instalando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1174. echo -en " OK.\n" | tee -a $logFile
  1175. elif [ $mariaDBOn = true ]; then
  1176. echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
  1177. # {
  1178. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1179. instalarMariaDB
  1180. progreso=$((progreso + 1))
  1181. # } > >(whiptail --gauge "Instalando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1182. echo -en " OK.\n" | tee -a $logFile
  1183. fi
  1184. # Instalación PHP-7.2
  1185. if [ $phpOn = true ]; then
  1186. echo -en "Instalando PHP-7..." | tee -a $logFile
  1187. # {
  1188. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1189. instalarPHP
  1190. progreso=$((progreso + 1))
  1191. # } > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1192. echo -en " OK.\n" | tee -a $logFile
  1193. fi
  1194. # Instalación SSL/TLS
  1195. if [ $sslOn = true ];then
  1196. echo -en "Instalando SSL/TLS..." | tee -a $logfile
  1197. # {
  1198. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1199. sleep 2
  1200. progreso=$((progreso + 1))
  1201. # } > >(whiptail --gauge "Instalando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1202. echo -en " OK.\n" | tee -a $logFile
  1203. fi
  1204. # Configuración Web Server
  1205. if [ $apacheOn = true ];then
  1206. echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
  1207. # {
  1208. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1209. configurarApache
  1210. progreso=$((progreso + 1))
  1211. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1212. echo -en " OK.\n" | tee -a $logFile
  1213. elif [ $nginxOn = true ]; then
  1214. echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
  1215. # {
  1216. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1217. configurarNginx
  1218. progreso=$((progreso + 1))
  1219. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1220. echo -en " OK.\n" | tee -a $logFile
  1221. fi
  1222. # Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
  1223. if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
  1224. habilitarServicio "$sqlServerName"
  1225. echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile
  1226. # {
  1227. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1228. establecerSQLPasswd
  1229. progreso=$((progreso + 1))
  1230. # } > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1231. echo -en " OK.\n" | tee -a $logFile
  1232. fi
  1233. # Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
  1234. if [ $phpOn = true ];then
  1235. echo -en "Configurando PHP-7..." | tee -a $logFile
  1236. # {
  1237. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1238. configurarPHP
  1239. progreso=$((progreso + 1))
  1240. # } > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1241. echo -en " OK.\n" | tee -a $logFile
  1242. fi
  1243. # Configuración SSL/TLS
  1244. # Generar certificados
  1245. # Configurar certificados
  1246. if [ $sslOn = true ];then
  1247. echo -en "Configurando SSL/TLS..." | tee -a $logFile
  1248. # {
  1249. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1250. sleep 2
  1251. progreso=$((progreso + 1))
  1252. # } > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1253. echo -en " OK.\n" | tee -a $logFile
  1254. fi
  1255. # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
  1256. # {
  1257. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1258. if [ $apacheOn = true ];then
  1259. habilitarServicio $webServerName
  1260. elif [ $nginxOn = true ];then
  1261. habilitarServicio $webServerName
  1262. if [ $phpOn = true ];then
  1263. habilitarServicio $phpFPMName
  1264. fi
  1265. fi
  1266. progreso=$((progreso + 1))
  1267. # } > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1268. # MediaWiki
  1269. if [ $mediaWikiOn = true ]; then
  1270. # Descargar MediaWiki
  1271. echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
  1272. # {
  1273. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1274. descargarMediaWiki
  1275. progreso=$((progreso + 1))
  1276. # } > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1277. echo -en " OK.\n" | tee -a $logFile
  1278. # Configurar MediWiki
  1279. echo -en "Configurando MediaWiki..." | tee -a $logFile
  1280. # {
  1281. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1282. sleep 2
  1283. progreso=$((progreso + 1))
  1284. # } > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1285. echo -en " OK.\n" | tee -a $logFile
  1286. fi
  1287. # Moodle
  1288. if [ $moodleOn = true ]; then
  1289. # Descargar Moodle
  1290. echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
  1291. # {
  1292. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1293. descargarMoodle
  1294. progreso=$((progreso + 1))
  1295. # } > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1296. echo -en " OK.\n" | tee -a $logFile
  1297. # Configuración Moodle
  1298. echo -en "Configurando Moodle..." | tee -a $logFile
  1299. # {
  1300. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1301. sleep 2
  1302. progreso=$((progreso + 1))
  1303. # } > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1304. echo -en " OK.\n" | tee -a $logFile
  1305. fi
  1306. # Configurar Virtual Hosts
  1307. # Instalar info.php
  1308. if [ $infoPHPOn = true ];then
  1309. echo -en "Configurando 'info.php'..." | tee -a $logFile
  1310. instalarPHPInfo
  1311. if [ $? -eq 0 ];then
  1312. echo -en " OK.\n" | tee -a $logFile
  1313. else
  1314. echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
  1315. fi
  1316. fi
  1317. # Añadir reglas del cortafuegos
  1318. echo -en "Configurando Cortafuegos..." | tee -a $logFile
  1319. # {
  1320. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1321. configurarCortafuegos
  1322. progreso=$((progreso + 1))
  1323. # } > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1324. echo -en " OK.\n" | tee -a $logFile
  1325. # Configurar actualizaciones
  1326. if [ $actualizacionesOn = true ]; then
  1327. echo -en "Configurando Actualizaciones Automáticas..." | tee -a $logFile
  1328. # {
  1329. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1330. sleep 2
  1331. progreso=$((progreso + 1))
  1332. # } > >(whiptail --gauge "Configurando actualizaciones automáticas..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1333. echo -en " OK.\n" | tee -a $logFile
  1334. fi