Restore snapshot bash script

Hi;

I am attempting to automatically restore a snapshot as part of hassio installation using this snippet:

# Restore backup config and integrations
CONTAINER=$(docker ps | grep hassio-cli | cut -d " " -f1)
SLUG=$(docker exec -it $CONTAINER ha snapshots | grep slug | sed -e 's/  / /g' |  cut -d " " -f3)
docker exec -it $CONTAINER ha snapshots restore $SLUG

Environmental considerations:

  • There is only one snapshot
  • hassio newly installed; by same script. I determine when install / init complete using this method:
# Wait for home-assistant to install and configure itself
while [ ! -f /usr/share/hassio/homeassistant/configuration.yaml ]; do sleep 1; done

Q1: Is there a better (bash, from docker host) method to determine that hassio is installed and has completed init?

Q2: This command fails, despite the fact that variables OK (Error: Snapshot does not exist). Why?
docker exec -it $CONTAINER ha snapshots restore $SLUG
This command succeeds:
docker exec -it $CONTAINER ha snapshots restore <actual slug value>
So, some sort of environment variable eval issue when passing to container / ha

Any suggestions? Better way to achieve this?
Thanks;
Bill