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##*/} \
55 if [ "$ssh_key" ] && [ -f "$ssh_key" ]; then
56 echo "adding pubkey from $ssh_key"
57 ssh_key_data=$(cat "$ssh_key")
61 if ! [ "$hostname" ]; then
65 trap 'rm -rf $config_dir' EXIT
66 config_dir=$(mktemp -t -d configXXXXXX)
68 if [ "$user_data" ] && [ -f "$user_data" ]; then
69 echo "adding user data from $user_data"
70 cp ${user_data} ${config_dir}/user-data
72 touch $config_dir/user-data
75 if [ "$vendor_data" ] && [ -f "$vendor_data" ]; then
76 echo "adding vendor data from $vendor_data"
77 cp ${vendor_data} ${config_dir}/vendor-data
80 cat > $config_dir/meta-data <<-EOF
83 local-hostname: $hostname
86 if [ "$ssh_key_data" ]; then
87 cat >> $config_dir/meta-data <<-EOF
94 #PS1="debug> " bash --norc
96 echo "generating configuration image at $config_image"
97 if ! mkisofs -o $config_image -V cidata -r -J --quiet $config_dir; then
98 echo "ERROR: failed to create $config_image" >&2
101 chmod a+r $config_image