51 lines
2.3 KiB
Bash
51 lines
2.3 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
|
|
|
|
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
|
|
|
|
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 -q -k -L https://localhost:8443/users/?username=ogadmin -H 'accept: application/json' -H "Authorization: Bearer $bearer" | jq .[0].uuid | sed 's/"//g')
|
|
curl -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"
|
|
exit 0
|
|
fi
|
|
|
|
curl -k -L --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
|