install 35 KB

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