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).
16 echo "usage: ${0##*/}: [--ssh-key <pubkey>] [--vendor-data <file>] [--user-data <file>] [--hostname <hostname>] <imagename>"
21 --long help,hostname:,ssh-key:,user-data:,vendor-data: -n "${0##*/}" \
24 # shellcheck disable=SC2181
63 if [ "${ssh_key}" ] && [ -f "${ssh_key}" ]; then
64 echo "adding pubkey from ${ssh_key}"
65 ssh_key_data=$(cat "${ssh_key}")
69 if ! [ "${hostname}" ]; then
73 trap 'rm -rf $config_dir' EXIT
74 config_dir=$(mktemp -t -d configXXXXXX)
76 if [ "${user_data}" ] && [ -f "${user_data}" ]; then
77 echo "adding user data from ${user_data}"
78 cp "${user_data}" "${config_dir}/user-data"
80 touch "${config_dir}/user-data"
83 if [ "${vendor_data}" ] && [ -f "${vendor_data}" ]; then
84 echo "adding vendor data from ${vendor_data}"
85 cp "${vendor_data}" "${config_dir}/vendor-data"
88 cat > "${config_dir}/meta-data" <<-EOF
91 local-hostname: ${hostname}
94 if [ "${ssh_key_data}" ]; then
95 cat >> "${config_dir}/meta-data" <<-EOF
102 #PS1="debug> " bash --norc
104 echo "generating configuration image at ${config_image}"
105 if ! mkisofs -o "${config_image}" -V cidata -r -J --quiet "${config_dir}"; then
106 echo "ERROR: failed to create ${config_image}" >&2
109 chmod a+r "${config_image}"