3 . ${CIRROS_LIB:=/lib/cirros/shlib_cirros} ||
4 { echo "failed to read ${CIRROS_LIB}" 1>&2; exit 1; }
6 SSH_ROOT_PREFIX="command=\"echo Please login as \\'cirros\\' user, not as root; echo; sleep 10\""
10 Usage: ${0##*/} [ options ] mode
12 Call appropriate datasource for its 'apply-<mode>' stage,
13 and then apply generic 'apply-<mode>' hooks.
15 If there is no data source, or datasource configured is
16 not of type 'mode', then it will exit silently with success.
18 mode is one of 'net' or 'local'
21 -v | --verbose : be more verbose
27 local long_opts="help,verbose"
29 getopt_out=$(getopt --name "${0##*/}" \
30 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
31 eval set -- "${getopt_out}" ||
32 { bad_Usage; return; }
34 local cur="" next="" mode="" VERBOSITY
36 while [ $# -ne 0 ]; do
39 -h|--help) Usage ; exit 0;;
40 -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
46 [ $# -ne 0 ] || { bad_Usage "must provide mode"; return; }
50 [ "$mode" = "net" -o "$mode" = "local" ] ||
51 { bad_Usage "mode must be 'net' or 'local'"; return; }
53 local dsname dsmode root
56 { debug 1 "no datasource present"; return 0; }
58 dsname="${_DATASOURCE_NAME}"
59 dsmode="${_DATASOURCE_MODE}"
61 [ "${dsmode}" = "$mode" ] || {
62 debug 1 "datasource found is mode '${dsmode}', skipping";
67 local root="${TARGET_ROOT}"
68 if [ -n "$root" ]; then
70 cd "$root" && root="$PWD" && cd "$sd" ||
75 TARGET_ROOT=$root "$dsname" "apply-${dsmode}" "$RESULTS_D" ||
76 { error "$dsname failed in apply-$dsmode"; return 1; }
79 # here do any common things for $mode
82 if ds_get_item hostname || ds_get_item local-hostname; then
83 hostname="${_RET%%.*}"
84 echo "$hostname" > /etc/hostname
85 hostname -F /etc/hostname
89 ## if there is a 'ephemeral0' block device, mount it
90 if find_devs_with LABEL=ephemeral0 && [ -n "${_RET}" ]; then
91 # get the first one only
92 local dev="${_RET% *}"
93 echo "${dev} /mnt auto rw,defaults 0 0" >> /etc/fstab
95 error "failed to mount ${dev}"
98 # if we were provided with a network/interfaces file copy it
99 if [ -f "$RESULTS_D/network-interfaces" ]; then
100 local nif="$TARGET_ROOT/etc/network/interfaces"
101 [ -d "$TARGET_ROOT/etc/network" ] ||
102 mkdir -p "$TARGET_ROOT/etc/network"
103 [ ! -f "$nif" ] || cp "$nif" "$nif.dist" ||
104 error "failed to copy network interfaces"
105 debug 1 "copied network/interfaces"
108 # if we have public-keys, put them in cirros user
109 if ds_get_item_path public-keys; then
110 local keyfile="$_RET"
111 ds_get_item public-keys ||
112 error "failed to get public-keys"
113 mkdir -p "${TARGET_ROOT}/home/cirros" "${TARGET_ROOT}/root"
114 HOME=$TARGET_ROOT/home/cirros su -c "ssh-add-key --replace -" cirros < "$keyfile"
115 HOME=$TARGET_ROOT/root ssh-add-key --replace \
116 --prefix "$SSH_ROOT_PREFIX" - < "$keyfile"
120 if [ -c /dev/urandom ]; then
121 for name in random_seed random-seed; do
122 if ds_has_item "$name"; then
123 ds_cat_item "$name" > /dev/urandom && break
133 # vi: ts=4 noexpandtab