The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / src / sbin / cirros-ds
1 #!/bin/sh
2
3 . ${CIRROS_LIB:=/lib/cirros/shlib_cirros} ||
4         { echo "failed to read ${CIRROS_LIB}" 1>&2; exit 1; }
5
6 Usage() {
7         cat <<EOF
8 Usage: ${0##*/} [ options ] mode [datasource [datasource [ ... ] ]
9
10    Search for datasources of type 'mode'.
11    mode is one of 'net' or 'local'
12
13    if no datasources are provided, all available are searched
14    see configuration in $CONFIG
15
16    options:
17         --dry-run  : only report, do not update results
18    -v | --verbose  : be more verbose
19 EOF
20 }
21
22 cleanup() {
23         [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
24 }
25
26 cirros_ds() {
27         local short_opts="hv"
28         local long_opts="help,dry-run,verbose"
29         local getopt_out=""
30         getopt_out=$(getopt --name "${0##*/}" \
31                 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
32                 eval set -- "${getopt_out}" ||
33                 { bad_Usage; return; }
34
35         local dryrun=false uptime="" cur="" next="" mode="" ptv="" VERBOSITY
36         read_uptime && uptime=${_RET}
37
38         while [ $# -ne 0 ]; do
39                 cur=${1}; next=${2};
40                 case "$cur" in
41                         -h|--help) Usage ; exit 0;;
42                         -v|--verbose)
43                                 [ -z "${ptv}" ] && ptv="-v" || ptv="${ptv}v"
44                                 VERBOSITY=$((${VERBOSITY}+1));;
45                        --dry-run) dryrun=true;;
46                         --) shift; break;;
47                 esac
48                 shift;
49         done
50
51         [ $# -ne 0 ] || { bad_Usage "must provide mode"; return; }
52         mode="$1"
53         shift
54
55         [ "$mode" = "net" -o "$mode" = "local" ] ||
56                 { bad_Usage "mode must be 'net' or 'local'"; return; }
57
58         debug 1 "${0##*/} '$mode' up at $uptime"
59
60         local cmdline tok cmdline_list oifs="$IFS"
61         if [ $# -eq 0 ]; then
62                 { read cmdline < /proc/cmdline; } >/dev/null 2>&1
63                 for tok in $cmdline; do
64                         case "$tok" in
65                                 dslist=) cmdline_list=none;;
66                                 dslist=*) cmdline_list=${tok#dslist=};;
67                         esac
68                 done
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:" "$@"
72                 else
73                         set -- ${DATASOURCE_LIST}
74                         debug 2 "found datasource list in config:" "$@"
75                 fi
76                 [ $# -ne 0 ] || { error "no datasource list configured?"; return 1; }
77         fi
78
79         TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
80                 { error "failed to make tempdir"; return 1; }
81         trap cleanup EXIT
82
83         local ds result="" ret=""
84
85         PATH="${DS_D}:$PATH"
86         for ds in "$@"; do
87                 result="${TEMP_D}/${ds}/result"
88                 read_uptime
89                 debug 2 "running: $ds $ptv $mode $TEMP_D/${ds} [up ${_RET}]"
90                 "$ds" $ptv "$mode" "${TEMP_D}/${ds}" > "${TEMP_D}/output"
91                 ret=$?
92                 if [ $ret -eq 0 ] && [ -r "$result" ]; then
93                         rm -f "$result"
94                         if $dryrun; then
95                                 error "$ds-$mode: datasource found"
96                         else
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";
100                                                 return 1;
101                                         }
102                                 echo "$ds" > "$RESULTS_D/dsname"
103                                 echo "$mode" > "$RESULTS_D/dsmode"
104                         fi
105                         debug 1 "found datasource ($ds, $mode)"
106                         return 0
107                 elif [ $ret -eq 0 ]; then
108                         debug 2 "$ds-$mode: no datasource found"
109                 else
110                         error "$ds-$mode: returned error"
111                 fi
112         done
113
114         read_uptime
115         debug 1 "no results found for mode=$mode. up $_RET. searched:" "$@"
116         return 1
117 }
118
119 cirros_ds "$@"
120
121 # vi: ts=4 noexpandtab