oginstaller/provision_ogcore.sh

73 lines
2.9 KiB
Bash

#!/bin/bash
#
set -x
cd /opt/opengnsys/ogCore/repo/
# Preparar el fichero .yaml
CONF_DIR=/opt/opengnsys/ogCore/etc/
mkdir -p $CONF_DIR
# Copiar el fichero de configuración a CONF_DIR
cp docker-compose-deploy.yml $CONF_DIR/
if [ -f /opt/opengnsys/ogCore/installer/.deployed ]; then
echo "ogCore ya instalado"
exit 0
fi
CONF_DIR=/opt/opengnsys/ogCore/etc/
containers="ogcore-database ogcore-php gcore-nginx"
while true ; do
all_running=true
for container in $containers; do
if ! docker compose -f $CONF_DIR/docker-compose-deploy.yml ps --format json |jq -r '"\(.Name) \(.State)"' |grep -q "$container running"
then
echo "El contenedor $container no está corriendo"
all_running=false
fi
done
if $all_running; then
echo "Todos los contenedores están corriendo"
break
fi
sleep 5
done
# while ! docker compose -f $CONF_DIR/docker-compose-deploy.yml ps --format json |jq -r '"\(.Name) \(.State)"' |grep -q 'ogcore-php running'; do
# sleep 2
# done
sleep 5
adminuser=$(jq -r '.username' /opt/opengnsys/ogCore/installer/config.json)
adminpass=$(jq -r '.password' /opt/opengnsys/ogCore/installer/config.json)
docker compose -f $CONF_DIR/docker-compose-deploy.yml exec php composer install
docker compose -f $CONF_DIR/docker-compose-deploy.yml exec php php bin/console lexik:jwt:generate-keypair --overwrite
docker compose -f $CONF_DIR/docker-compose-deploy.yml exec php php bin/console doctrine:migrations:migrate --no-interaction
## TODO we need to feed $adminuser and $adminpass to doctrine:fixtures:load somehow
docker compose -f $CONF_DIR/docker-compose-deploy.yml exec php php bin/console doctrine:fixtures:load --no-interaction
# Provision user admin
bearer=$(curl -k -X 'POST' 'https://localhost:8443/auth/login' -H 'accept: application/json' -H 'Content-Type: application/json' -d "{ \"username\": \"ogadmin\", \"password\": \"12345678\" }" | jq .token | sed 's/"//g' )
if [ $adminuser == "ogadmin" ]; then
echo "Cambiando password a ogadmin no puede ser el usuario administrador"
ogadmin_uuid=$(curl -f -q -k -L https://localhost:8443/users/?username=ogadmin -H 'accept: application/json' -H "Authorization: Bearer $bearer" | jq .[0].uuid | sed 's/"//g')
curl -f -k -L -X PUT "https://localhost:8443/users/$ogadmin_uuid/reset-password" -H 'accept: application/ld+json' -H 'Content-Type: application/ld+json' -d "{\"currentPassword\": \"12345678\", \"newPassword\": \"$adminpass\", \"repeatNewPassword\": \"$adminpass\"}" -H "Authorization: Bearer $bearer"
touch /opt/opengnsys/ogCore/installer/.deployed
exit 0
fi
curl -k -L -f --location 'https://localhost:8443/users' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $bearer" \
--data "{ \"username\": \"$adminuser\", \"password\": \"$adminpass\", \"roles\": [\"ROLE_SUPER_ADMIN\"] }"
touch /opt/opengnsys/ogCore/installer/.deployed
exit 0