1 # This bash script is sourced by the various tools to set the
2 # adt_... variables and some other useful ones.
7 #---------- useful general functions ----------
10 echo >&2 "xenlvm: ${0##*/}: error: $*"
14 x () { echo "x $*"; "$@"; }
17 if type udevsettle >/dev/null 2>&1; then
19 elif test -x /sbin/udevsettle; then
24 case "$BASH_VERSION" in
25 '') fail 'scripts using adtxenlvm readconfig must be bash scripts' ;;
29 #---------- default values for simple settings ----------
37 adt_playbase=/var/lib/autopkgtest/xenlvm
40 adt_vm_reduce_retries=10
43 adt_debootstrap_components='*'
44 adt_debootstrap_include=libc6-xen,openssh-server,ed
45 adt_debootstrap_includemore=
46 adt_debootstrap_mirrors=''
47 adt_debootstrap_script=''
49 adt_fw_localmirrors=''
50 adt_fw_prohibnets='192.168.0.0/24 172.16.0.0/12 10.0.0.0/8'
51 adt_fw_allowglobalports='80'
53 adt_guest_macaddr=00:16:3e:7c:aa:7f
54 adt_net_vifscript=/etc/xen/scripts/vif-route-adt
55 adt_normaluser=adtxenu
57 #---------- arguments and config file ----------
60 while [ $# -gt 0 ]; do
69 *-*) var="$(printf "%s" "$var" | tr -- - _)" ;;
75 *) fail "unknown configuration variable \`$var'" ;;
78 eval "$var=\"\$value\""
82 -*) fail "unknown option \`$arg'" ;;
90 : "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
91 test ! -e "${adt_config}" || . "${adt_config}"
94 #---------- calculated defaults for complex settings ----------
98 printf "searching for default volume group ... "
99 vgdisplay_out=`vgdisplay -c 10>&-`
100 case "$vgdisplay_out" in
101 "") fail 'no volume groups found';;
103 "*) fail 'several volume groups, config must specify which';;
105 adt_lvm_vg=${vgdisplay_out%%:*}
106 case "$adt_lvm_vg" in
107 *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
109 adt_lvm_vg=${adt_lvm_vg##* }
110 echo "using system's only volume group: $adt_lvm_vg"
114 if [ "$adt_readconfig_needkernel" ]; then
115 case "$adt_kernel" in
117 printf "searching for kernel ... "
118 for f in /boot/*"`uname -r`"*; do
119 test -e "$f" || continue
121 output="$(file -- "$f")"
123 *"gzip compressed data"*) ;;
124 *) printf "!gzip) "; continue ;;
126 trap 'rm -f -- "$tf"; exit 127' 0
129 output="$(file -- "$tf")"
131 *"ELF "*" executable,"*) ;;
132 *) printf "!ELF) "; continue;;
134 output="$(objdump -j __xen_guest -s -- "$tf")"
135 rm -f "$tf"; trap '' 0
137 *" __xen_guest:"*) ;;
138 *) printf "!Xen) "; continue
141 test "x$adt_kernel" = x || \
142 fail 'several kernels, config must specify which'
145 [ "x$adt_kernel" != x ] || \
146 fail 'could not find currently booted Xen kernel'
147 echo "using currently booted kernel: $adt_kernel"
151 case "$adt_ramdisk" in
152 none) echo "ramdisk \`none' specified, using static kernel"
154 '') adt_ramdisk="${adt_kernel/\/vmlinuz-//initrd.img-}"
155 test -e "$adt_ramdisk" || \
156 fail "calculated default ramdisk initrd.img \`$adt_ramdisk' does not exist"
157 echo "using calculated default ramdisk initrd.img: $adt_ramdisk" ;;
162 case "$adt_modules" in
163 '') adt_modules="/lib/modules/`uname -r`" ;;
167 case "$adt_distro" in
169 printf "considering which distro to use ... "
170 test -e /etc/lsb-release || \
171 fail 'no /etc/lsb-version, config must specify adt_distro'
173 adt_distro=$DISTRIB_CODENAME
174 echo "using same distro as host: $adt_distro"
178 hostname_from_ipaddr () {
180 if [ x"$adt_'$1'_hostname" = x ] && \
181 [ x"$adt_'$1'_ipaddr" != x ]; then
182 printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
183 adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
184 printf "%s\n" "${adt_'$1'_hostname}"
189 hostname_from_ipaddr guest
190 hostname_from_ipaddr host
192 if [ x"$adt_host_hostname" = x ]; then
193 printf "finding host hostname, supposely our own FQDN: "
194 adt_host_hostname=`hostname -f`
195 printf "%s\n" "$adt_host_hostname"
198 if [ x"$adt_guest_hostname" = x ]; then
199 case "$adt_guests_domain" in
200 '') printf "guessing guest hostname from host hostname: "
201 adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;;
202 .*) printf "setting guest hostname using distro and nominum: "
203 adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;;
204 *) printf "setting guest hostname using distro and domain: "
205 adt_guest_hostname=$adt_distro.$adt_guests_domain ;;
207 printf "%s\n" "$adt_guest_hostname"
210 ipaddr_from_hostname () {
212 if [ x"$adt_'$1'_ipaddr" = x ] && \
213 [ x"$adt_'$1'_hostname" != x ]; then
214 printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
215 adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
216 echo "${adt_'$1'_ipaddr}"
221 ipaddr_from_hostname guest
222 ipaddr_from_hostname host
226 printf "looking for '$2' hook ... "
227 case "$adt_'$1'_hook" in
229 case "$adt_config" in
231 adt_'$1'_hook=${adt_config%_config}_'$3'
232 if test -e "$adt_'$1'_hook"; then
233 echo "default exists: $adt_'$1'_hook"
235 echo "default $adt_'$1'_hook is not a file, so: none"
240 echo "not specified, not computable from config, so: none"
246 if test -e "$adt_'$1'_hook"; then
247 echo "exists: $adt_'$1'_hook"
249 echo "specified as $adt_'$1'_hook, but not a file, so: none"
257 search_hook fw firewall fwhook
258 search_hook setup setup setuphook
262 case "${adt_'$1'}" in
263 y*|Y*|1*|t*) adt_'$1'=true ;;
264 n*|N*|0*|f*) adt_'$1'=false ;;
266 *) fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
272 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
273 : ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub}
274 : ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}}
275 : ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}}
278 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
280 # In-host-file-system playground
281 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
282 : ${adt_xmconfig:=${adt_play}/xmconfig}
283 : ${adt_lock:=${adt_play}/lock}
286 boolean_config lvm_erasebase true
287 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
288 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
289 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
291 : ${adt_fslink_dir:=adt-xenlvm}
292 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
295 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
297 lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
298 lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
300 lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
301 lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
303 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
305 lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name}
306 lvm_fslink_dirpath=/dev/${adt_fslink_dir}
307 lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name}
309 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"