#!/bin/bash
# Workaround for cloud-init bug https://bugs.launchpad.net/cloud-init/+bug/1263294

set -eux

ephemeraldisk=$(os-apply-config --key block-device-mapping.ephemeral0 --type raw --key-default '')
[ -n "$ephemeraldisk" ] || exit 0

if grep -q "^$ephemeraldisk " /proc/mounts ; then
    if ! grep -q "^$ephemeraldisk /mnt" /proc/mounts ; then
        echo ERROR: ephemeral0 $ephemeraldisk is mounted but not at /mnt
        echo ERROR: aborting so state is not stored on the image disk
        exit 1
    fi
    exit 0
fi

mount $ephemeraldisk /mnt
