4 CONFIG="/etc/cirros-init/ds-nocloud"
5 SEED_PRE_D="/var/lib/cloud/seed/nocloud-pre"
6 SEED_POST_D="/var/lib/cloud/seed/nocloud"
10 . ${CIRROS_SHLIB:=/lib/cirros/shlib} ||
11 { echo "failed to read ${CIRROS_SHLIB}" 1>&2; exit 1; }
15 Usage: ${0##*/} mode output_d
17 Datasource for 'nocloud' config disk.
23 local devlist="" num="" found="" dev="" tmpd="" found="" f=""
24 find_devs_with "LABEL=$LABEL" ||
25 { error "failed to find devs"; return 1; }
29 if [ -d "${SEED_PRE_D}" ]; then
30 devlist="$SEED_PRE_D $devlist"
32 if [ -d "${SEED_POST_D}" ]; then
33 devlist="$devlist $SEED_POST_D"
36 [ -n "$devlist" ] || { debug 2 "no devices labeled $LABEL"; return 0; }
39 for dev in ${devlist}; do num=$(($num+1)); done
40 [ $num -eq 1 ] || debug 1 "multiple devices matching $LABEL: $devlist"
42 [ -d "$out_d" ] || mkdir -p "$out_d" ||
43 { error "failed to create outputdir: ${out_d}"; return 1; }
47 data_d="${out_d}/data"
48 for dev in ${devlist}; do
50 if [ -b "$dev" ]; then
51 mount_callback_umount "$dev" -o,ro cp -a "${tmpd}" ||
52 { debug 1 "mount callback umount $dev failed"; continue; }
54 cp -a "$dev" "${tmpd}" ||
55 { debug 1 "failed to copy from $dev"; continue; }
58 [ -f "${tmpd}/meta-data" ] ||
59 { debug 2 "$dev had no meta-data"; continue; }
61 json2fstree "${data_d}" "${tmpd}/meta-data" || {
62 error "json2fstree failed on ${tmpd}/meta-data from $dev"
66 [ ! -f "${tmpd}/user-data" ] || cp "${tmpd}/user-data" "${data_d}" ||
67 { error "failed to copy user-data from $dev"; return 1; }
69 [ -d "${tmpd}/files" ] && cp -a "${tmpd}/files" "${data_d}"
76 [ -z "$found" ] && return 0
78 # now we have filesystem rendering at $fstree_d
79 # and raw data (copy of config drive data) at $raw_d
80 mkdir -p "${out_d}/data" ||
81 fail "failed to make data dir"
83 if [ ! -f "${data_d}/instance-id" ]; then
84 echo "i-nocloud-default" > "${data_d}/instance-id"
86 if [ -d "${data_d}/public-keys" ]; then
87 # turn public-keys list into
88 mv "${data_d}/public-keys" "${out_d}/public-keys-d";
90 for f in "${out_d}/public-keys-d/"*; do
91 [ -f "${f}" -a "${f##*/}" != "0" ] && cat "$f"
92 done > "${data_d}/public-keys"
96 echo 0 > "$out_d/result"
100 local mode="$1" data_d="$2"
101 # support copying 'files' if it happened to be on that disk
102 if [ -d "$data_d/files" ]; then
103 local omask="" f="" path="" tpath=""
106 for f in $(find "$data_d/files/" -type f); do
107 path="${f#${data_d}/files/}"
108 tpath="${TARGET_ROOT}/${path}"
109 mkdir -p "${tpath%/*}" && cp "${f}" "${tpath}" ||
110 { error "failed to create ${tpath}"; return 1; }
117 long_opts="help,verbose"
118 getopt_out=$(getopt --name "${0##*/}" \
119 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
120 eval set -- "${getopt_out}" ||
123 while [ $# -ne 0 ]; do
126 -h|--help) Usage ; exit 0;;
127 -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
133 [ $# -eq 2 ] || bad_Usage "must provide mode and output dir"
137 [ "$mode" = "local" -o "$mode" = "apply-local" ] ||
138 { debug 2 "only supported in mode 'local'"; exit 0; }
140 [ ! -e "$CONFIG" ] || . "$CONFIG" ||
141 fail "failed to read $CONFIG"
143 if [ "$mode" = "local" ]; then
144 search_local "$out_d"
145 elif [ "$mode" = "apply-local" ]; then
146 apply "$mode" "$out_d"
148 fail "error, unexpected input"
152 # vi: ts=4 noexpandtab