#!/bin/sh

# Copyright (c) 2018 - 2023 Jolla Ltd.
#
# License: Jolla Proprietary

BASE_INSTALL_PATH="$(appsupport-config --base)"
source "$BASE_INSTALL_PATH/init/appsupport-common"
appsupport_init_source $1

if [ ! -f "$(appsupport-config --config $CONFIG_INSTANCE)" ]; then
    echo "No container found: $INSTANCE_NAME"
    exit 1
fi

appsupport-attach $CONFIG_INSTANCE /system/bin/reboot -p

appsupport_run_hook_scripts "stop-hook.d"

echo "Waiting for container to exit."
while appsupport-info $CONFIG_INSTANCE --running; do
    sleep 1
done

exit 0
