3 . ${CIRROS_LIB:=/lib/cirros/shlib_cirros} ||
4 { echo "failed to read ${CIRROS_LIB}" 1>&2; exit 1; }
10 handle the user-data present in file.
11 If no file is present, retrieve 'user-data' from datasource.
13 if no file is given, and no datasource is found, exit silently.
16 --dry-run : only report, do not update results
17 -v | --verbose : be more verbose
23 local long_opts="help,dry-run,verbose"
25 getopt_out=$(getopt --name "${0##*/}" \
26 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
27 eval set -- "${getopt_out}" ||
28 { bad_Usage; return; }
30 local dryrun=false cur="" next="" VERBOSITY="$VERBOSITY"
32 while [ $# -ne 0 ]; do
35 -h|--help) Usage ; exit 0;;
36 -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
37 --dry-run) dryrun=true;;
44 assert_datasource || exit 0
45 ds_has_item user-data ||
46 { debug 1 "no userdata for datasource"; return 0; }
47 ds_get_item_path user-data || { error "failed to get user-data"; return 1; }
51 local tempf="" ret="" failures=0
53 [ -f "$@" ] || { error "$cur is not a file"; return 1; }
54 if [ -x "$cur" ]; then
57 debug 1 "$cur returned $ret"
58 elif [ "$(head -c 2 "$cur" )" = "#!" ]; then
59 $dryrun && { error "execute ${cur}"; continue; }
60 if [ -z "$tempf" ]; then
61 tempf=$(mktemp "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
62 { error "failed to make tempdir"; return 1; }
64 cat "$cur" > "$tempf" && chmod 700 "$cur" || {
65 error "failed to copy $cur to make executable";
71 debug 2 "$cur returned $ret"
74 debug 1 "$cur was not '#!' or executable"
76 [ $ret -eq 0 ] || failures=$(($failures+1))
85 # vi: ts=4 noexpandtab