3 # This will generate a openstack-style config drive image suitable for
4 # use with cloud-init. You may optionally pass in an ssh public key
5 # (using the -k/--ssh-key option) and a user-data blog (using the
6 # -u/--user-data option).
9 echo "usage: ${0##*/}: [--ssh-key <pubkey>] [--vendor-data <file>] [--user-data <file>] [--hostname <hostname>] <imagename>"
14 --long help,hostname:,ssh-key:,user-data:,vendor-data: -n "${0##*/}" \
17 # shellcheck disable=SC2181
56 if [ "${ssh_key}" ] && [ -f "${ssh_key}" ]; then
57 echo "adding pubkey from ${ssh_key}"
58 ssh_key_data=$(cat "${ssh_key}")
62 if ! [ "${hostname}" ]; then
66 trap 'rm -rf $config_dir' EXIT
67 config_dir=$(mktemp -t -d configXXXXXX)
69 if [ "${user_data}" ] && [ -f "${user_data}" ]; then
70 echo "adding user data from ${user_data}"
71 cp "${user_data}" "${config_dir}/user-data"
73 touch "${config_dir}/user-data"
76 if [ "${vendor_data}" ] && [ -f "${vendor_data}" ]; then
77 echo "adding vendor data from ${vendor_data}"
78 cp "${vendor_data}" "${config_dir}/vendor-data"
81 cat > "${config_dir}/meta-data" <<-EOF
84 local-hostname: ${hostname}
87 if [ "${ssh_key_data}" ]; then
88 cat >> "${config_dir}/meta-data" <<-EOF
95 #PS1="debug> " bash --norc
97 echo "generating configuration image at ${config_image}"
98 if ! mkisofs -o "${config_image}" -V cidata -r -J --quiet "${config_dir}"; then
99 echo "ERROR: failed to create ${config_image}" >&2
102 chmod a+r "${config_image}"