1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059 |
- #!/bin/bash
- comprobarError() {
-
- type="ERROR"
- exitNum=$1
- shift
- codeNum=$1
- shift
- extraInfo=$@
- case $codeNum in
- 1)
- error="$type $codeNum:\tInstalación interrumpida por el usuario.\n"
- ;;
- 2)
- error="$type $codeNum:\tError interno (selección express).\n"
- ;;
- 3)
- error="$type $codeNum:\tError interno (selección avanzada).\n"
- ;;
- 4)
- error="\n$type $codeNum:\tEl archivo '"$(realpath $extraInfo)"' no existe.\n"
- ;;
- 5)
- error="\n$type $codeNum:\tEl directorio '"$(realpath $extraInfo)"' no existe.\n"
- ;;
- 6)
- error="$type $codeNum:\tError interno (selección SSL/TLS).\n"
- ;;
- 100)
- error="$type $codeNum:\tError interno (selección del servidor web).\n"
- ;;
- 101)
- error="\n$type $codeNum:\tError al instalar Apache2.\nDetalles:\n$extraInfo\n"
- ;;
- 102)
- error="\n$type $codeNum:\tError al instalar Nginx.\nDetalles:\n$extraInfo\n"
- ;;
- 103)
- error="\n$type $codeNum:\tError al nstalar repositorio 'epel-release'.\nDetalles:\n$extraInfo\n"
- ;;
- 104)
- error="\n$type $codeNum:\tError interno (instalación Apache2).\n"
- ;;
- 105)
- error="\n$type $codeNum:\tError interno (instalación Nginx).\n"
- ;;
- 106)
- type="WARNING"
- error="\n$type $codeNum:\tImposible instalar 'info.php'.\n"
- ;;
- 107)
- error="\n$type $codeNum:\tError al configurar Nginx.\n"
- ;;
- 108)
- error="\n$type $codeNum:\tError al configurar Apache2.\n"
- ;;
- 200)
- error="$type $codeNum:\tError interno (selección de base de datos).\n"
- ;;
- 201)
- error="\n$type $codeNum:\tError al instalar MySQL.\nDetalles:\n$extraInfo\n"
- ;;
- 202)
- error="\n$type $codeNum:\tError al instalar MariaDB.\nDetalles:\n$extraInfo\n"
- ;;
- 203)
- error="\n$type $codeNum:\tError interno (instalación MySQL).\n"
- ;;
- 204)
- error="\n$type $codeNum:\tError interno (instalación MariaDB).\n"
- ;;
- 205)
- error="\n$type $codeNum:\t$DIST no incluye MySQL en sus repositorios.\n"
- ;;
- 206)
- type="WARNING"
- error="\n$type $codeNum:\tUsuario 'root' ya dispone de contraseña."
- ;;
- 207)
- error="\n$type $codeNum:\tImposible cambiar la contraseña de 'root'."
- ;;
- 208)
- error="\n$type $codeNum:\tImposible desactivar acceso 'root' desde el exterior."
- ;;
- 209)
- error="\n$type $codeNum:\tImposible eliminar usuarios anónimos."
- ;;
- 210)
- type="WARNING"
- error="\n$type $codeNum:\tImposible eliminar bases de datos de pruebas."
- ;;
- 211)
- type="WARNING"
- error="\n$type $codeNum:\tImposible eliminar los permisos de las bases de datos de pruebas."
- ;;
- 212)
- error="\n$type $codeNum:\tImposible recargar base de datos."
- ;;
- 213)
- error="\n$type $codeNum:\tImposible configurar SQL.\n"
- ;;
- 214)
- type="WARNING"
- error="\n$type $codeNum:\tSQL ya está configurado."
- ;;
- 300)
- error="\n$type $codeNum:\tError interno (instalación PHP-7).\n"
- ;;
- 301)
- error="\n$type $codeNum:\tError interno (Web Server no seleccionado).\n"
- ;;
- 302)
- error="\n$type $codeNum:\tError al instalar PHP-7.\nDetalles:\n$extraInfo\n"
- ;;
- 303)
- error="\n$type $codeNum:\tError al instalar Repositorio Remi.\nDetalles:\n$extraInfo\n"
- ;;
- 304)
- error="\n$type $codeNum:\tSistema Operativo no compatible con PHP-7 ($OS $DIST $REV).\n"
- ;;
- 305)
- error="\n$type $codeNum:\tImposible configurar PHP-7.\n"
- ;;
- 401)
- error="\n$type $codeNum:\tError al instalar 'certbot' (Let's Encrypt).\n"
- ;;
- 402)
- error="\n$type $codeNum:\tImposible generar Certificados Autofirmados.\n"
- ;;
- 403)
- error="\n$type $codeNum:\tImposible generar claves de intercambio Diffie-Hellman.\n"
- ;;
- 404)
- error="\n$type $codeNum:\tImposible generar Certificados Let's Encrypt.\n"
- ;;
- 501)
- error="\n$type $codeNum:\tImposible descargar MediaWiki-1.31.0.\n"
- ;;
- 502)
- error="\n$type $codeNum:\tImposible configurar MediaWiki-1.31.0.\n"
- ;;
- 503)
- type="WARNING"
- error="\n$type $codeNum:\tYa existe una copia configurada de MediaWiki en el dominio: '$extraInfo'."
- ;;
- 601)
- error="\n$type $codeNum:\tImposible descargar Moodle-3.5.1.\n"
- ;;
- 602)
- error="\n$type $codeNum:\tImposible configurar Moodle-3.5.1.\n"
- ;;
- 603)
- type="WARNING"
- error="\n$type $codeNum:\tYa existe una copia configurada de Moodle en el dominio: '$extraInfo'."
- ;;
- 604)
- error="\n$type $codeNum:\tImposible configurar SELinux.\n"
- ;;
- 605)
- error="\n$type $codeNum:\tImposible instalar 'policycoreutils-python'.Detalles:\n$extraInfo\n"
- ;;
- 701)
- type="WARNING"
- error="\n$tupe $codeNum:\tImposible configurar actualizaciones automáticas.\n"
- ;;
- 800)
- error="$type $codeNum:\tEs necesario ser root ('sudo $0').\n"
- ;;
- 801)
- error="$type $codeNum:\t'whiptail' no instalado.\n"
- ;;
- 802)
- error="$type $codeNum:\t'hostnamectl' no instalado.\n"
- ;;
- 803)
- error="$type $codeNum:\t'apt-get' no instalado.\n"
- ;;
- 804)
- error="$type $codeNum:\t'yum' no instalado.\n"
- ;;
- 805)
- error="\n$type $codeNum:\tImposible actualizar repositorio\nDetalles:\n$extraInfo.\n"
- ;;
- 806)
- error="$type $codeNum:\t'ufw' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 807)
- error="$type $codeNum:\t'firewall-cmd' no instalado.\n"
- ;;
- 808)
- error="$type $codeNum:\t'tput' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 809)
- error="$type $codeNum:\t'sed' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 810)
- error="$type $codeNum:\t'curl' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 811)
- error="$type $codeNum:\t'tar' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 812)
- error="$type $codeNum:\t'gzip' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 813)
- error="$type $codeNum:\t'bzip2' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 814)
- error="$type $codeNum:\t'xz' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 815)
- error="$type $codeNum:\t'openssl' no instalado.\nDetalles:\n$extraInfo\n"
- ;;
- 816)
- error="$type $codeNum:\t'find' no instalado.\n"
- ;;
- 817)
- error="$type $codeNum:\tLa Distribución '$OS $DIST $REV' no está soportada.\nSoportadas: Ubuntu 16.04, 18.04, Debian 9, CentOS 7 y Fedora 28.\n"
- ;;
- 900)
- error="$type $codeNum:\tError interno (habilitar servicio).\n"
- ;;
- 901)
- error="$type $codeNum:\tImposible encender servicio '$extraInfo'.\n"
- ;;
- 902)
- error="$type $codeNum:\tImposible habilitar servicio '$extraInfo' durante el arranque.\n"
- ;;
- 903)
- error="$type $codeNum:\tError interno (deshabilitar servicio).\n"
- ;;
- 904)
- error="$type $codeNum:\tImposible parar servicio '$extraInfo'.\n"
- ;;
- 905)
- error="$type $codeNum:\tImposible deshabilitar servicio '$extraInfo' durante el arranque.\n"
- ;;
- 906)
- type="WARNING"
- error="\n$type $codeNum:\tImposible añadir regla al cortafuegos ('$extraInfo').\n"
- ;;
- 907)
- type="WARNING"
- error="\n$type $codeNum:\tImposible encender cortafuegos.\n"
- ;;
- 908)
- error="\n$type $codeNum:\tError interno (instalar Virtual Host).\n"
- ;;
- 909)
- error="\n$type $codeNum:\tVirtual Host '$extraInfo' no existe.\n"
- ;;
- 910)
- error="\n$type $codeNum:\tImposible copiar Virtual Host '$extraInfo'.\n"
- ;;
- 911)
- error="\n$type $codeNum:\tImposible activar Virtual Host '$extraInfo'.\n"
- ;;
- 912)
- error="\n$type $codeNum:\tError interno (recargar servicio).\n"
- ;;
- 913)
- error="\n$type $codeNum:\tImposible recargar servicio '$extraInfo'.\n"
- ;;
- *)
- error="ERROR 13:\tError interno (comprobación de errores)\n"
- exitNum=1
- codeNum=13
- ;;
- esac
- if [ $exitNum -ne 0 ];then
- echo -en "$error" | tee -a $logFile
- if [ $type = "ERROR" ];then
- exit $codeNum
- fi
- fi
- unset error exitNum codeNum type
- }
- OSInfo() {
- echo -en "Detectando SO..." >> $logFile
- OS=$(uname -s)
- if [ $OS = "Linux" ]; then
- OS="GNU/Linux"
- if [ -f /etc/os-release ]; then
- DIST=$(grep ^NAME= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
- REV=$(grep ^VERSION= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
- ID=$(grep ^ID= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
- ID_LIKE=$(grep ^ID_LIKE= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
- VERSION=$(grep ^VERSION_ID= /etc/os-release | cut -d = -f 2 | cut -d '"' -f 2)
- for i in $ID; do
- case $i in
- debian)
- debianOS=true
- case $VERSION in
- 9)
- apacheName="apache2"
- nginxName="nginx"
- mysqlName="mysql"
- mariadbName="mariadb"
- phpFPMName="php7.0-fpm"
- phpDest="/etc/php/7.2/cli/php.ini"
- ;;
- *)
- comprobarError 1 817
- ;;
- esac
- break
- ;;
- ubuntu)
- debianOS=true
- case $VERSION in
- 18.04)
- apacheName="apache2"
- nginxName="nginx"
- mysqlName="mysql"
- mariadbName="mariadb"
- phpFPMName="php7.2-fpm"
- phpDest="/etc/php/7.2/cli/php.ini"
- ;;
- 16.04)
- apacheName="apache2"
- nginxName="nginx"
- mysqlName="mysql"
- mariadbName="mysql"
- phpFPMName="php7.0-fpm"
- phpDest="/etc/php/7.0/cli/php.ini"
- ;;
- *)
- comprobarError 1 817
- ;;
- esac
- break
- ;;
- rhel|centos)
- rhelOS=true
- case $VERSION in
- 7)
- apacheName="httpd"
- nginxName="nginx"
- mysqlName=""
- mariadbName="mariadb"
- phpFPMName="php-fpm"
- ;;
- *)
- comprobarError 1 817
- ;;
- esac
- break
- ;;
- fedora)
- rhelOS=true
- case $VERSION in
- 28)
- apacheName="httpd"
- nginxName="nginx"
- mysqlName=""
- mariadbName="mariadb"
- phpFPMName="php-fpm"
- ;;
- *)
- comprobarError 1 817
- ;;
- esac
- break
- ;;
- *)
- debianOS=false
- rhelOS=false
- comprobarError 1 817
- ;;
- esac
- done
- else
-
- comprobarError 1 817
- fi
- else
-
- comprobarError 1 817
- fi
- echo -en " $OS $DIST $REV\n" >> $logFile
- HDInfo=$(df -h | head -1)"\n"$(df -h | grep ^/dev/sd)"\n"$(df -h | grep ^/dev/mapper)
- echo -en "$HDInfo\n" >> $logFile
- }
- comprobarRoot() {
- comprobarError $(id -u) 800
- }
- comprobarDependencias() {
-
- which whiptail > /dev/null 2>&1
- comprobarError $? 801
-
- which hostnamectl > /dev/null 2>&1
- comprobarError $? 802
- which find > /dev/null 2>&1
- comprobarError $? 816
- if [ $debianOS = true ];then
-
- which apt-get > /dev/null 2>&1
- comprobarError $? 803
-
- echo -en "Actualizando repositorio APT..." | tee -a $logFile
- result=$(apt-get -q -y update 2>&1)
- comprobarError $? 805 $result
- echo -en " OK.\n" | tee -a $logFile
-
- which ufw > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install ufw 2>&1)
- comprobarError $? 806 $result
- fi
-
- which tput > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install ncurses-bin 2>&1)
- comprobarError $? 808 $result
- fi
-
- which sed > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install sed 2>&1)
- comprobarError $? 809 $result
- fi
-
- which curl > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install curl 2>&1)
- comprobarError $? 810 $result
- fi
-
- which tar > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install tar 2>&1)
- comprobarError $? 811 $result
- fi
- which gzip > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install gzip 2>&1)
- comprobarError $? 812 $result
- fi
- which bzip2 > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install bzip2 2>&1)
- comprobarError $? 813 $result
- fi
- which xz > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install xz-utils 2>&1)
- comprobarError $? 814 $result
- fi
- which openssl > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(apt-get -q -y install openssl 2>&1)
- comprobarError $? 815 $result
- fi
- fi
- if [ $rhelOS = true ]; then
-
- which yum > /dev/null 2>&1
- comprobarError $? 804
-
- echo -en "Actualizando repositorio YUM..." | tee -a $logFile
- result=$(yum -y makecache 2>&1)
- comprobarError $? 805 $result
- echo -en " OK.\n" | tee -a $logFile
-
- which firewall-cmd > /dev/null 2>&1
- comprobarError $? 807
-
- which tput > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(yum -y install ncurses 2>&1)
- comprobarError $? 808 $result
- fi
-
- which sed > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(yum -y install sed 2>&1)
- comprobarError $? 809 $result
- fi
-
- which curl > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(yum -y install curl 2>&1)
- comprobarError $? 810 $result
- fi
-
- which tar > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(yum -y install tar 2>&1)
- comprobarError $? 811 $result
- fi
- which gzip > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(yum -y install gzip 2>&1)
- comprobarError $? 812 $result
- fi
- which bzip2 > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(yum -y install bzip2 2>&1)
- comprobarError $? 813 $result
- fi
- which xz > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(yum -y install xz 2>&1)
- comprobarError $? 814 $result
- fi
- which openssl > /dev/null 2>&1
- if [ $? -ne 0 ];then
- result=$(yum -y install openssl 2>&1)
- comprobarError $? 815 $result
- fi
- fi
- }
- inicializarVariables() {
- debianOS=false
- rhelOS=false
- apacheOn=false
- nginxOn=false
- mySQLOn=false
- mariaDBOn=false
- phpOn=false
- sslOn=false
- letsEncryptOn=false
- mediaWikiOn=false
- moodleOn=false
- infoPHPOn=false
- backupOn=false
- hostname=""
- logFile="./."$(basename $0)".log"
- maxUpload="100M"
- apacheName=""
- nginxName=""
- mysqlName=""
- mariadbName=""
- webServerName=""
- webServerUser=""
- webServerGroup=""
- sqlServerName=""
- phpFPMName=""
- nombreMediaWiki=""
- dominioMediaWiki=""
- passwdMediaWiki=""
- nombreMoodle=""
- nombreCortoMoodle=""
- dominioMoodle=""
- passwdMoodle=""
- }
- instalacionExpress() {
- nginxOn=true
- mariaDBOn=true
- phpOn=true
- sslOn=true
- letsEncryptOn=true
- mediaWikiOn=true
- moodleOn=true
- backupOn=true
-
- establecerFQDN
- leerSQLPasswd
- mostrarMediaWiki
- mostrarMoodle
- mostrarConfirmacion
- }
- mostrarBienvenida() {
- ANCHO=$(tput cols)
- ALTO=$(tput lines)
- whiptail --title "INSTALACION MEDIAWIKI" --yesno "Este script automatiza completamente la instalación de una WIKI y un CAMPUS VIRTUAL.\nPara ello instala un servidor LAMP, el software MediaWiki y configura todo lo necesario.\n\nInformación del sistema:\nOS: $OS $DIST $REV\n$HDInfo" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --yes-button "Continuar" --no-button "Salir"
- comprobarError $? 1
- }
- mostrarExpress() {
- express=$(whiptail --title "INSTALACION EXPRESS" --radiolist "<ESPACIO>: seleccionar <TAB>: cambiar <FLECHAS>: moverse\n\nLa instalación express instala Nginx, MariaDB, PHP-7, Let's Encrypt, MediaWiki, Moodle y backups automático.\nSeleccione el tipo de instalación que desee:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \
- "Express" "Instalación rápida" ON \
- "Avanzada" "Permite escoger todas las opciones disponibles" OFF \
- --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- case $express in
- Express)
- instalacionExpress
-
- ;;
- Avanzada)
- mostrarAvanzada
- ;;
- *)
- comprobarError 1 2
- ;;
- esac
- unset express
- }
- mostrarAvanzada() {
- 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 \
- "LEMP" "GNU/Linux + (E)Nginx + MySQL/MariaDB + PHP-7" ON \
- "LAMP" "GNU/Linux + Apache + MySQL/MariaDB + PHP-7" OFF \
- --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- for i in $webServer; do
- case $i in
- LEMP)
- nginxOn=true
- ;;
- LAMP)
- apacheOn=true
- ;;
- *)
- comprobarError 1 100
- ;;
- esac
- done
-
- establecerFQDN
- mostrarDatabase
- phpOn=true
- establecerMaxUpload
- mostrarComponentes
- mostrarConfirmacion
- unset webServer
- }
- mostrarComponentes() {
- 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 \
- "SSL/TLS" "Instalar certificados para activar HTTPS" ON \
- "MediaWiki" "Instalar wiki con MediaWiki" ON \
- "Moodle" "Instalar campus virtual con Moodle" ON \
- "InfoPHP" "Instalar info.php (sólo para pruebas)" OFF \
- "Backup" "Programar backups automáticos" ON \
- --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
-
- for i in $componentes; do
- case $i in
- \"SSL/TLS\")
-
- mostrarSSL
- ;;
- \"MediaWiki\")
- mediaWikiOn=true
- mostrarMediaWiki
- ;;
- \"Moodle\")
- moodleOn=true
- mostrarMoodle
- ;;
- \"InfoPHP\")
- infoPHPOn=true
- ;;
- \"Backup\")
- backupOn=true
- ;;
- *)
- comprobarError 1 3
- ;;
- esac
- done
- unset componentes
- }
- mostrarSSL() {
- ssl=$(whiptail --title "INSTALACION SSL/TLS" --radiolist "<ESPACIO>: seleccionar <TAB>: cambiar <FLECHAS>: moverse\n\nEscoge el tipo de Certificado SSL/TLS que quieres instalar:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) 2 \
- "LetsEncrypt" "Compatible con todos los navegadores" ON \
- "Auto-Firmado" "Certificados auto-firmados (sólo para pruebas)" OFF \
- --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- for i in $ssl; do
- case $i in
- LetsEncrypt)
- sslOn=true
- letsEncryptOn=true
- ;;
- Auto-Firmado)
- sslOn=true
- ;;
- *)
- comprobarError 1 6
- ;;
- esac
- done
- unset ssl
- }
- mostrarMediaWiki(){
-
- while [ -z "$nombreMediaWiki" ]; do
- nombreMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --inputbox "Introduzca el nombre de la Wiki:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- done
-
- while [ -z "$dominioMediaWiki" ]; do
- dominioMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --inputbox "Introduzca el dominio/subdominio de la Wiki.\nTenga en cuenta que debes apuntar este dominio a la dirección IP de esta máquina mediante un registro DNS de tipo CNAME.\nSi quiere introducir varios dominios sepárelos con espacios. El primero será el principal.\nPor ejemplo: 'www.$hostname $hostname wiki.$hostname'" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) wiki.$hostname --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- done
- cont=1
- serverName=""
- aliasMediaWiki=""
- for dominio in $dominioMediaWiki;do
- if [ $cont -eq 1 ];then
-
- serverName=$dominio
- else
-
- aliasMediaWiki=$aliasMediaWiki" "$dominio
- fi
- cont=$((cont + 1))
- done
- dominioMediaWiki=$serverName
-
- control=false
- error=""
- while [ $control = false ]; do
- passwdMediaWiki=$(whiptail --title "CONFIGURACION MEDIAWIKI" --passwordbox "$error""Introduzca la contraseña para el usuario administrador 'admin':" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
- comprobarError $? 1
- passwdMediaWiki2=$(whiptail --title "CONFIGURACION MEDIAWIKI" --passwordbox "Confirme la contraseña:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
- comprobarError $? 1
- if [ -z "$passwdMediaWiki" ] || [ -z "$passwdMediaWiki2" ]; then
- error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
- elif [ $passwdMediaWiki != $passwdMediaWiki2 ];then
- error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
- else
- control=true
- fi
- done
- unset control error passwdMediaWiki2 dominio cont serverName
- }
- mostrarMoodle() {
-
- while [ -z "$nombreMoodle" ]; do
- nombreMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el NOMBRE COMPLETO del campus virtual.\nPor ejemplo: 'Campus Virtual Ejemplo'." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- done
-
- while [ -z "$nombreCortoMoodle" ]; do
- nombreCortoMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el NOMBRE CORTO del campus virtual.\nPor ejemplo: 'Ejemplo'." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- done
- nombreCortoMoodle=$(echo $nombreCortoMoodle | cut -d ' ' -f 1)
-
- while [ -z "$dominioMoodle" ]; do
- dominioMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el dominio/subdominio del campus virtual.\nMoodle SÓLO permite un ÚNICO DOMINIO." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) moodle.$hostname --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- done
- cont=1
- serverName=""
- aliasMoodle=""
- for dominio in $dominioMoodle;do
- if [ $cont -eq 1 ];then
-
- serverName=$dominio
- else
-
- aliasMeoodle=$aliasMoodle" "$dominio
- fi
- cont=$((cont + 1))
- done
- dominioMoodle=$serverName
-
- control=false
- error=""
- while [ $control = false ]; do
- passwdMoodle=$(whiptail --title "CONFIGURACION MOODLE" --passwordbox "$error""Introduzca la contraseña para el usuario administrador 'admin':" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
- comprobarError $? 1
- passwdMoodle2=$(whiptail --title "CONFIGURACION MOODLE" --passwordbox "Confirme la contraseña:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --nocancel 3>&1 1>&2 2>&3)
- comprobarError $? 1
- if [ -z "$passwdMoodle" ] || [ -z "$passwdMoodle2" ]; then
- error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
- elif [ $passwdMoodle != $passwdMoodle2 ];then
- error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
- else
- control=true
- fi
- done
- unset control error passwdMoodle2 dominio cont serverName aliasMoodle
- }
- mostrarConfirmacion() {
- whiptail --title "INSTALACION" --yesno "ESTA TODO LISTO PARA LA INSTALACION.\nNO SE OLVIDE DE GUARDAR LAS CONFIGURACIONES EN UN LUGAR SEGURO, YA QUE SERÁN IMPORTANTES POR SI DESEA HACER ALGÚN CAMBIO EN EL FUTURO.\n¿DESEA CONTINUAR?" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --yes-button "Instalar" --no-button "Salir"
- comprobarError $? 1
- }
- establecerFQDN() {
- while [ -z "$hostname" ]; do
- hostname=$(whiptail --title "FQDN" --inputbox "El nombre de dominio principal (FQDN) de este servidor es:\n"$(hostname)"\n\n¿Quieres cambiarlo por otro?" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Cambiar" --cancel-button "No Cambiar" 3>&1 1>&2 2>&3)
- if [ $? -eq 0 ] && [ ! -z "$hostname" ]; then
- hostnamectl set-hostname $hostname
- else
- hostname=$(hostname)
- fi
- done
- echo -en "Hostname: $hostname\n" >> $logFile
- }
- instalarApache() {
- webServerName=$apacheName
- if [ $debianOS = true ];then
- result=$(apt-get -q -y install apache2 2>&1)
- comprobarError $? 101 $result
- elif [ $rhelOS = true ]; then
- result=$(yum -y install httpd 2>&1)
- comprobarError $? 101 $result
- if [ $sslOn = true ];then
-
- result=$(yum -y install mod_ssl 2>&1)
- comprobarError $? 101 $result
- fi
- else
- comprobarError 1 104
- fi
- deshabilitarServicio $webServerName
- }
- configurarApache() {
- if [ $debianOS = true ];then
- apacheConfFile="./etc/apache2/apache2.conf"
- if [ ! -f $apacheConfFile ];then
- comprobarError 1 4 $apacheConfFile
- fi
- cp -f $apacheConfFile /etc/$webServerName/apache2.conf 2>/dev/null
- comprobarError $? 108
- webServerUser=$(grep ^User /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
- webServerGroup=$(grep ^Group /etc/$webServerName/apache2.conf | cut -d ' ' -f 2)
- if [ ! -L /etc/$webServerName/logs ];then
- ln -s /var/log/apache2 /etc/$webServerName/logs 2>/dev/null
- comprobarError $? 108
- fi
-
- a2enmod rewrite >/dev/null 2>&1
- comprobarError $? 108
-
- if [ $sslOn = true ];then
- a2enmod ssl >/dev/null 2>&1
- comprobarError $? 108
- a2enmod headers >/dev/null 2>&1
- comprobarError $? 108
- fi
- unset apacheConfFile
- elif [ $rhelOS = true ];then
- apacheConfFile="./etc/apache2/conf/httpd.conf"
- sslConfFile="./etc/apache2/conf.d/ssl.conf"
- welcomeConfFile="/etc/apache2/conf.d/welcome.conf"
- if [ ! -f $apacheConfFile ];then
- comprobarError 1 4 $apacheConfFile
- fi
- cp -f $apacheConfFile /etc/$webServerName/conf/httpd.conf 2>/dev/null
- comprobarError $? 108
-
- if [ -f $welcomeConfFile ];then
- sed -i -e 's/^/#/' $welcomeConfFile
- comprobarError $? 108
- fi
-
- if [ $sslOn = true ];then
- if [ ! -f $sslConfFile ];then
- comprobarError 1 4 $sslConfFile
- fi
- cp -f $sslConfFile /etc/$webServerName/conf.d/ssl.conf 2>/dev/null
- comprobarError $? 108
- fi
- webServerUser=$(grep ^User /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
- webServerGroup=$(grep ^Group /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
- unset apacheConfFile sslConfFile welcomeConfFile
- fi
- if [ ! -d "/etc/$webServerName/sites-available" ];then
- mkdir "/etc/$webServerName/sites-available" 2>/dev/null
- comprobarError $? 5 "/etc/$webServerName/sites-available"
- fi
- if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
- mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
- comprobarError $? 5 "/etc/$webServerName/sites-enabled"
- else
-
- if [ -f /etc/$webServerName/sites-enabled/000-default.conf ];then
- rm -f /etc/$webServerName/sites-enabled/000-default.conf 2>/dev/null
- fi
- fi
- }
- instalarNginx() {
- webServerName=$nginxName
- case $ID in
- ubuntu|debian)
- result=$(apt-get -q -y install nginx 2>&1)
- comprobarError $? 102 $result
- ;;
- centos)
-
- result=$(yum -y install epel-release)
- comprobarError $? 103 $result
- result=$(yum -y install nginx 2>&1)
- comprobarError $? 102 $result
- ;;
- fedora)
- result=$(yum -y install nginx 2>&1)
- comprobarError $? 102 $result
- ;;
- *)
- comprobarError 1 105
- ;;
- esac
- deshabilitarServicio $webServerName
- }
- configurarNginx() {
- rm -Rf "/etc/$webServerName/!(sites-available|sites-enabled)" 2>/dev/null
- comprobarError $? 107
- nginxConfFile="./etc/$webServerName"
- if [ -d "$nginxConfFile" ];then
- cp -Rf $nginxConfFile/* /etc/$webServerName/ 2>/dev/null
- comprobarError $? 107
- else
- comprobarError 1 5 "$nginxConfFile"
- fi
- if [ ! -d "/etc/$webServerName/sites-available" ];then
- mkdir "/etc/$webServerName/sites-available" 2>/dev/null
- comprobarError $? 5 "/etc/$webServerName/sites-available"
- fi
- if [ ! -d "/etc/$webServerName/sites-enabled" ]; then
- mkdir "/etc/$webServerName/sites-enabled" 2>/dev/null
- comprobarError $? 5 "/etc/$webServerName/sites-enabled"
- else
-
- if [ -f /etc/$webServerName/sites-enabled/default ];then
- rm -f /etc/$webServerName/sites-enabled/default 2>/dev/null
- fi
- fi
-
- if [ $debianOS = true ];then
- webServerUser="www-data"
- webServerGroup=$webServerUser
- elif [ $rhelOS = true ];then
- webServerUser="nginx"
- webServerGroup=$webServerUser
- fi
- sed -i '/user /c\user '$webServerUser';' /etc/$webServerName/nginx.conf
- comprobarError $? 107
- unset nginxConfFile
- }
- instalarVirtualHost() {
- if [ $# -ge 3 ];then
- rootVirtualHost=$(realpath $1)
- shift
- virtualHostFile=$(realpath $1)
- shift
- dominioVirtualHost=$1
- virtualHostName=$dominioVirtualHost".conf"
- shift
- aliasVirtualHost=$@
- else
- comprobarError 1 908
- fi
- if [ ! -f $virtualHostFile ];then
- comprobarError 1 909 $virtualHostName
- fi
- if [ $apacheOn = true ];then
-
- sed -i '/ServerName /c\\tServerName '"$dominioVirtualHost" $virtualHostFile
- comprobarError $? 908
- if [ ! -z "$aliasVirtualHost" ];then
- sed -i '/ServerName /a\\tServerAlias '"$aliasVirtualHost" $virtualHostFile
- comprobarError $? 908
- fi
- sed -i '/DocumentRoot /c\\tDocumentRoot '"$rootVirtualHost" $virtualHostFile
- comprobarError $? 908
- sed -i '/ErrorLog /c\\tErrorLog logs/'"$dominioVirtualHost"'-error.log' $virtualHostFile
- comprobarError $? 908
- sed -i '/CustomLog /c\\tCustomLog logs/'"$dominioVirtualHost"'-access.log common' $virtualHostFile
- comprobarError $? 908
- if [ $sslOn = true ];then
- sed -i '/SSLCertificateFile /c\\tSSLCertificateFile ssl/'"$dominioVirtualHost"'.crt' $virtualHostFile
- comprobarError $? 908
- sed -i '/SSLCertificateKeyFile /c\\tSSLCertificateKeyFile ssl/'"$dominioVirtualHost"'.key' $virtualHostFile
- comprobarError $? 908
- fi
- elif [ $nginxOn = true ];then
-
- sed -i '/root /c\\troot '$rootVirtualHost';' "$virtualHostFile"
- comprobarError $? 908
- sed -i '/server_name /c\\tserver_name '"$dominioVirtualHost"' '"$aliasVirtualHost"';' $virtualHostFile
- comprobarError $? 908
- sed -i '/access_log /c\\taccess_log /var/log/nginx/'"$dominioVirtualHost"'-access.log;' $virtualHostFile
- comprobarError $? 908
- sed -i '/error_log /c\\terror_log /var/log/nginx/'"$dominioVirtualHost"'-error.log;' $virtualHostFile
- comprobarError $? 908
- socket=$(find /var/run/ -type s -name 'php*.sock')
- sed -i '/fastcgi_pass /c\\t\tfastcgi_pass unix:'"$socket"';' $virtualHostFile
- comprobarError $? 908
- if [ $sslOn = true ];then
- sed -i '/ssl_certificate /c\\tssl_certificate ssl/'"$dominioVirtualHost"'.crt;' $virtualHostFile
- comprobarError $? 908
- sed -i '/ssl_certificate_key /c\\tssl_certificate_key ssl/'"$dominioVirtualHost"'.key;' $virtualHostFile
- comprobarError $? 908
- fi
- fi
-
- cp -f $virtualHostFile "/etc/$webServerName/sites-available/$virtualHostName" >> $logFile 2>&1
- comprobarError $? 910
- if [ -f "/etc/$webServerName/sites-enabled/$virtualHostName" ];then
- rm -f /etc/$webServerName/sites-enabled/$virtualHostName 2>/dev/null
- comprobarError 911 $virtualHostName
- fi
- ln -s "/etc/$webServerName/sites-available/$virtualHostName" "/etc/$webServerName/sites-enabled/$virtualHostName" >> $logFile 2>&1
- comprobarError $? 911 $virtualHostName
- recargarServicio $webServerName
- unset rootVirtualHost dominioVirtualHost virtualHostFile virtualHostName aliasVirtualHost socket
- }
- mostrarDatabase() {
- if [ $debianOS = true ]; then
- 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 \
- "MariaDB" "Instalar la base de datos MariaDB (fork de MySQL)" ON \
- "MySQL" "Instalar la base de datos MySQL (uso no comercial)" OFF \
- --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
- comprobarError $? 1
- case $database in
- MariaDB)
- mariaDBOn=true
- ;;
- MySQL)
- mySQLOn=true
- ;;
- *)
- comprobarError 1 200
- ;;
- esac
- unset database
- elif [ $rhelOS = true ]; then
- 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"
- comprobarError $? 1
- mariaDBOn=true
- else
- comprobarError 1 200
- fi
-
- leerSQLPasswd
- }
- leerSQLPasswd() {
- control=false
- error=""
-
- while [ $control = false ]; do
- 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)
- comprobarError $? 1
- 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)
- comprobarError $? 1
-
-
- if [ -z "$sqlPasswd" ] || [ -z "$sqlPasswd2" ]; then
- error="ERROR: LA CONTRASEÑA NO PUEDE ESTAR VACIA.\n"
- elif [ $sqlPasswd != $sqlPasswd2 ];then
- error="ERROR: LAS CONTRASEÑAS NO COINCIDEN.\n"
- else
- control=true
- fi
- done
-
- unset control error sqlPasswd2
- }
- establecerSQLPasswd() {
-
- mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
- if [ $? -eq 0 ];then
-
- mysql -e "UPDATE mysql.user SET plugin = '', Password = PASSWORD('$sqlPasswd') WHERE User = 'root'" >> $logFile 2>&1
- if [ $? -ne 0 ];then
-
- mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$sqlPasswd'" >> $logFile 2>&1
- comprobarError $? 207
- fi
-
- mysql -e "FLUSH PRIVILEGES" >> $logFile 2>&1
-
- mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" >> $logFile 2>&1
- comprobarError $? 208
-
- mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.user WHERE User=''" >> $logFile 2>&1
- comprobarError $? 209
-
- mysql -u root --password=$sqlPasswd -e "DROP DATABASE IF EXISTS test" >> $logFile 2>&1
- comprobarError $? 210
-
- mysql -u root --password=$sqlPasswd -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" >> $logFile 2>&1
- comprobarError $? 211
-
- mysql -u root --password=$sqlPasswd -e "FLUSH PRIVILEGES" >> $logFile 2>&1
- comprobarError $? 212
- else
- comprobarError 1 206
- fi
- }
- instalarMySQL() {
- sqlServerName=$mysqlName
- if [ $debianOS = true ];then
- result=$(apt-get -q -y install mysql-server mysql-client 2>&1)
- comprobarError $? 201 $result
- elif [ $rhelOS = true ];then
-
-
-
- comprobarError 1 205
- else
- comprobarError 1 203
- fi
- deshabilitarServicio $sqlServerName
- }
- instalarMariaDB() {
- sqlServerName=$mariadbName
- if [ $debianOS = true ];then
- result=$(apt-get -q -y install mariadb-server mariadb-client 2>&1)
- comprobarError $? 202 $result
- elif [ $rhelOS = true ];then
- result=$(yum -y install mariadb-server mariadb 2>&1)
- comprobarError $? 202 $result
- else
- comprobarError 1 204
- fi
- deshabilitarServicio $sqlServerName
- }
- configurarSQL() {
-
- if [ $mariaDBOn = true ] && [ $debianOS = true ];then
- sqlConfFile="/etc/mysql/my.cnf"
- elif [ $mariaDBOn = true ] && [ $rhelOS = true ];then
- sqlConfFile="/etc/my.cnf"
- elif [ $mySQLOn = true ] && [ $debianOS = true ];then
- sqlConfFile="/etc/mysql/my.cnf"
- else
- comprobarError 1 213
- fi
- if [ ! -f $sqlConfFile ];then
- comprobarError 1 213
- fi
- grep "# Configuration for Moodle" $sqlConfFile >/dev/null 2>&1
- if [ $? -ne 0 ];then
-
- echo -en "\n# Configuration for Moodle\n" >> $sqlConfFile
- echo -en "[client]\n" >> $sqlConfFile
- echo -en "default-character-set = utf8mb4\n\n" >> $sqlConfFile
- echo -en "[mysqld]\n" >> $sqlConfFile
- echo -en "innodb_file_format = Barracuda\n" >> $sqlConfFile
- echo -en "innodb_file_per_table = 1\n" >> $sqlConfFile
- echo -en "innodb_large_prefix\n\n" >> $sqlConfFile
- echo -en "character-set-server = utf8mb4\n" >> $sqlConfFile
- echo -en "collation-server = utf8mb4_unicode_ci\n" >> $sqlConfFile
- echo -en "skip-character-set-client-handshake\n\n" >> $sqlConfFile
- echo -en "[mysql]\n" >> $sqlConfFile
- echo -en "default-character-set = utf8mb4\n" >> $sqlConfFile
- else
- comprobarError 1 214
- fi
- unset sqlConfFile
- }
- instalarPHP() {
- case $ID in
- ubuntu|debian)
- if [ $apacheOn = true ]; then
- result=$(apt-get -q -y install php libapache2-mod-php php-mysql php-intl php-mbstring php-xml php-apcu php-gd php-curl php-zip php-soap php-xmlrpc 2>&1)
- comprobarError $? 302 $result
- elif [ $nginxOn = true ];then
- result=$(apt-get -q -y install php-fpm php-mysql php-intl php-mbstring php-xml php-apcu php-gd php-curl php-zip php-soap php-xmlrpc 2>&1)
- comprobarError $? 302 $result
- deshabilitarServicio $phpFPMName
- else
- comprobarError 1 301
- fi
- ;;
- centos)
-
- result=$(yum -y install epel-release yum-utils 2>&1)
- comprobarError $? 103 $result
-
- if [ ! -f /etc/yum.repos.d/remi-php72.repo ];then
- result=$(yum -y install "http://remi.mirrors.cu.be/enterprise/remi-release-7.rpm" 2>&1)
- comprobarError $? 303 $result
- fi
-
- result=$(yum-config-manager --enable remi-php72 2>&1)
- comprobarError $? 303 $result
-
- if [ $apacheOn = true ];then
- result=$(yum -y install php php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd php-pear-Net-Curl php-pecl-zip php-soap php-xmlrpc 2>&1)
- comprobarError $? 302 $result
- elif [ $nginxOn = true ];then
- result=$(yum -y install php php-fpm php-mysql php-intl php-mbstring php-mcrypt php-xml php-pecl-apcu php-gd php-pear-Net-Curl php-pecl-zip php-soap php-xmlrpc 2>&1)
- comprobarError $? 302 $result
- deshabilitarServicio $phpFPMName
- else
- comprobarError 1 301
- fi
- ;;
- fedora)
-
- if [ $apacheOn = true ];then
- result=$(yum -y install php php-mysqlnd php-intl php-mbstring php-pecl-mcrypt php-xml php-pecl-apcu php-gd php-pear-Net-Curl php-pecl-zip php-soap php-xmlrpc php-json 2>&1)
- comprobarError $? 302 $result
- elif [ $nginxOn = true ];then
- result=$(yum -y install php php-fpm php-mysqlnd php-intl php-mbstring php-pecl-mcrypt php-xml php-pecl-apcu php-gd php-pear-Net-Curl php-pecl-zip php-soap php-xmlrpc php-json 2>&1)
- comprobarError $? 302 $result
- deshabilitarServicio $phpFPMName
- else
- comprobarError 1 301
- fi
- ;;
- *)
- comprobarError 1 300
- ;;
- esac
- }
- configurarPHP() {
- if [ $debianOS = true ];then
- phpConfFile="./etc/php/php.ini.debian"
-
- elif [ $rhelOS = true ];then
- phpConfFile="./etc/php/php.ini.rhel"
- phpDest="/etc/php.ini"
- fi
- if [ ! -f $phpConfFile ];then
- comprobarError 1 4 "$phpConfFile"
- fi
-
- cp -f $phpConfFile $phpDest 2>/dev/null
- comprobarError $? 305
-
- sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=0' $phpDest
- comprobarError $? 305
-
- sed -i '/post_max_size =/c\post_max_size = '$maxUpload $phpDest
- comprobarError $? 305
-
- sed -i '/upload_max_filesize =/c\upload_max_filesize = '$maxUpload $phpDest
- comprobarError $? 305
-
- if [ $rhelOS = true ] && [ $nginxOn = true ];then
-
- phpConfFile="./etc/php/php-fpm.d/www.conf"
- phpDest="/etc/php-fpm.d/www.conf"
- if [ ! -f $phpConfFile ];then
- comprobarError $? 4 "$phpConfFile"
- fi
- cp -f $phpConfFile $phpDest 2>/dev/null
- comprobarError $? 305
-
- chown -R $webServerUser:$webServerGroup /var/lib/php/
- comprobarError $? 305
- fi
- unset phpConfFile phpDest
- }
- establecerMaxUpload() {
- control=false
- error=""
- while [ $control = false ];do
- 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)
- comprobarError $? 1
- if [ -z "$maxUpload2" ];then
- error="ERROR: NO PUEDES DEJAR ESTE PARÁMETRO VACIO.\n"
- else
- control=true
- fi
- done
- maxUpload=$maxUpload2
- unset control maxUpload2
- }
- instalarLetsEncrypt() {
-
- which certbot > /dev/null 2>&1
- if [ $? -ne 0 ];then
-
- curl -o ./var/certbot https://dl.eff.org/certbot-auto 2>/dev/null
- comprobarError $? 401
- chmod 755 ./var/certbot 2>/dev/null
- comprobarError $? 401
- cp -f ./var/certbot /usr/bin/certbot 2>/dev/null
- comprobarError $? 401
-
- echo -en "# /etc/cron.d/certbot: certbot autorenew the certificates twice a day\n" > /etc/cron.d/certbot
- echo -en "SHELL=/bin/sh\n" >> /etc/cron.d/certbot
- echo -en "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n\n" >> /etc/cron.d/certbot
- echo -en "# Job start twice per day (4am & 2pm) in a random minute" >> /etc/cron.d/certbot
- echo -en "0 4,14 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew\n" >> /etc/cron.d/certbot
- fi
- }
- generarCertLetsEncrypt() {
- dominios=""
- if [ $apacheOn = true ];then
-
- if [ $mediaWikiOn = true ];then
- if [ ! -z "$aliasMediaWiki" ];then
- dominios=$dominioMediaWiki$(echo "$aliasMediaWiki" | sed -e 's/ /,/g')
- else
- dominios=$dominioMediaWiki
- fi
- certbot -n --agree-tos --email "admin@$hostname" --apache --domains "$dominios" >> $logFile 2>&1
- comprobarError $? 404
- fi
- if [ $moodleOn = true ];then
- certbot -n --agree-tos --email "admin@$hostname" --apache --domains "$dominioMoodle" >> $logFile 2>&1
- comprobarError $? 404
- fi
- elif [ $nginxOn = true ];then
-
- if [ $mediaWikiOn = true ];then
- if [ ! -z "$aliasMediaWiki" ];then
- dominios=$dominioMediaWiki$(echo "$aliasMediaWiki" | sed -e 's/ /,/g')
- else
- dominios=$dominioMediaWiki
- fi
- certbot -n --agree-tos --email "admin@$hostname" --nginx --domains "$dominios" >> $logFile 2>&1
- comprobarError $? 404
- fi
- if [ $moodleOn = true ];then
- certbot -n --agree-tos --email "admin@$hostname" --nginx --domains "$dominioMoodle" >> $logFile 2>&1
- comprobarError $? 404
- fi
- else
- comprobarError 1 404
- fi
- unset dominios
- }
- generarCertAutofirmado() {
- dominio=$1
- sslDir="/etc/$webServerName/ssl"
- keyFile="$sslDir/$dominio.key"
- reqFile="$sslDir/$dominio.csr"
- certFile="$sslDir/$dominio.crt"
- dhParamFile="$sslDir/dhparam.pem"
- if [ ! -d "$sslDir" ];then
- mkdir "$sslDir" 2>/dev/null
- comprobarError $? 5 "$sslDir"
- fi
-
- openssl genrsa -out "$keyFile" 2048 >/dev/null 2>&1
- comprobarError $? 402
-
- echo -en "ES\nMadrid\nMadrid\n$dominio\n$dominio\n$dominio\nadmin@$dominio\n\n\n" | openssl req -new -key "$keyFile" -out "$reqFile" >/dev/null 2>&1
- comprobarError $? 402
-
- openssl x509 -req -days 730 -in "$reqFile" -signkey "$keyFile" -out "$certFile" >/dev/null 2>&1
- comprobarError $? 402
-
- rm -f $reqFile
- comprobarError $? 402
-
- if [ -f "$dhParamFile" ];then
- cat "$dhParamFile" >> $certFile
- comprobarError $? 402
- fi
-
- chmod 644 $certFile
- comprobarError $? 402
- chmod 400 $keyFile
- comprobarError $? 402
- unset dominio sslDir keyFile reqFile certFile dhParamFile
- }
- generarDHParam() {
- sslDir="/etc/$webServerName/ssl"
- dhParamFile="$sslDir/dhparam.pem"
- nginxConfFile="/etc/$webServerName/nginx.conf"
- if [ ! -d "$sslDir" ];then
- mkdir "$sslDir" 2>/dev/null
- comprobarError $? 5 "$sslDir"
- fi
- openssl dhparam -out "$dhParamFile" 2048 >/dev/null 2>&1
- comprobarError $? 403
-
- if [ $nginxOn = true ];then
- sed -i '/ssl_param /c\\tssl_dhparam '$dhParamFile';' $nginxConfFile
- comprobarError $? 403
- fi
- unset sslDir dhParamFile nginxConfFile
- }
- habilitarServicio() {
-
-
- if [ $# -le 0 ];then
- comprobarError 1 900
- fi
- which systemctl > /dev/null 2>&1
- if [ $? -eq 0 ]; then
-
- systemctl start $1 > /dev/null 2>&1
- comprobarError $? 901 $1
- systemctl enable $1 > /dev/null 2>&1
- comprobarError $? 902 $1
- else
-
- which service > /dev/null 2>&1
- if [ $? -eq 0 ]; then
-
- service $1 start > /dev/null 2>&1
- comprobarError $? 901 $1
- else
-
-
- /etc/init.d/$1 start > /dev/null 2>&1
- comprobarError $? 901 $1
- fi
-
- which update-rc.d > /dev/null 2>&1
- if [ $? -eq 0 ];then
- update-rc.d $1 enable
- comprobarError $? 902 $1
- else
-
- which chkconfig > /dev/null 2>&1
- if [ $? -eq 0 ];then
- chkconfig $1 on
- comprobarError $? 902 $1
- else
-
- comprobarError 1 902 $1
- fi
- fi
- fi
-
-
- }
- deshabilitarServicio() {
-
-
- if [ $# -le 0 ];then
- comprobarError 1 903
- fi
- which systemctl > /dev/null 2>&1
- if [ $? -eq 0 ]; then
-
- systemctl stop $1 > /dev/null 2>&1
- comprobarError $? 904 $1
- systemctl disable $1 > /dev/null 2>&1
- comprobarError $? 905 $1
- else
-
- which service > /dev/null 2>&1
- if [ $? -eq 0 ]; then
-
- service $1 stop > /dev/null 2>&1
- comprobarError $? 904 $1
- else
-
-
- /etc/init.d/$1 stop > /dev/null 2>&1
- comprobarError $? 904 $1
- fi
-
- which update-rc.d > /dev/null 2>&1
- if [ $? -eq 0 ];then
- update-rc.d $1 disable
- comprobarError $? 905 $1
- else
-
- which chkconfig > /dev/null 2>&1
- if [ $? -eq 0 ];then
- chkconfig $1 off
- comprobarError $? 905 $1
- else
-
- comprobarError 1 905 $1
- fi
- fi
- fi
-
-
- }
- recargarServicio() {
-
-
- if [ $# -le 0 ];then
- comprobarError 1 912
- fi
- which systemctl > /dev/null 2>&1
- if [ $? -eq 0 ]; then
-
- systemctl reload $1 > /dev/null 2>&1
- comprobarError $? 913 $1
- else
-
- which service > /dev/null 2>&1
- if [ $? -eq 0 ]; then
-
- service $1 reload > /dev/null 2>&1
- comprobarError $? 913 $1
- else
-
-
- /etc/init.d/$1 reload > /dev/null 2>&1
- comprobarError $? 913 $1
- fi
- fi
-
-
- }
- configurarCortafuegos() {
-
- esSSH $PPID
- if [ $debianOS = true ];then
- ufw allow 80/tcp >> $logFile 2>&1
- comprobarError $? 906 "80/tcp"
- if [ $sshControl = true ];then
- ufw allow 22/tcp >> $logFile 2>&1
- comprobarError $? 906 "22/tcp"
- fi
- if [ $sslOn = true ];then
- ufw allow 443/tcp >> $logFile 2>&1
- comprobarError $? 906 "443/tcp"
- fi
- ufw --force enable >> $logFile 2>&1
- comprobarError $? 907
- elif [ $rhelOS = true ];then
- firewall-cmd --add-port=80/tcp >> $logFile 2>&1
- comprobarError $? 906 "80/tcp"
- if [ $sshControl = true ];then
- firewall-cmd --add-port=22/tcp >> $logFile 2>&1
- comprobarError $? 906 "22/tcp"
- fi
- if [ $sslOn = true ];then
- firewall-cmd --add-port=443/tcp >> $logFile 2>&1
- comprobarError $? 906 "443/tcp"
- fi
- firewall-cmd --runtime-to-permanent >> $logFile 2>&1
- comprobarError $? 907
- habilitarServicio firewalld >> $logFile 2>&1
- comprobarError $? 907
- fi
- unset sshControl
- }
- esSSH() {
- p=${1:-$PPID}
-
- read pid name ppid < <( ps -o pid= -o comm= -o ppid= -p $p)
- [[ "$name" =~ sshd ]] && { sshControl=true; return 0; }
- [ "$ppid" -le 1 ] && { sshControl=false; return 1; }
- esSSH $ppid
- }
- descargarMediaWiki() {
- if [ ! -d ./var ];then
- comprobarError 1 5 "./var"
- fi
- curl "https://releases.wikimedia.org/mediawiki/1.31/mediawiki-1.31.0.tar.gz" 2>/dev/null | tar -xz -C "./var/"
- comprobarError $? 501
- }
- configurarMediaWiki() {
- if [ ! -f /var/www/$dominioMediaWiki/LocalSettings.php ];then
-
- cp -fR ./var/mediawiki-1.31.0/ /var/www/$dominioMediaWiki
- comprobarError $? 502
-
- nombreDBMW=$(echo $dominioMediaWiki | sed -e 's/\./_/g' | sed -e 's/-/_/g')
- userDBMW=$(echo "mediawiki_user" | sed -e 's/\./_/g' | sed -e 's/-/_/g')
- php /var/www/$dominioMediaWiki/maintenance/install.php --dbname=$nombreDBMW --dbserver="localhost" --installdbuser=root --installdbpass=$sqlPasswd --dbuser=$userDBMW --dbpass=$sqlPasswd --scriptpath="" --lang=es --pass=$passwdMediaWiki --with-extensions "$nombreMediaWiki" "admin" >> $logFile 2>&1
- comprobarError $? 502
-
- sed -i '/$wgLanguageCode =/c\$wgLanguageCode = "es";' /var/www/$dominioMediaWiki/LocalSettings.php
- comprobarError $? 502
- sed -i '/$wgEnableEmail =/c\$wgEnableEmail = false;' /var/www/$dominioMediaWiki/LocalSettings.php
- comprobarError $? 502
- sed -i '/$wgEnableUploads =/c\$wgEnableUploads = true;' /var/www/$dominioMediaWiki/LocalSettings.php
- comprobarError $? 502
- echo -en "\$wgArticlePath = \"/wiki/\$1\";\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
- echo -en "\$wgUsePathInfo = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
- echo -en "\$wgGroupPermissions['*']['createaccount'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
- echo -en "\$wgGroupPermissions['*']['edit'] = false;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
- echo -en "\$wgGroupPermissions['*']['read'] = true;\n" >> /var/www/$dominioMediaWiki/LocalSettings.php
-
- chown -R $webServerUser:$webServerGroup /var/www/$dominioMediaWiki
- comprobarError $? 502
-
- if [ $apacheOn = true ] && [ $sslOn = false ];then
- virtualHost="./etc/apache2/sites-available/mediawiki.conf"
- elif [ $nginxOn = true ] && [ $sslOn = false ];then
- virtualHost="./etc/nginx/sites-available/mediawiki.conf"
- elif [ $apacheOn = true ] && [ $sslOn = true ];then
- virtualHost="./etc/apache2/sites-available/mediawiki-ssl.conf"
- elif [ $nginxOn = true ] && [ $sslOn = true ];then
- virtualHost="./etc/nginx/sites-available/mediawiki-ssl.conf"
- else
- comprobarError 1 502
- fi
- if [ ! -f $virtualHost ];then
- comprobarError $? 502
- fi
- instalarVirtualHost "/var/www/$dominioMediaWiki" $virtualHost $dominioMediaWiki $aliasMediaWiki
- unset virtualHost
- else
- comprobarError 1 503 $dominioMediaWiki
- fi
- }
- descargarMoodle() {
- if [ ! -d ./var ];then
- comprobarError 1 5 "./var"
- fi
-
-
- curl "https://download.moodle.org/download.php/direct/stable35/moodle-latest-35.tgz" 2>/dev/null | tar -xz -C "./var/"
- comprobarError $? 501
-
- }
- configurarMoodle() {
- if [ ! -f /var/www/$dominioMoodle/config.php ];then
-
- cp -Rf ./var/moodle/ /var/www/$dominioMoodle
- comprobarError $? 602
-
- if [ ! -d /var/www/moodledata ];then
- mkdir /var/www/moodledata 2>/dev/null
- comprobarError $? 602
- fi
-
- perm=$(stat -c %a /var/www/moodledata)
- if [ $perm -ne 777 ];then
- chmod -R 777 /var/www/moodledata 2>/dev/null
- comprobarError $? 602
- fi
- perm=$(stat -c %U /var/www/moodledata)
- if [ $perm != "$webServerUser" ];then
- chown -R $webServerUser:$webServerGroup /var/www/moodledata 2>/dev/null
- comprobarError $? 602
- fi
- unset perm
-
- nombreDBMo=$(echo $dominioMoodle | sed -e 's/\./_/g' | sed -e 's/-/_/g')
- userDBMo=$(echo "moodle_user" | sed -e 's/\./_/g' | sed -e 's/-/_/g')
- crearDBMoodle
-
- if [ $sslOn = true ];then
- wwwroot="https://$dominioMoodle"
- else
- wwwroot="http://$dominioMoodle"
- fi
- if [ $mySQLOn = true ];then
- dbtype="mysqli"
- elif [ $mariaDBOn = true ];then
- dbtype="mariadb"
- else
- comprobarError 1 602
- fi
- php /var/www/$dominioMoodle/admin/cli/install.php --lang=es --wwwroot="$wwwroot" --dataroot="/var/www/moodledata" --dbtype="$dbtype" --dbname="$nombreDBMo" --dbuser="$userDBMo" --dbpass="$sqlPasswd" --fullname="$nombreMoodle" --shortname="$nombreCortoMoodle" --adminuser=admin --adminpass="$passwdMoodle" --adminemail="admin@$dominioMoodle" --agree-license --non-interactive >>$logFile 2>&1
- comprobarError $? 602
-
- chown -R $webServerUser:$webServerGroup /var/www/$dominioMoodle /var/www/moodledata
-
- if [ $rhelOS = true ];then
- configurarSELinux
- fi
-
- if [ $apacheOn = true ] && [ $sslOn = false ];then
- virtualHost="./etc/apache2/sites-available/moodle.conf"
- elif [ $nginxOn = true ] && [ $sslOn = false ];then
- virtualHost="./etc/nginx/sites-available/moodle.conf"
- elif [ $apacheOn = true ] && [ $sslOn = true ];then
- virtualHost="./etc/apache2/sites-available/moodle-ssl.conf"
- elif [ $nginxOn = true ] && [ $sslOn = true ];then
- virtualHost="./etc/nginx/sites-available/moodle-ssl.conf"
- else
- comprobarError 1 602
- fi
- instalarVirtualHost "/var/www/$dominioMoodle" $virtualHost $dominioMoodle
- unset virtualHost wwwroot dbtype
- else
- comprobarError 1 603 $dominioMoodle
- fi
- }
- crearDBMoodle() {
- dbDir="./etc/db"
- if [ ! -d $dbDir ];then
- mkdir $dbDir 2>/dev/null
- comprobarError $? 603
- fi
- dbFile=$dbDir"/moodle.sql"
- echo -en "CREATE DATABASE IF NOT EXISTS $nombreDBMo DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\n" > $dbFile
- echo -en "GRANT ALL PRIVILEGES ON $nombreDBMo.* TO '$userDBMo'@'localhost' IDENTIFIED BY '$sqlPasswd';\n" >> $dbFile
- mysql -u root --password=$sqlPasswd < $dbFile > /dev/null 2>&1
- control=$?
- rm -f $dbFile 2>/dev/null
- comprobarError $? 603
- comprobarError $control 603
- unset control dbFile dbDir
- }
- configurarSELinux() {
- which semanage >/dev/null 2>&1
- if [ $? -ne 0 ];then
- case $ID in
- centos)
- result=$(yum -y install policycoreutils-python 2>&1)
- comprobarError $? 605 $result
- ;;
- fedora)
- result=$(yum -y install policycoreutils-python-utils 2>&1)
- comprobarError $? 605 $result
- ;;
- *)
- comprobarError 1 604
- ;;
- esac
- fi
- semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/moodledata(/.*)?" > /dev/null 2>&1
-
- restorecon -R /var/www/ > /dev/null 2>&1
- comprobarError $? 604
- }
- instalarPHPInfo() {
- if [ ! -f /etc/$webServerName/sites-enabled/phpinfo.conf ];then
- infoFile="./var/www/info.php"
- if [ ! -f $infoFile ];then
- comprobarError 1 4 "$infoFile"
- fi
- mkdir /var/www/localhost 2>/dev/null
- comprobarError $? 106
- cp -f $infoFile /var/www/localhost/ 2>/dev/null
- comprobarError $? 106
- chown -R $webServerUser:$webServerGroup /var/www/localhost 2>/dev/null
- comprobarError $? 106
- unset infoFile
-
- if [ $apacheOn = true ] && [ $sslOn = false ];then
- virtualHost="./etc/apache2/sites-available/phpinfo.conf"
- elif [ $nginxOn = true ] && [ $sslOn = false ];then
- virtualHost="./etc/nginx/sites-available/phpinfo.conf"
- elif [ $apacheOn = true ] && [ $sslOn = true ];then
- virtualHost="./etc/apache2/sites-available/phpinfo-ssl.conf"
- elif [ $nginxOn = true ] && [ $sslOn = true ];then
- virtualHost="./etc/nginx/sites-available/phpinfo-ssl.conf"
- else
- comprobarError 1 106
- fi
- instalarVirtualHost "/var/www/localhost" $virtualHost "localhost"
- unset virtualHost
- return 0
- else
- return 1
- fi
- }
- configurarBackups() {
- letsEncryptCode=""
- if [ ! -d "./var" ];then
- comprobarError 1 5 "./var"
- fi
- which backup-server > /dev/null 2>&1
- if [ $? -ne 0 ];then
-
- curl "https://code.castanedo.es/guzman/backup-server/archive/2.1.tar.gz" 2>/dev/null | tar -xz -C "./var/"
- if [ $? -ne 0 ];then
- comprobarError 1 701
- return 1
- fi
-
- cp -f ./var/backup-server/backup-server /usr/bin/backup-server
- if [ $? -ne 0 ];then
- comprobarError 1 701
- return 1
- fi
- cp -f ./var/backup-server/scripts/logrotate.d/backup-server /etc/logrotate.d/backup-server
- if [ $? -ne 0 ];then
- comprobarError 1 701
- return 1
- fi
-
- if [ ! -d /var/backup ];then
- mkdir /var/backup 2>/dev/null
- comprobarError $? 5 "/var/backup"
- fi
-
- if [ $letsEncryptOn = false ];then
- letsEncryptCode="--no-letsencrypt "
- fi
- echo -en "# /etc/cron.d/backup-server: crontab for $hostname\n\n" > /etc/cron.d/backup-server
- echo -en "# Backup every day at 4:00 am\n" >> /etc/cron.d/backup-server
- echo -en "0 4 * * * root [ -x /usr/bin/backup-server ] && /usr/bin/backup-server --xz -u $webServerUser -g $webServerGroup --no-encryption --sql-user root --sql-pass $sqlPasswd --nginx-dir /etc/$webServerName $letsEncryptCode--no-mail --no-gogs --no-postfix --no-dovecot --no-opendkim --no-spf --no-opendmarc --no-amavis --no-spamassassin /var/backup >> /var/log/backup-server.log 2>&1" >> /etc/cron.d/backup-server
- comprobarError $? 701
- fi
- unset letsEncryptCode
- }
- horaInicial=$(date +"%s")
- inicializarVariables
- comprobarRoot
- OSInfo
- comprobarDependencias
- mostrarBienvenida
-
- mostrarExpress
- if [ $apacheOn = true ]; then
- echo -en "Instalando Servidor Web Apache..." | tee -a $logFile
- instalarApache
- echo -en " OK.\n" | tee -a $logFile
- elif [ $nginxOn = true ]; then
- echo -en "Instalando Servidor Web Nginx..." | tee -a $logFile
- instalarNginx
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $mySQLOn = true ]; then
- echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
- instalarMySQL
- echo -en " OK.\n" | tee -a $logFile
- elif [ $mariaDBOn = true ]; then
- echo -en "Instalando Base de Datos MariaDB..." | tee -a $logFile
- instalarMariaDB
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $phpOn = true ]; then
- echo -en "Instalando PHP-7..." | tee -a $logFile
- instalarPHP
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $letsEncryptOn = true ];then
- echo -en "Instalando Let's Encrypt..." | tee -a $logfile
- instalarLetsEncrypt
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $apacheOn = true ];then
- echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
- configurarApache
- echo -en " OK.\n" | tee -a $logFile
- elif [ $nginxOn = true ]; then
- echo -en "Configurando Servidor Web Nginx..." | tee -a $logFile
- configurarNginx
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
- echo -en "Configurando Base de Datos..." | tee -a $logFile
- configurarSQL
- echo -en " OK.\n" | tee -a $logFile
- habilitarServicio "$sqlServerName"
- echo -en "Estableciendo contraseña de la Base de Datos..." | tee -a $logFile
- establecerSQLPasswd
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $phpOn = true ];then
- echo -en "Configurando PHP-7..." | tee -a $logFile
- configurarPHP
- echo -en " OK.\n" | tee -a $logFile
- fi
-
- if [ $sslOn = true ];then
- echo -en "Generando claves de intercambio Diffie-Hellman (puede llevar un largo tiempo)..." | tee -a $logFile
- generarDHParam
- echo -en " OK.\n" | tee -a $logFile
- echo -en "Generando Certificados Auto-Firmados..." | tee -a $logFile
- if [ $mediaWikiOn = true ];then
- generarCertAutofirmado $dominioMediaWiki
- fi
- if [ $moodleOn = true ];then
- generarCertAutofirmado $dominioMoodle
- fi
- if [ $infoPHPOn = true ];then
- generarCertAutofirmado "localhost"
- fi
- echo -en " OK.\n" | tee -a $logFile
- fi
- echo -en "Habilitando todos los servicios..." | tee -a $logFile
- if [ $apacheOn = true ] || [ $nginxOn = true ];then
- habilitarServicio $webServerName
- fi
- if [ $nginxOn = true ] && [ $phpOn = true ];then
- habilitarServicio $phpFPMName
- fi
- echo -en " OK.\n" | tee -a $logFile
- if [ $mediaWikiOn = true ]; then
-
- echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
- descargarMediaWiki
- echo -en " OK.\n" | tee -a $logFile
-
- echo -en "Configurando MediaWiki..." | tee -a $logFile
- configurarMediaWiki
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $moodleOn = true ]; then
-
- echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
- descargarMoodle
- echo -en " OK.\n" | tee -a $logFile
-
- echo -en "Configurando Moodle (puede llevar un tiempo largo)..." | tee -a $logFile
- configurarMoodle
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $infoPHPOn = true ];then
- echo -en "Configurando 'info.php'..." | tee -a $logFile
- instalarPHPInfo
- if [ $? -eq 0 ];then
- echo -en " OK.\n" | tee -a $logFile
- else
- echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
- fi
- fi
- echo -en "Configurando Cortafuegos..." | tee -a $logFile
- configurarCortafuegos
- echo -en " OK.\n" | tee -a $logFile
- if [ $letsEncryptOn = true ];then
- echo -en "Generando Certificados Válidos Let's Encrypt..." | tee -a $logFile
- generarCertLetsEncrypt
- echo -en " OK.\n" | tee -a $logFile
- fi
- if [ $backupOn = true ]; then
- echo -en "Configurando Backup Automático..." | tee -a $logFile
- configurarBackups
- echo -en " OK.\n" | tee -a $logFile
- fi
- horaFinal=$(date +"%s")
- echo -en "\n--------------------------------------------------\n" | tee -a $logFile
- echo -en "\t¡INSTALACION FINALIZADA CON EXITO! \n" | tee -a $logFile
- echo -en "\tDuración: "$((horaFinal-horaInicial))" seg." | tee -a $logFile
- echo -en "\n--------------------------------------------------\n" | tee -a $logFile
|