install 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  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. autoFirmadoOn=false
  441. mediaWikiOn=false
  442. moodleOn=false
  443. infoPHPOn=false
  444. actualizacionesOn=false
  445. progreso=0
  446. progresoTotal=0
  447. logFile="./."$(basename $0)".log"
  448. maxUpload="100M"
  449. webServerName=""
  450. webServerUser=""
  451. webServerGroup=""
  452. sqlServerName=""
  453. phpFPMName=""
  454. }
  455. instalacionExpress() {
  456. apacheOn=true
  457. mariaDBOn=true
  458. phpOn=true
  459. sslOn=true
  460. letsEncryptOn=true
  461. mediaWikiOn=true
  462. moodleOn=true
  463. actualizacionesOn=true
  464. progresoTotal=15
  465. # Preguntas mínimas
  466. establecerFQDN
  467. leerSQLPasswd
  468. }
  469. mostrarBienvenida() {
  470. ANCHO=$(tput cols)
  471. ALTO=$(tput lines)
  472. if [ $debianOS = false ] && [ $rhelOS = false ]; then
  473. 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"
  474. exit 1
  475. fi
  476. 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"
  477. comprobarError $? 1
  478. }
  479. mostrarExpress() {
  480. 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 \
  481. "Express" "Instalación rápida" ON \
  482. "Avanzada" "Permite escoger todas las opciones disponibles" OFF \
  483. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  484. comprobarError $? 1
  485. case $express in
  486. Express)
  487. instalacionExpress
  488. # DECIDIR QUÉ OPCIONES SON LAS MÍNIMAS
  489. ;;
  490. Avanzada)
  491. mostrarAvanzada
  492. ;;
  493. *)
  494. comprobarError 1 2
  495. ;;
  496. esac
  497. }
  498. mostrarAvanzada() {
  499. 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 \
  500. "LAMP" "GNU/Linux + Apache + MySQL/MariaDB + PHP-7" ON \
  501. "LEMP" "GNU/Linux + Nginx + MySQL/MariaDB + PHP-7" OFF \
  502. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  503. comprobarError $? 1
  504. for i in $webServer; do
  505. case $i in
  506. LAMP)
  507. apacheOn=true
  508. ;;
  509. LEMP)
  510. nginxOn=true
  511. ;;
  512. *)
  513. comprobarError 1 100
  514. ;;
  515. esac
  516. done
  517. # Opciones comunes
  518. establecerFQDN
  519. mostrarDatabase
  520. phpOn=true
  521. establecerMaxUpload
  522. progresoTotal=$((progresoTotal + 6))
  523. mostrarComponentes
  524. }
  525. mostrarComponentes() {
  526. 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 \
  527. "SSL/TLS" "Instalar certificados para activar HTTPS" ON \
  528. "MediaWiki" "Instalar wiki con MediaWiki" ON \
  529. "Moodle" "Instalar campus virtual con Moodle" ON \
  530. "InfoPHP" "Instalar info.php (sólo para pruebas)" OFF \
  531. "Actualizaciones" "Programar actualizaciones automáticas" ON \
  532. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  533. comprobarError $? 1
  534. # Mejora: autodetección de componentes ya instalados
  535. for i in $componentes; do
  536. case $i in
  537. \"SSL/TLS\")
  538. sslOn=true
  539. # 2 Opciones: Let's Encrypt o Autofirmado
  540. mostrarSSL
  541. progresoTotal=$((progresoTotal + 2))
  542. ;;
  543. \"MediaWiki\")
  544. mediaWikiOn=true
  545. progresoTotal=$((progresoTotal + 2))
  546. ;;
  547. \"Moodle\")
  548. moodleOn=true
  549. progresoTotal=$((progresoTotal + 2))
  550. ;;
  551. \"InfoPHP\")
  552. infoPHPOn=true
  553. progresoTotal=$((progresoTotal + 2))
  554. ;;
  555. \"Actualizaciones\")
  556. actualizacionesOn=true
  557. progresoTotal=$((progresoTotal + 1))
  558. ;;
  559. *)
  560. comprobarError 1 3
  561. ;;
  562. esac
  563. done
  564. progresoTotal=$((progresoTotal + 2))
  565. }
  566. mostrarSSL() {
  567. ssl=$(whiptail --tile "INSTALACION SSL/TLS" --radiolist "<ESPACIO>: seleccionar <TAB>: cambiar <FLECHAS>: moverse\n\nEscoge el tipo de Certificado SSL/TLS que quieres instalar:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \
  568. "LetsEncrypt" "Instala certificados 100% compatibles con todos los navegadores" ON \
  569. "Auto-Firmado" "Instala certificados auto-firmados (sólo para pruebas)" OFF \
  570. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  571. comprobarError $? 1
  572. for i in $ssl; do
  573. case $i in
  574. LetsEncrypt)
  575. letsEcnryptOn=true
  576. ;;
  577. Auto-Firmados)
  578. autoFirmadoOn=true
  579. ;;
  580. *)
  581. comprobarError 1 6
  582. ;;
  583. esac
  584. done
  585. }
  586. establecerFQDN() {
  587. while [ -z $hostname ]; do
  588. 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)
  589. if [ $? -eq 0 ] && [ ! -z $hostname ]; then
  590. hostnamectl set-hostname $hostname
  591. else
  592. hostname=$(hostname)
  593. fi
  594. done
  595. echo -en "Hostname: $hostname\n" >> $logFile
  596. }
  597. instalarApache() {
  598. if [ $debianOS = true ];then
  599. webServerName="apache2"
  600. result=$(apt-get -q -y install apache2 2>&1)
  601. comprobarError $? 101 $result
  602. elif [ $rhelOS = true ]; then
  603. webServerName="httpd"
  604. result=$(yum -y install httpd 2>&1)
  605. comprobarError $? 101 $result
  606. else
  607. comprobarError 1 104
  608. fi
  609. deshabilitarServicio $webServerName
  610. }
  611. configurarApache() {
  612. if [ $debianOS = true ];then
  613. apacheConfFile="./etc/$webServerName-debian/apache2.conf"
  614. if [ ! -f $apacheConfFile ];then
  615. comprobarError 1 4 $apacheConfFile
  616. fi
  617. cp -f $apacheConfFile /etc/$webServerName/apache2.conf 2>/dev/null
  618. comprobarError $? 108
  619. webServerUser=$(grep ^User /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
  620. webServerGroup=$(grep ^Group /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
  621. elif [ $rhelOS = true ];then
  622. apacheConfFile="./etc/$webServerName-rhel/conf/httpd.conf"
  623. welcomeConfFile="/etc/$webServerName/conf.d/welcome.conf"
  624. if [ ! -f $apacheConfFile ];then
  625. comprobarError 1 4 $apacheConfFile
  626. fi
  627. cp -f $apacheConfFile /etc/$webServerName/conf/ 2>/dev/null
  628. comprobarError $? 108
  629. if [ -f $welcomeConfFile ];then
  630. sed -i -e 's/^/#/' $welcomeConfFile
  631. comprobarError $? 108
  632. fi
  633. webServerUser=$(grep ^User /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
  634. webServerGroup=$(grep ^Group /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
  635. unset apacheConfFile welcomeConfFile
  636. fi
  637. if [ ! -d "/etc/$webServerName/sites-available" ];then
  638. mkdir "/etc/$webServerName/sites-available" 2>/dev/null
  639. comprobarError $? 5 "/etc/$webServerName/sites-available"
  640. fi
  641. if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
  642. mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
  643. comprobarError $? 5 "$webServerRoot/sites-enabled"
  644. fi
  645. }
  646. instalarNginx() {
  647. webServerName="nginx"
  648. if [ $debianOS = true ];then
  649. result=$(apt-get -q -y install nginx 2>&1)
  650. comprobarError $? 102 $result
  651. elif [ $rhelOS = true ]; then
  652. # Hay que instalar primero otro repositorio
  653. result=$(yum -y install epel-release)
  654. comprobarError $? 103 $result
  655. result=$(yum -y install nginx 2>&1)
  656. comprobarError $? 102 $result
  657. else
  658. comprobarError 1 105
  659. fi
  660. deshabilitarServicio $webServerName
  661. }
  662. configurarNginx() {
  663. # Configuramos Nginx
  664. rm -Rf /etc/$webServerName/* 2>/dev/null
  665. comprobarError $? 107
  666. if [ $debianOS = true ];then
  667. nginxConfFile="./etc/$webServerName-debian"
  668. elif [ $rhelOS = true ];then
  669. nginxConfFile="./etc/$webServerName-rhel"
  670. fi
  671. if [ -d "$nginxConfFile" ];then
  672. cp -Rf $nginxConfFile/* /etc/$webServerName/ 2>/dev/null
  673. comprobarError $? 107
  674. else
  675. comprobarError 1 5 "$nginxConfFile"
  676. fi
  677. if [ ! -d "/etc/$webServerName/sites-available" ];then
  678. mkdir "/etc/$webServerName/sites-available" 2>/dev/null
  679. comprobarError $? 5 "/etc/$webServerName/sites-available"
  680. fi
  681. if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
  682. mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
  683. comprobarError $? 5 "$webServerRoot/sites-enabled"
  684. fi
  685. webServerUser=$(grep ^user /etc/$webServerName/nginx.conf | cut -d ' ' -f 2 | cut -d ';' -f 1)
  686. webServerGroup=$webServerUser
  687. unset nginxConfFile
  688. }
  689. instalarVirtualHost() {
  690. # Configuramos un Virtual Host para Apache o Nginx
  691. # Uso: instalarVirtualHost $virtualHost
  692. if [ $# -ne 1 ];then
  693. comprobarError 1 908
  694. fi
  695. webServerRoot=$(realpath "/etc/$webServerName/")
  696. virtualHost=$(realpath $1)
  697. virtualHostName=$(basename $virtualHost)
  698. if [ ! -f $virtualHost ];then
  699. comprobarError 1 909 $virtualHostName
  700. fi
  701. cp -f $virtualHost "$webServerRoot/sites-available/$virtualHostName" >> $logFile 2>&1
  702. comprobarError $? 910
  703. ln -s "$webServerRoot/sites-available/$virtualHostName" "$webServerRoot/sites-enabled/$virtualHostName" >> $logFile 2>&1
  704. comprobarError $? 911 $virtualHostName
  705. recargarServicio $webServerName
  706. unset webServerRoot virtualHost virtualHostName
  707. }
  708. mostrarDatabase() {
  709. if [ $debianOS = true ]; then
  710. 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 \
  711. "MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" ON \
  712. "MySQL" "Instalar la base de datos MySQL (uso no comercial)" OFF \
  713. --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
  714. comprobarError $? 1
  715. case $database in
  716. MariaDB)
  717. mariaDBOn=true
  718. ;;
  719. MySQL)
  720. mySQLOn=true
  721. ;;
  722. *)
  723. comprobarError 1 200
  724. ;;
  725. esac
  726. elif [ $rhelOS = true ]; then
  727. 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"
  728. comprobarError $? 1
  729. mariaDBOn=true
  730. else
  731. comprobarError 1 200
  732. fi
  733. # Otras opciones (contraseña)
  734. leerSQLPasswd
  735. }
  736. leerSQLPasswd() {
  737. control=false
  738. error=""
  739. # Leemos la contreseña (stdin) y confirmamos
  740. while [ $control = false ]; do
  741. 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)
  742. comprobarError $? 1
  743. 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)
  744. comprobarError $? 1
  745. #echo -en "SQL Password 1: $sqlPasswd\n"
  746. #echo -en "SQL Password 2: $sqlPasswd2\n"
  747. if [ -z $sqlPasswd ] || [ -z $sqlPasswd2 ]; then
  748. error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
  749. elif [ $sqlPasswd != $sqlPasswd2 ];then
  750. error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
  751. else
  752. control=true
  753. fi
  754. done
  755. #echo -en "SQL Password: $sqlPasswd\n"
  756. unset control error sqlPasswd2
  757. }
  758. establecerSQLPasswd() {
  759. # Establecemos SQL root passwd y securizamos BD (mysql_secure_installation)
  760. # Comprobamos si ya tiene una contraseña asignada
  761. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  762. if [ $? -eq 0 ];then
  763. # Establecemos contraseña del usuario root (y desactivamos posibles plugins para forzar login por contraseña)
  764. mysql -e "UPDATE mysql.user SET plugin = '', Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1
  765. comprobarError $? 207
  766. # Desactivamos acceso root desde el exterior (solo localhost)
  767. mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" >> $logFile 2>&1
  768. comprobarError $? 208
  769. # Eliminamos todos los usuarios anónimos
  770. mysql -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1
  771. comprobarError $? 209
  772. # Eliminamos bases de datos 'test'
  773. mysql -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1
  774. comprobarError $? 210
  775. # Eliminamos privilegios de la base de datos 'test'
  776. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1
  777. comprobarError $? 211
  778. # Aplicamos los cambios
  779. mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
  780. comprobarError $? 212
  781. else
  782. comprobarError 1 206
  783. fi
  784. }
  785. instalarMySQL() {
  786. sqlServerName="mysql"
  787. if [ $debianOS = true ];then
  788. result=$(apt-get -q -y install mysql-server mysql-client 2>&1)
  789. comprobarError $? 201 $result
  790. elif [ $rhelOS = true ];then
  791. # MySQL no disponible en RHEL. 2 opciones:
  792. # 1) Instalar un repositorio adicional
  793. # 2) No instalar MySQL en distribuciones RHEL
  794. comprobarError 1 205
  795. else
  796. comprobarError 1 203
  797. fi
  798. }
  799. instalarMariaDB() {
  800. sqlServerName="mariadb"
  801. if [ $debianOS = true ];then
  802. result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1)
  803. comprobarError $? 202 $result
  804. elif [ $rhelOS = true ];then
  805. result=$(yum -y install mariadb-server mariadb 2>&1)
  806. comprobarError $? 202 $result
  807. else
  808. comprobarError 1 204
  809. fi
  810. }
  811. instalarPHP() {
  812. # Instalamos PHP-7 de forma diferente si es junto a Apache o con Nginx
  813. if [ $debianOS = true ];then
  814. if [ $apacheOn = true ]; then
  815. result=$(apt-get -q -y install php libapache2-mod-php php-mysql php-intl php-mbstring openssl 2>&1)
  816. comprobarError $? 302 $result
  817. elif [ $nginxOn = true ];then
  818. phpFPMName="php7.2-fpm"
  819. result=$(apt-get -q -y install php-fpm php-mysql php-intl php-mbstring openssl 2>&1)
  820. comprobarError $? 302 $result
  821. deshabilitarServicio $phpFPMName
  822. else
  823. comprobarError 1 301
  824. fi
  825. elif [ $rhelOS = true ];then
  826. # Necesitamos un repositorio adicional para PHP-7 (EPEL-RELEASE)
  827. result=$(yum -y install epel-release yum-utils 2>&1)
  828. comprobarError $? 103 $result
  829. # Necesitamos un repositorio adicional para PHP-7 (REMI-RELEASE)
  830. if [ ! -f /etc/yum.repos.d/remi-php72.repo ];then
  831. if [ $VERSION = "7" ];then
  832. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-7.rpm 2>&1)
  833. comprobarError $? 303 $result
  834. elif [ $VERSION = "6" ];then
  835. result=$(yum -y install http://remi.mirrors.cu.be/enterprise/remi-release-6.rpm 2>&1)
  836. comprobarError $? 303 $result
  837. elif [ $VERSION = "28" ];then
  838. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-28.rpm 2>&1)
  839. comprobarError $? 303 $result
  840. elif [ $VERSION = "27" ];then
  841. result=$(yum -y install http://remi.mirrors.cu.be/fedora/remi-release-27.rpm 2>&1)
  842. comprobarError $? 303 $result
  843. else
  844. comprobarError 1 304
  845. fi
  846. fi
  847. # Activamos repositorio remi-php72
  848. result=$(yum-config-manager --enable remi-php72 2>&1)
  849. comprobarError $? 303 $result
  850. # Instalamos PHP-7.2
  851. if [ $apacheOn = true ];then
  852. result=$(yum -y install php php-mysql php-intl php-mbstring php-mcrypt openssl 2>&1)
  853. comprobarError $? 302 $result
  854. elif [ $nginxOn = true ];then
  855. phpFPMName="php-fpm"
  856. result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt openssl 2>&1)
  857. comprobarError $? 302 $result
  858. deshabilitarServicio $phpFPMName
  859. else
  860. comprobarError 1 301
  861. fi
  862. else
  863. comprobarError 1 300
  864. fi
  865. }
  866. configurarPHP() {
  867. # Configura PHP para segurizarlo y establecer máximo de subida.
  868. if [ $debianOS = true ];then
  869. phpConfFile="./etc/php/php.ini.debian"
  870. phpDest="/etc/php/7.2/cli/php.ini"
  871. elif [ $rhelOS = true ];then
  872. phpConfFile="./etc/php/php.ini.rhel"
  873. phpDest="/etc/php.ini"
  874. fi
  875. if [ ! -f $phpConfFile ];then
  876. comprobarError 1 4 "$phpConfFile"
  877. fi
  878. # Copiamos configuración
  879. cp -f $phpConfFile $phpDest 2>/dev/null
  880. comprobarError $? 305
  881. # Configuramos cgi.fix_pathinfo
  882. sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=0' $phpDest
  883. comprobarError $? 305
  884. # Configuramos post_max_size
  885. sed -i '/post_max_size =/c\post_max_size = '$maxUpload $phpDest
  886. comprobarError $? 305
  887. # Configuramos upload_max_filesize
  888. sed -i '/upload_max_filesize =/c\upload_max_filesize = '$maxUpload $phpDest
  889. comprobarError $? 305
  890. # Configurar php-fpm (sólo en RHEL con Nginx)
  891. if [ $rhelOS = true ] && [ $nginxOn = true ];then
  892. phpConfFile="./etc/php/php-fpm.d/www.conf"
  893. phpDest="/etc/php-fpm.d/www.conf"
  894. if [ ! -f $phpConfFile ];then
  895. comprobarError $? 4 "$phpConfFile"
  896. fi
  897. cp -f $phpConfFile $phpDest 2>/dev/null
  898. comprobarError $? 305
  899. fi
  900. unset phpConfFile phpDest
  901. }
  902. establecerMaxUpload() {
  903. control=false
  904. error=""
  905. while [ $control = false ];do
  906. 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)
  907. comprobarError $? 1
  908. if [ -z $maxUpload2 ];then
  909. error="ERROR: NO PUEDES DEJAR ESTE PARÁMETRO VACIO.\n"
  910. else
  911. control=true
  912. fi
  913. done
  914. maxUpload=$maxUpload2
  915. unset control maxUpload2
  916. }
  917. instalarPHPInfo() {
  918. # Instalar fichero php
  919. if [ ! -f /etc/$webServerName/sites-enabled/phpinfo.conf ];then
  920. infoFile="./var/www/info.php"
  921. if [ ! -f $infoFile ];then
  922. comprobarError 1 4 "$infoFile"
  923. fi
  924. cp -f $infoFile /var/www/html/ 2>/dev/null
  925. comprobarError $? 106
  926. chown -R $webServerUser:$webServerGroup /var/www/html 2>/dev/null
  927. comprobarError $? 106
  928. unset infoFile
  929. # Instalar VirtualHost
  930. if [ $debianOS = true ];then
  931. virtualHost="./etc/$webServerName-debian/sites-available/phpinfo.conf"
  932. elif [ $rhelOS = true ];then
  933. virtualHost="./etc/$webServerName-rhel/sites-available/phpinfo.conf"
  934. fi
  935. instalarVirtualHost $virtualHost
  936. unset virtualHost
  937. return 0
  938. else
  939. return 1
  940. fi
  941. }
  942. habilitarServicio() {
  943. # Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
  944. # Intentamos con systemctl (SystemD)
  945. #echo -en "Habilitando Servicio '$1'" | tee -a $logFile
  946. if [ $# -le 0 ];then
  947. comprobarError 1 900
  948. fi
  949. which systemctl > /dev/null 2>&1
  950. if [ $? -eq 0 ]; then
  951. #echo -en " (SystemD)..." | tee -a $logFile
  952. systemctl start $1 > /dev/null 2>&1
  953. comprobarError $? 901 $1
  954. systemctl enable $1 > /dev/null 2>&1
  955. comprobarError $? 902 $1
  956. else
  957. # Intentamos con service (Upstart)
  958. which service > /dev/null 2>&1
  959. if [ $? -eq 0 ]; then
  960. #echo -en " (Upstart)..." | tee -a $logFile
  961. service $1 start > /dev/null 2>&1
  962. comprobarError $? 901 $1
  963. else
  964. # Intentamos con init.d (SystemV)
  965. #echo -en " (SystemV)..." | tee -a $logFile
  966. /etc/init.d/$1 start > /dev/null 2>&1
  967. comprobarError $? 901 $1
  968. fi
  969. # Intentamos habilitar en el arranque (Upstart)
  970. which update-rc.d > /dev/null 2>&1
  971. if [ $? -eq 0 ];then
  972. update-rc.d $1 enable
  973. comprobarError $? 902 $1
  974. else
  975. # Intentamos habilitar en el arranque (SystemV)
  976. which chkconfig > /dev/null 2>&1
  977. if [ $? -eq 0 ];then
  978. chkconfig $1 on
  979. comprobarError $? 902 $1
  980. else
  981. # ¿Qué mas opciones nos quedan?
  982. comprobarError 1 902 $1
  983. fi
  984. fi
  985. fi
  986. # Mejora: comprobar si el servicio está parado
  987. #echo -en " OK.\n" | tee -a $logFile
  988. }
  989. deshabilitarServicio() {
  990. # Paramos y deshabilitamos el servicio (con SystemD, Upstart o SystemV)
  991. # Intentamos con systemctl (SystemD)
  992. #echo -en "Deshabilitando Servicio '$1'" | tee -a $logFile
  993. if [ $# -le 0 ];then
  994. comprobarError 1 903
  995. fi
  996. which systemctl > /dev/null 2>&1
  997. if [ $? -eq 0 ]; then
  998. #echo -en " (SystemD)..." | tee -a $logFile
  999. systemctl stop $1 > /dev/null 2>&1
  1000. comprobarError $? 904 $1
  1001. systemctl disable $1 > /dev/null 2>&1
  1002. comprobarError $? 905 $1
  1003. else
  1004. # Intentamos con service (Upstart)
  1005. which service > /dev/null 2>&1
  1006. if [ $? -eq 0 ]; then
  1007. #echo -en " (Upstart)..." | tee -a $logFile
  1008. service $1 stop > /dev/null 2>&1
  1009. comprobarError $? 904 $1
  1010. else
  1011. # Intentamos con init.d (SystemV)
  1012. #echo -en " (SystemV)..." | tee -a $logFile
  1013. /etc/init.d/$1 stop > /dev/null 2>&1
  1014. comprobarError $? 904 $1
  1015. fi
  1016. # Intentamos habilitar en el arranque (Upstart)
  1017. which update-rc.d > /dev/null 2>&1
  1018. if [ $? -eq 0 ];then
  1019. update-rc.d $1 disable
  1020. comprobarError $? 905 $1
  1021. else
  1022. # Intentamos habilitar en el arranque (SystemV)
  1023. which chkconfig > /dev/null 2>&1
  1024. if [ $? -eq 0 ];then
  1025. chkconfig $1 off
  1026. comprobarError $? 905 $1
  1027. else
  1028. # ¿Qué mas opciones nos quedan?
  1029. comprobarError 1 905 $1
  1030. fi
  1031. fi
  1032. fi
  1033. # Mejora: comprobar si el servicio está funcionando
  1034. #echo -en " OK.\n" | tee -a $logFile
  1035. }
  1036. recargarServicio() {
  1037. # Recargamos el servicio (con SystemD, Upstart o SystemV)
  1038. # Intentamos con systemctl (SystemD)
  1039. #echo -en "Recargando Servicio '$1'" | tee -a $logFile
  1040. if [ $# -le 0 ];then
  1041. comprobarError 1 912
  1042. fi
  1043. which systemctl > /dev/null 2>&1
  1044. if [ $? -eq 0 ]; then
  1045. #echo -en " (SystemD)..." | tee -a $logFile
  1046. systemctl reload $1 > /dev/null 2>&1
  1047. comprobarError $? 913 $1
  1048. else
  1049. # Intentamos con service (Upstart)
  1050. which service > /dev/null 2>&1
  1051. if [ $? -eq 0 ]; then
  1052. #echo -en " (Upstart)..." | tee -a $logFile
  1053. service $1 reload > /dev/null 2>&1
  1054. comprobarError $? 913 $1
  1055. else
  1056. # Intentamos con init.d (SystemV)
  1057. #echo -en " (SystemV)..." | tee -a $logFile
  1058. /etc/init.d/$1 reload > /dev/null 2>&1
  1059. comprobarError $? 913 $1
  1060. fi
  1061. fi
  1062. # Mejora: comprobar si el servicio está funcionando
  1063. #echo -en " OK.\n" | tee -a $logFile
  1064. }
  1065. configurarCortafuegos() {
  1066. # Configuramos cortafuegos (añadir reglas y encender)
  1067. # Comprobamos si estamos usando SSH
  1068. esSSH $PPID
  1069. if [ $debianOS = true ];then
  1070. ufw allow 80/tcp >> $logFile 2>&1
  1071. comprobarError $? 906 "80/tcp"
  1072. if [ $sshControl = true ];then
  1073. ufw allow 22/tcp >> $logFile 2>&1
  1074. comprobarError $? 906 "22/tcp"
  1075. fi
  1076. if [ $sslOn = true ];then
  1077. ufw allow 443/tcp >> $logFile 2>&1
  1078. comprobarError $? 906 "443/tcp"
  1079. fi
  1080. ufw --force enable >> $logFile 2>&1
  1081. comprobarError $? 907
  1082. elif [ $rhelOS = true ];then
  1083. firewall-cmd --add-port=80/tcp >> $logFile 2>&1
  1084. comprobarError $? 906 "80/tcp"
  1085. if [ $sshControl = true ];then
  1086. firewall-cmd --add-port=22/tcp >> $logFile 2>&1
  1087. comprobarError $? 906 "22/tcp"
  1088. fi
  1089. if [ $sslOn = true ];then
  1090. firewall-cmd --add-port=443/tcp >> $logFile 2>&1
  1091. comprobarError $? 906 "443/tcp"
  1092. fi
  1093. firewall-cmd --runtime-to-permanent >> $logFile 2>&1
  1094. comprobarError $? 907
  1095. habilitarServicio firewalld >> $logFile 2>&1
  1096. comprobarError $? 907
  1097. fi
  1098. unset sshControl
  1099. }
  1100. esSSH() {
  1101. p=${1:-$PPID}
  1102. #read pid name x ppid y < <( cat /proc/$p/stat )
  1103. read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
  1104. [[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
  1105. [ "$ppid" -le 1 ] && { sshControl=false; return 1; }
  1106. esSSH $ppid
  1107. }
  1108. descargarMediaWiki() {
  1109. # Descargar la versión 1.31.0 de MediaWiki
  1110. if [ ! -d ./var ];then
  1111. comprobarError 1 5 "./var"
  1112. fi
  1113. #echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
  1114. #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
  1115. curl "https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz" 2>$logFile | tar -xz -C "./var/"
  1116. comprobarError $? 501
  1117. #echo -en " Ok.\n" | tee -a $logFile
  1118. }
  1119. descargarMoodle() {
  1120. # Descargar la versión 1.31.0 de MediaWiki
  1121. if [ ! -d ./var ];then
  1122. comprobarError 1 5 "./var"
  1123. fi
  1124. #echo -en "Descargando Moodle-3.5-1..." | tee -a $logFile
  1125. #curl -o "./var/moodle-3.5.1.tgz" "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" >> $logFile 2>&1
  1126. curl "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" 2>$logFile | tar -xz -C "./var/"
  1127. comprobarError $? 501
  1128. #echo -en " OK.\n" | tee -a $logFile
  1129. }
  1130. # Comprobación del sistema e inicialización
  1131. inicializarVariables
  1132. comprobarRoot
  1133. OSInfo
  1134. comprobarDependencias
  1135. # Bienvenida
  1136. mostrarBienvenida
  1137. # Selección de componentes (express vs avanzada)
  1138. mostrarExpress
  1139. # Instalación Servidor Web
  1140. if [ $apacheOn = true ]; then
  1141. echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
  1142. # {
  1143. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1144. instalarApache
  1145. progreso=$((progreso + 1))
  1146. # } > >(whiptail --gauge "Instalando Web Server Apache..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1147. echo -en " OK.\n" | tee -a $logFile
  1148. elif [ $nginxOn = true ]; then
  1149. echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
  1150. # {
  1151. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1152. instalarNginx
  1153. progreso=$((progreso + 1))
  1154. # } > >(whiptail --gauge "Instalando Web Server Nginx..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1155. echo -en " OK.\n" | tee -a $logFile
  1156. fi
  1157. # Instalación Base de Datos
  1158. if [ $mySQLOn = true ]; then
  1159. echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
  1160. # {
  1161. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1162. instalarMySQL
  1163. progreso=$((progreso + 1))
  1164. # } > >(whiptail --gauge "Instalando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1165. echo -en " OK.\n" | tee -a $logFile
  1166. elif [ $mariaDBOn = true ]; then
  1167. echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
  1168. # {
  1169. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1170. instalarMariaDB
  1171. progreso=$((progreso + 1))
  1172. # } > >(whiptail --gauge "Instalando Base de Datos MariaDB..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1173. echo -en " OK.\n" | tee -a $logFile
  1174. fi
  1175. # Instalación PHP-7.2
  1176. if [ $phpOn = true ]; then
  1177. echo -en "Instalando PHP-7..." | tee -a $logFile
  1178. # {
  1179. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1180. instalarPHP
  1181. progreso=$((progreso + 1))
  1182. # } > >(whiptail --gauge "Instalando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1183. echo -en " OK.\n" | tee -a $logFile
  1184. fi
  1185. # Instalación SSL/TLS
  1186. if [ $sslOn = true ];then
  1187. echo -en "Instalando SSL/TLS..." | tee -a $logfile
  1188. # {
  1189. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1190. sleep 2
  1191. progreso=$((progreso + 1))
  1192. # } > >(whiptail --gauge "Instalando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1193. echo -en " OK.\n" | tee -a $logFile
  1194. fi
  1195. # Configuración Web Server
  1196. if [ $apacheOn = true ];then
  1197. echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
  1198. # {
  1199. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1200. configurarApache
  1201. progreso=$((progreso + 1))
  1202. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1203. echo -en " OK.\n" | tee -a $logFile
  1204. elif [ $nginxOn = true ]; then
  1205. echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
  1206. # {
  1207. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1208. configurarNginx
  1209. progreso=$((progreso + 1))
  1210. # } > >(whiptail --gauge "Configurando Servidor Web..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1211. echo -en " OK.\n" | tee -a $logFile
  1212. fi
  1213. # Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
  1214. if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
  1215. habilitarServicio "$sqlServerName"
  1216. echo -en "Configurando Base de Datos MySQL..." | tee -a $logFile
  1217. # {
  1218. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1219. establecerSQLPasswd
  1220. progreso=$((progreso + 1))
  1221. # } > >(whiptail --gauge "Configurando Base de Datos MySQL..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1222. echo -en " OK.\n" | tee -a $logFile
  1223. fi
  1224. # Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
  1225. if [ $phpOn = true ];then
  1226. echo -en "Configurando PHP-7..." | tee -a $logFile
  1227. # {
  1228. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1229. configurarPHP
  1230. progreso=$((progreso + 1))
  1231. # } > >(whiptail --gauge "Configurando PHP-7..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1232. echo -en " OK.\n" | tee -a $logFile
  1233. fi
  1234. # Configuración SSL/TLS
  1235. # Generar certificados
  1236. # Configurar certificados
  1237. if [ $sslOn = true ];then
  1238. echo -en "Configurando SSL/TLS..." | tee -a $logFile
  1239. # {
  1240. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1241. sleep 2
  1242. progreso=$((progreso + 1))
  1243. # } > >(whiptail --gauge "Configurando SSL/TLS..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1244. echo -en " OK.\n" | tee -a $logFile
  1245. fi
  1246. # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
  1247. # {
  1248. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1249. if [ $apacheOn = true ];then
  1250. habilitarServicio $webServerName
  1251. elif [ $nginxOn = true ];then
  1252. habilitarServicio $webServerName
  1253. if [ $phpOn = true ];then
  1254. habilitarServicio $phpFPMName
  1255. fi
  1256. fi
  1257. progreso=$((progreso + 1))
  1258. # } > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1259. # MediaWiki
  1260. if [ $mediaWikiOn = true ]; then
  1261. # Descargar MediaWiki
  1262. echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
  1263. # {
  1264. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1265. descargarMediaWiki
  1266. progreso=$((progreso + 1))
  1267. # } > >(whiptail --gauge "Instalando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1268. echo -en " OK.\n" | tee -a $logFile
  1269. # Configurar MediWiki
  1270. echo -en "Configurando MediaWiki..." | tee -a $logFile
  1271. # {
  1272. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1273. sleep 2
  1274. progreso=$((progreso + 1))
  1275. # } > >(whiptail --gauge "Configurando MediaWiki..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1276. echo -en " OK.\n" | tee -a $logFile
  1277. fi
  1278. # Moodle
  1279. if [ $moodleOn = true ]; then
  1280. # Descargar Moodle
  1281. echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
  1282. # {
  1283. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1284. descargarMoodle
  1285. progreso=$((progreso + 1))
  1286. # } > >(whiptail --gauge "Instalando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1287. echo -en " OK.\n" | tee -a $logFile
  1288. # Configuración Moodle
  1289. echo -en "Configurando Moodle..." | tee -a $logFile
  1290. # {
  1291. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1292. sleep 2
  1293. progreso=$((progreso + 1))
  1294. # } > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1295. echo -en " OK.\n" | tee -a $logFile
  1296. fi
  1297. # Configurar Virtual Hosts
  1298. # Instalar info.php
  1299. if [ $infoPHPOn = true ];then
  1300. echo -en "Configurando 'info.php'..." | tee -a $logFile
  1301. instalarPHPInfo
  1302. if [ $? -eq 0 ];then
  1303. echo -en " OK.\n" | tee -a $logFile
  1304. else
  1305. echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
  1306. fi
  1307. fi
  1308. # Añadir reglas del cortafuegos
  1309. echo -en "Configurando Cortafuegos..." | tee -a $logFile
  1310. # {
  1311. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1312. configurarCortafuegos
  1313. progreso=$((progreso + 1))
  1314. # } > >(whiptail --gauge "Configurando Cortafuegos..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1315. echo -en " OK.\n" | tee -a $logFile
  1316. # Configurar actualizaciones
  1317. if [ $actualizacionesOn = true ]; then
  1318. echo -en "Configurando Actualizaciones Automáticas..." | tee -a $logFile
  1319. # {
  1320. # echo -en "%s\n" $((100 * progreso / progresoTotal))
  1321. sleep 2
  1322. progreso=$((progreso + 1))
  1323. # } > >(whiptail --gauge "Configurando actualizaciones automáticas..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
  1324. echo -en " OK.\n" | tee -a $logFile
  1325. fi