3 . ${CIRROS_LIB:=/lib/cirros/shlib_cirros} ||
4 { echo "failed to read ${CIRROS_LIB}" 1>&2; exit 1; }
8 Usage: ${0##*/} [ options ] mode [datasource [datasource [ ... ] ]
10 Search for datasources of type 'mode'.
11 mode is one of 'net' or 'local'
13 if no datasources are provided, all available are searched
14 see configuration in $CONFIG
17 --dry-run : only report, do not update results
18 -v | --verbose : be more verbose
23 [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
28 local long_opts="help,dry-run,verbose"
30 getopt_out=$(getopt --name "${0##*/}" \
31 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
32 eval set -- "${getopt_out}" ||
33 { bad_Usage; return; }
35 local dryrun=false uptime="" cur="" next="" mode="" ptv="" VERBOSITY
36 read_uptime && uptime=${_RET}
38 while [ $# -ne 0 ]; do
41 -h|--help) Usage ; exit 0;;
43 [ -z "${ptv}" ] && ptv="-v" || ptv="${ptv}v"
44 VERBOSITY=$((${VERBOSITY}+1));;
45 --dry-run) dryrun=true;;
51 [ $# -ne 0 ] || { bad_Usage "must provide mode"; return; }
55 [ "$mode" = "net" -o "$mode" = "local" ] ||
56 { bad_Usage "mode must be 'net' or 'local'"; return; }
58 debug 1 "${0##*/} '$mode' up at $uptime"
60 local cmdline tok cmdline_list oifs="$IFS"
62 { read cmdline < /proc/cmdline; } >/dev/null 2>&1
63 for tok in $cmdline; do
65 dslist=) cmdline_list=none;;
66 dslist=*) cmdline_list=${tok#dslist=};;
69 if [ -n "${cmdline_list}" -a "${cmdline_list}" != "none" ]; then
70 IFS=","; set -- ${cmdline_list}; IFS="$oifs"
71 debug 2 "found datasource list on cmdline:" "$@"
73 set -- ${DATASOURCE_LIST}
74 debug 2 "found datasource list in config:" "$@"
76 [ $# -ne 0 ] || { error "no datasource list configured?"; return 1; }
79 TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
80 { error "failed to make tempdir"; return 1; }
83 local ds result="" ret=""
87 result="${TEMP_D}/${ds}/result"
89 debug 2 "running: $ds $ptv $mode $TEMP_D/${ds} [up ${_RET}]"
90 "$ds" $ptv "$mode" "${TEMP_D}/${ds}" > "${TEMP_D}/output"
92 if [ $ret -eq 0 ] && [ -r "$result" ]; then
95 error "$ds-$mode: datasource found"
97 rm -Rf "$RESULTS_D" && mkdir -p "${RESULTS_D%/*}" &&
98 cp -a "${TEMP_D}/$ds/" "${RESULTS_D}" || {
99 error "failed to copy results from $ds to $RESULTS_D";
102 echo "$ds" > "$RESULTS_D/dsname"
103 echo "$mode" > "$RESULTS_D/dsmode"
105 debug 1 "found datasource ($ds, $mode)"
107 elif [ $ret -eq 0 ]; then
108 debug 2 "$ds-$mode: no datasource found"
110 error "$ds-$mode: returned error"
115 debug 1 "no results found for mode=$mode. up $_RET. searched:" "$@"
121 # vi: ts=4 noexpandtab