2 ##############################################################################
3 # Copyright (c) 2017 Mirantis Inc. and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 # This will generate a openstack-style config drive image suitable for
11 # use with cloud-init. You may optionally pass in an ssh public key
12 # (using the -k/--ssh-key option) and a user-data blog (using the
13 # -u/--user-data option).
15 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
18 echo "usage: ${0##*/}: [--ssh-key <pubkey>] [--vendor-data <file>] [--user-data <file>] [--hostname <hostname>] <imagename>"
23 --long help,hostname:,ssh-key:,user-data:,vendor-data: -n "${0##*/}" \
26 # shellcheck disable=SC2181
65 if [ "${ssh_key}" ] && [ -f "${ssh_key}" ]; then
66 echo "adding pubkey from ${ssh_key}"
67 ssh_key_data=$(cat "${ssh_key}")
71 if ! [ "${hostname}" ]; then
75 trap 'rm -rf $config_dir' EXIT
76 config_dir=$(mktemp -t -d configXXXXXX)
78 if [ "${user_data}" ] && [ -f "${user_data}" ]; then
79 echo "adding user data from ${user_data}"
80 cp "${user_data}" "${config_dir}/user-data"
82 touch "${config_dir}/user-data"
85 if [ "${vendor_data}" ] && [ -f "${vendor_data}" ]; then
86 echo "adding vendor data from ${vendor_data}"
87 cp "${vendor_data}" "${config_dir}/vendor-data"
90 cat > "${config_dir}/meta-data" <<-EOF
93 local-hostname: ${hostname}
96 if [ "${ssh_key_data}" ]; then
97 cat >> "${config_dir}/meta-data" <<-EOF
104 #PS1="debug> " bash --norc
106 echo "generating configuration image at ${config_image}"
107 if ! mkisofs -o "${config_image}" -V cidata -r -J --quiet "${config_dir}"; then
108 echo "ERROR: failed to create ${config_image}" >&2
111 chmod a+r "${config_image}"