#!/bin/bash
#
# prototype script for injecting files into the cloudvm
#
# XXX ideally we'd unify with the ovf parameter methods

for cd_device in /dev/cdrom*; do
    # first check if the cd is readable, because mount takes 15 seconds to fail
    if isosize $cd_device &> /dev/null; then
        echo "Mounting $cd_device"
        umask 077
        mkdir -p /mnt/cdrom
        if mount $cd_device /mnt/cdrom -t iso9660; then
            if test -e /mnt/cdrom/settings.json; then
                echo "Copying files from /mnt/cdrom to /var/install"
                mkdir -p /var/install
                cp -ra /mnt/cdrom/* /var/install/
                umount /mnt/cdrom
                echo "Done"
                break
            else
                umount /mnt/cdrom
                echo "No settings.json found on CD, skipping..."
            fi
        fi
    else
        echo "No CD found in $cd_device"
    fi
done
