4 CONFIG=/etc/cirros-init/configdrive
8 SEED_PRE_D="/var/lib/cloud/seed/configdrive-pre"
9 SEED_POST_D="/var/lib/cloud/seed/configdrive"
11 . ${CIRROS_SHLIB:=/lib/cirros/shlib} ||
12 { echo "failed to read ${CIRROS_SHLIB}" 1>&2; exit 1; }
16 Usage: ${0##*/} mode output_d
18 Datasource for openstack config drive
24 local devlist="" num="" found="" fstree_d=""
25 local raw_d="" dev="" rdir="" mdjson="" ud="" found=""
26 find_devs_with "LABEL=$LABEL" && [ -n "${_RET}" ] ||
27 find_devs_with "LABEL=$LABEL_ALT" ||
28 { error "failed to find devs"; return 1; }
31 [ -n "$devlist" ] || { debug 1 "no devices labeled $LABEL"; exit 0; }
33 if [ -d "${SEED_PRE_D}" ]; then
34 devlist="$SEED_PRE_D $devlist"
36 if [ -d "${SEED_POST_D}" ]; then
37 devlist="$devlist $SEED_POST_D"
41 for dev in ${devlist}; do num=$(($num+1)); done
42 [ $num -eq 1 ] || debug 1 "multiple devices matching $LABEL: $devlist"
44 [ -d "$out_d" ] || mkdir -p "$out_d" ||
45 fail "failed to create outputdir: ${out_d}"
49 fstree_d="${out_d}/processed"
51 for dev in ${devlist}; do
54 if [ -b "$dev" ]; then
55 mount_callback_umount "$dev" -o,ro cp -a "${rdir}" ||
56 { debug 1 "mount callback umount $dev failed"; continue; }
58 cp -a "$dev" "${rdir}" ||
59 { debug 1 "failed to copy from $dev"; continue; }
62 mdjson="$rdir/openstack/latest/meta_data.json"
63 if [ -f "$mdjson" ]; then
64 json2fstree "$fstree_d" "$mdjson" ||
65 fail "json2fstree failed on $mdjson for $dev"
66 ud="$rdir/openstack/latest/user_data"
67 [ -f "$ud" ] && cp "$ud" "$fstree_d/user-data"
69 mv "$rdir" "$raw_d" ||
75 [ -z "$found" ] && return 0
77 # now we have filesystem rendering at $fstree_d
78 # and raw data (copy of config drive data) at $raw_d
79 mkdir -p "${out_d}/data" ||
80 fail "failed to make data dir"
84 local f="" t="" fix=""
86 for f in ../processed/*; do
87 [ -f "$f" ] || continue
92 if [ -d ../processed/public_keys ]; then
94 cat ../processed/public_keys/* > public-keys || rm public-keys
98 for fix in uuid:instance-id hostname:local-hostname user_data:user-data \
99 availability_zone:availability-zone launch_index:launch-index; do
102 [ -f "$f" -a ! -f "$t" ] || continue
103 ln -sf "$f" "$t" || fail "failed to link $f to $t"
106 # now create files/ tree
109 local d path content_path omask
112 if [ -f processed/files/0 ]; then
113 # processed/files/0 is the length
115 for d in processed/files/*; do
116 [ "${d##*/}" = "0" ] && continue
118 [ -f "$d/path" -a -f "$d/content_path" ] ||
119 { debug 1 "$d unexpected file dir"; continue; }
120 { read path < "$d/path" || [ -n "$path" ] ; } &&
121 { read content_path < "$d/content_path" ||
122 [ -n "$content_path" ]; } ||
123 { debug 1 "skipping $d, failed reads"; continue; }
124 mkdir -p "files/${path%/*}" &&
125 cp "raw/openstack/${content_path}" "files/${path}" ||
126 { fail "failed to create ${path} in files"; return 1; }
134 echo 0 > "$out_d/result"
138 local mode="$1" data_d="$2"
139 if [ -d "$data_d/files" ]; then
140 local omask="" f="" path="" tpath=""
143 for f in $(find "$data_d/files/" -type f); do
144 path="${f#${data_d}/files/}"
145 tpath="${TARGET_ROOT}/${path}"
146 mkdir -p "${tpath%/*}" && cp "${f}" "${tpath}" ||
147 { error "failed to create ${tpath}"; return 1; }
154 long_opts="help,verbose"
155 getopt_out=$(getopt --name "${0##*/}" \
156 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
157 eval set -- "${getopt_out}" ||
160 while [ $# -ne 0 ]; do
163 -h|--help) Usage ; exit 0;;
164 -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
170 [ $# -eq 2 ] || bad_Usage "must provide mode and output dir"
174 [ "$mode" = "local" -o "$mode" = "apply-local" ] ||
175 { debug 2 "only supported in mode 'local'"; exit 0; }
177 [ ! -e "$CONFIG" ] || . "$CONFIG" ||
178 fail "failed to read $CONFIG"
180 if [ "$mode" = "local" ]; then
181 search_local "$out_d"
182 elif [ "$mode" = "apply-local" ]; then
183 apply "$mode" "$out_d"
185 fail "error, unexpected input"
189 # vi: ts=4 noexpandtab