How to start Quickinstall from Bash when necessary?

Hi. We are developing a complete Docker-Image for our customer using Plone 5. It is using RelStorage with an Oracle database located in their infrastructure.
After we created a new version of our add-ons we create the docker image and the database remains unchanged. Now it can happen that we have to create a new index or metadata attribute in the catalog for the new version which is used directly by some templates. When the newly created container is started this template runs into an error because nobody clicked "Reinstall" in portal_quickinstaller to create the missing metadata or index in the catalog. How could I check what the current version of our add-on in the database is and if I have to do a quickinstall before doing anything else and then run it from bash?

It should work somehow like this:

  1. docker run our-plone ....
  2. run.sh inside the docker container gets executed
  3. run.sh checks what the version of our add-on in the current database is.
  4. run.sh starts the instance.
  5. run.sh decides if it has to run quickinstall and does it when necessary.
  6. All new catalog indexes and metadata are now available. Plone can be used normally.
  7. run.sh waits until the instance dies.