diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index 9e98638..b83ab12 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -8,6 +8,9 @@ USER="opengnsys" # Detectar si es una instalación nueva o una actualización if [ "$1" = "configure" ] && [ -z "$2" ]; then + # Detectar IP de la interfaz de red asociad a la ruta por defecto. + + IP=$(ip -4 route get 8.8.8.8 | grep -oP '(?<=src )[\d.]+') echo ">>> Instalación nueva detectada." # Solicitar credenciales solo en instalación nueva @@ -54,29 +57,31 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then systemctl restart og-mercure systemctl restart nginx systemctl restart php8.3-fpm + + #Obteniendo bearer token + BEARER=$(curl -sk -X 'POST' 'https://localhost:8443/auth/login' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -d '{ "username": "ogadmin", "password": "12345678" }' | jq -r .token) + # Creando nuevo repo + curl -skL -X POST 'https://localhost:8443/image-repositories' \ + -H "Authorization: Bearer $BEARER" \ + -H 'Content-Type: application/json' \ + -d "{ \"name\": \"Repository 1\", \"ip\": \"$IP\", \"comments\": \"Repositorio creado automaticamente por oginstaller\" }" # Solo gestionar credenciales en instalación nueva if [ "$ADMIN_USER" == "ogadmin" ]; then - BEARER=$(curl -sk -X 'POST' 'https://localhost:8443/auth/login' \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -d '{ "username": "ogadmin", "password": "12345678" }' | jq -r .token) - - echo ">>> Cambiando contraseña de ogadmin" - + echo ">>> Cambiando contraseña de ogadmin"¡ OGADMIN_UUID=$(curl -skL "https://localhost:8443/users/?username=ogadmin" \ -H 'accept: application/json' \ -H "Authorization: Bearer $BEARER" | jq -r '.[0].uuid') - curl -skL -X PUT "https://localhost:8443/users/$OGADMIN_UUID/reset-password" \ -H 'accept: application/ld+json' \ -H 'Content-Type: application/ld+json' \ -H "Authorization: Bearer $BEARER" \ -d "{ \"currentPassword\": \"12345678\", \"newPassword\": \"$ADMIN_PASS\", \"repeatNewPassword\": \"$ADMIN_PASS\" }" - echo ">>> Contraseña de ogadmin cambiada." else echo ">>> Creando nuevo usuario administrador: $ADMIN_USER" - curl -skL --location 'https://localhost:8443/users' \ --header 'Content-Type: application/json' \ --header "Authorization: Bearer $BEARER" \