blob: cd317581319c222bd971166f10be079f4a6d9c2b [file] [log] [blame]
Richard Felkl4c4829d2017-11-11 00:12:20 +01001#!/bin/sh
2
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).
7
8usage () {
9 echo "usage: ${0##*/}: [--ssh-key <pubkey>] [--vendor-data <file>] [--user-data <file>] [--hostname <hostname>] [--model <model>] [--mk-pipelines <mk-pipelines>] [--pipeline-library <pipeline-library>] <imagename>"
10}
11
12ARGS=$(getopt \
13 -o k:u:v:h:m:mp:p \
14 --long help,hostname:,ssh-key:,user-data:,vendor-data:,model:,mk-pipelines:,pipeline-library: -n ${0##*/} \
15 -- "$@")
16
17if [ $? -ne 0 ]; then
18 usage >&2
19 exit 2
20fi
21
22eval set -- "$ARGS"
23
24while :; do
25 case "$1" in
26 --help)
27 usage
28 exit 0
29 ;;
30 -k|--ssh-key)
31 ssh_key="$2"
32 shift 2
33 ;;
34 -u|--user-data)
35 user_data="$2"
36 shift 2
37 ;;
38 -v|--vendor-data)
39 vendor_data="$2"
40 shift 2
41 ;;
42 -h|--hostname)
43 hostname="$2"
44 shift 2
45 ;;
46 -m|--model)
47 model="$2"
48 shift 2
49 ;;
50 -mp|--mk-pipelines)
51 mk_pipelines="$2"
52 shift 2
53 ;;
54 -p|--pipeline-library)
55 pipeline_library="$2"
56 shift 2
57 ;;
58 --) shift
59 break
60 ;;
61 esac
62done
63
64config_image=$1
65shift
66
Richard Felkl4c4829d2017-11-11 00:12:20 +010067
68uuid=$(uuidgen)
69if ! [ "$hostname" ]; then
70 hostname="$uuid"
71fi
72
73trap 'rm -rf $config_dir' EXIT
74config_dir=$(mktemp -t -d configXXXXXX)
75
Petr Ruzicka6982da32018-08-09 15:11:06 +020076if [ "$ssh_key" ] && [ -f "$ssh_key" ]; then
77 echo "adding pubkey from $ssh_key"
78 cp $ssh_key $config_dir/root_auth_keys
79fi
80
Richard Felkl4c4829d2017-11-11 00:12:20 +010081if [ "$user_data" ] && [ -f "$user_data" ]; then
82 echo "adding user data from $user_data"
83 cp $user_data $config_dir/user-data
84else
85 touch $config_dir/user-data
86fi
87
88if [ "$vendor_data" ] && [ -f "$vendor_data" ]; then
89 echo "adding vendor data from $vendor_data"
90 cp $vendor_data $config_dir/vendor-data
91fi
92
93if [ "$model" ] ; then
94 echo "adding reclass model directory $model"
95 mkdir $config_dir/model
96 cp -r $model $config_dir/model/
97fi
98
99if [ "$mk_pipelines" ] ; then
Dmitry Pyzhovef9e19e2018-12-10 16:27:29 +0300100 echo "adding mk-pipelines directory $mk_pipelines"
Richard Felkl4c4829d2017-11-11 00:12:20 +0100101 cp -r $mk_pipelines $config_dir/mk-pipelines/
102fi
103
104if [ "$pipeline_library" ] ; then
Dmitry Pyzhovef9e19e2018-12-10 16:27:29 +0300105 echo "adding pipeline-library directory $pipeline_library"
Richard Felkl4c4829d2017-11-11 00:12:20 +0100106 cp -r $pipeline_library $config_dir/pipeline-library/
107fi
108
109cat > $config_dir/meta-data <<-EOF
110instance-id: $uuid
111hostname: $hostname
112local-hostname: $hostname
113EOF
114
115#PS1="debug> " bash --norc
116
117echo "generating configuration image at $config_image"
118if ! mkisofs -o $config_image -V cidata -r -J --quiet $config_dir; then
119 echo "ERROR: failed to create $config_image" >&2
120 exit 1
121fi
122
123chmod a+r $config_image
124
125
126