#!/usr/bin/sh

# Generated seed image for cloud-utils.
# Copyright (C) 2015 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


export tempdir

die ()
{
    echo >&2 "$*"
    exit 1
}

test -z "$tempdir" && die "no \$tempdir variable"
echo >&2 "using $tempdir"

ssh_key=$(cat "$HOME/.ssh/id_rsa.pub")
test -z "$ssh_key" && die "no ssh key in ~/.ssh/id_rsa.pub?"

dir="$tempdir"/cloud-seed
mkdir -p "$dir/files" || die "can't create $dir"

cat >"$dir/files/meta-data" <<EOF
# this is yaml formated data

instance-id: test-instance
local-hostname: test-instance

hostname: test-hostname

public-keys:
  ec2-keypair.us-east-1: [$ssh_key
      ec2-keypair.us-east-1, '']
EOF
test $? -eq 0 || die "can't create meta-data"

cat >"$dir/files/user-data" <<EOF
EOF
test $? -eq 0 || die "can't create meta-data"

virt-make-fs --label=test-data "$dir/files" "$dir/basic.img"
