#!/usr/bin/env bash ################################################################# # COLORS BOLD="\e[1m" RED="\033[0;31m" GREEN="\033[0;32m" BLUE="\033[0;34m" NOCOLOR="\033[0m" ################################################################### ROOT=$(id -u) if [ "$ROOT" != "0" ]; then echo -e "${RED} Este comando debe ejecutarse como root.${NOCOLOR}" exit 0 fi ################################################################### DEVELOP=0 CLIENT="" HELP=0 ANSIBLE=0 for VAR in "$@" do KEY="$(cut -d'=' -f1 <<<"$VAR")" VALUE="$(cut -d'=' -f2 <<<"$VAR")" if [ "$KEY" = "--help" ] || [ "$VAR" = "-h" ]; then HELP=1 fi if [ "$KEY" = "--ansible" ]; then ANSIBLE=1 fi if [ "$KEY" = "--cliente" ]; then CLIENT=${VALUE} fi done if [ "$HELP" = "1" ]; then echo -e "Comando para instalar flowdat." echo -e "Si no se pasan parametros se ejecuta el script completo preguntando los datos necesarios" echo -e "Parametros:" echo -e " --cliente Nombre del cliente que va a instalar. Se utiliza como dominio. NUNCA UTILIZAR EN CLIENTES." echo -e " --ansible Ejecuta la linea del ansible. Debe pasar el directorio donde se encuentra el playbook." exit 1 fi ################################################################### fcGetYesNo() { while true; do read VALUEYESNO if [ "$VALUEYESNO" = "" ] || [ "$VALUEYESNO" = "y" ] || [ "$VALUEYESNO" = "Y" ] || [ "$VALUEYESNO" = "yes" ] || [ "$VALUEYESNO" = "YES" ]; then VALUEYESNO=1 return fi if [ "$VALUEYESNO" = "n" ] || [ "$VALUEYESNO" = "N" ] || [ "$VALUEYESNO" = "no" ] || [ "$VALUEYESNO" = "NO" ]; then VALUEYESNO=0 return fi done } fcCheckExecution () { if [ $? -eq 0 ]; then return else echo -e "${RED}Algunos comandos no se ejecutaron correctamente.${NOCOLOR}" exit 0 fi } ################################################################### DIRINSTALLDEFAULT="/opt/flowdat" FILEANSIBLE="#!/bin/bash\neval \$(cat mysql.host.env running.env) ansible-playbook -i inventory.ini -u root playbook.yml " ################################################################### DIRINSTALL=${DIRINSTALLDEFAULT} echo -e "Ingrese el directorio absoluto de instalacion: (default: ${BOLD}${DIRINSTALLDEFAULT}${NOCOLOR})" read DIRINSTALL if [ "${DIRINSTALL}" = "" ]; then DIRINSTALL=${DIRINSTALLDEFAULT} fi cd ${DIRINSTALL} if [ "$ANSIBLE" = "0" ]; then echo -e "" echo -e "" echo -e "" echo -e "" echo -e "${BLUE}###############################################################${NOCOLOR}" echo -e "Parando las imagenes actuales" docker stop $(docker ps -q) ################################################################### if [ "$CLIENT" = "" ]; then echo -e "Ingrese el nombre del cliente para la instalacion. Ej.: ${BOLD}galvez${NOCOLOR}" read CLIENTNAME else CLIENTNAME=${CLIENT} fi DOMAINNAME="flowdat.net" echo -e "" echo -e "" echo -e "Las url seran ${GREEN}base.${CLIENTNAME}.${DOMAINNAME}${NOCOLOR}. Si esto NO es correcto aborte la ejecucion con ctrl+c" echo -e "" echo -e "" echo -e "${BLUE}###############################################################${NOCOLOR}" echo -e "Ingresando al directorio ${BOLD}${DIRINSTALL}${NOCOLOR}" cd ${DIRINSTALL} fcCheckExecution ################################################################### BRANCH="" echo -e "Ingrese la rama a instalar. (default: ${BOLD}latest${NOCOLOR})" read BRANCH if [ "$BRANCH" = "" ]; then BRANCH="latest" fi fcCheckExecution ################################################################### DOCKERIMAGEINSTALLERBASE="docker.infra.flowdat.com/fd3/installer:$BRANCH" DOCKERIMAGEINSTALLER="dind" DOCKERMAKEINSTALL="docker run -it -v ${DIRINSTALL}:${DIRINSTALL} -v /var/run/docker.sock:/tmp/docker.sock ${DOCKERIMAGEINSTALLER} make:updateImages ${DIRINSTALL} --client=${CLIENTNAME} --domain=${DOMAINNAME} --branch=${BRANCH} --develop=${DEVELOP}" DOCKERFIXNGINX="docker run -it -v ${DIRINSTALL}:${DIRINSTALL} -v /var/run/docker.sock:/tmp/docker.sock ${DOCKERIMAGEINSTALLER} fix:nginx ${DIRINSTALL}" ################################################################### docker pull ${DOCKERIMAGEINSTALLERBASE} docker tag ${DOCKERIMAGEINSTALLERBASE} ${DOCKERIMAGEINSTALLER} ################################################################### echo -e "${BLUE}###############################################################${NOCOLOR}" echo -e "Creando los archivos de instalacion." COMMAND="" eval ${DOCKERMAKEINSTALL} fcCheckExecution fi ################################################################### echo -e "" echo -e "" echo -e "" echo -e "" echo -e "${BLUE}###############################################################${NOCOLOR}" echo -e "Ejecutando el ansible" echo -e "${FILEANSIBLE}" > ${DIRINSTALL}/ansible.run docker run -it -v ${DIRINSTALL}:${DIRINSTALL} -v /var/run/docker.sock:/tmp/docker.sock dind ansible ${DIRINSTALL} echo -e "Borrando las imagenes que no se necesitandb." docker system prune -f fcCheckExecution exit 1