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 $*"; "$@"; }
16 case "$BASH_VERSION" in
17 '') fail 'scripts using adtxenlvm readconfig must be bash scripts' ;;
21 #---------- default values for simple settings ----------
24 : ${adt_testbed_ram:=256}
25 : ${adt_freeze_ram:=32}
26 : ${adt_fs_size:=3072M}
27 : ${adt_fs_snapsize:=2560M}
28 : ${adt_fs_cowchunk:=8}
29 : ${adt_playbase:=/var/lib/autopkgtest/xenlvm}
30 : ${adt_fs_type:=ext3}
31 : ${adt_fs_mkfs_args:=}
32 : ${adt_vm_reduce_retries:=10}
33 : ${adt_ssh_keytype:=dsa}
35 : ${adt_debootstrap_components:='*'}
36 : ${adt_debootstrap_include:=libc6-xen,openssh-server,ed}
37 : ${adt_debootstrap_includemore:=}
38 : ${adt_debootstrap_mirrors:=}
39 : ${adt_debootstrap_script:=}
41 : ${adt_fw_localmirrors:=}
42 : ${adt_fw_prohibnets:=192.168.0.0/24 172.16.0.0/12 10.0.0.0/8}
43 : ${adt_fw_allowglobalports:=80}
45 : ${adt_guest_macaddr:=00:16:3e:7c:aa:7f}
46 : ${adt_net_vifscript:=/etc/xen/scripts/vif-route-adt}
47 : ${adt_normaluser:=adtxenu}
49 #---------- arguments and config file ----------
52 while [ $# -gt 0 ]; do
61 *-*) var="$(printf "%s" "$var" | tr -- - _)" ;;
67 *) fail "unknown configuration variable \`$var'" ;;
70 eval "adt_$var=\"\$value\"; export adt_$var"
74 -*) fail "unknown option \`$arg'" ;;
82 : "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
83 test ! -e "${adt_config}" || . "${adt_config}"
86 #---------- calculated defaults for complex settings ----------
88 if [ ! "${adt_readconfig_initscript}" ]; then
91 printf "searching for default volume group ... "
92 vgdisplay_out=`vgdisplay -c 8>&-`
93 case "$vgdisplay_out" in
94 "") fail 'no volume groups found';;
96 "*) fail 'several volume groups, config must specify which';;
98 adt_lvm_vg=${vgdisplay_out%%:*}
100 *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
102 adt_lvm_vg=${adt_lvm_vg##* }
103 echo "using system's only volume group: $adt_lvm_vg"
108 if [ "$adt_readconfig_needkernel" ]; then
109 case "$adt_kernel" in
111 printf "searching for kernel ... "
112 for f in /boot/*"`uname -r`"*; do
113 test -e "$f" || continue
115 output="$(file -- "$f")"
117 *"gzip compressed data"*) ;;
118 *) printf "!gzip) "; continue ;;
120 trap 'rm -f -- "$tf"; exit 127' 0
123 output="$(file -- "$tf")"
125 *"ELF "*" executable,"*) ;;
126 *) printf "!ELF) "; continue;;
128 output="$(objdump -j __xen_guest -s -- "$tf")"
129 rm -f "$tf"; trap '' 0
131 *" __xen_guest:"*) ;;
132 *) printf "!Xen) "; continue
135 test "x$adt_kernel" = x || \
136 fail 'several kernels, config must specify which'
139 [ "x$adt_kernel" != x ] || \
140 fail 'could not find currently booted Xen kernel'
141 echo "using currently booted kernel: $adt_kernel"
145 case "$adt_ramdisk" in
146 none) echo "ramdisk \`none' specified, using static kernel"
148 '') adt_ramdisk="${adt_kernel/\/vmlinuz-//initrd.img-}"
149 test -e "$adt_ramdisk" || \
150 fail "calculated default ramdisk initrd.img \`$adt_ramdisk' does not exist"
151 echo "using calculated default ramdisk initrd.img: $adt_ramdisk" ;;
156 case "$adt_modules" in
157 '') adt_modules="/lib/modules/`uname -r`" ;;
161 if [ ! "${adt_readconfig_initscript}" ]; then
162 case "$adt_distro" in
164 printf "considering which distro to use ... "
165 test -e /etc/lsb-release || \
166 fail 'no /etc/lsb-version, config must specify adt_distro'
168 adt_distro=$DISTRIB_CODENAME
169 echo "using same distro as host: $adt_distro"
174 hostname_from_ipaddr () {
176 if [ x"$adt_'$1'_hostname" = x ] && \
177 [ x"$adt_'$1'_ipaddr" != x ]; then
178 printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
179 adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
180 printf "%s\n" "${adt_'$1'_hostname}"
185 hostname_from_ipaddr host
187 if [ ! "${adt_readconfig_initscript}" ]; then
188 hostname_from_ipaddr guest
191 if [ x"$adt_host_hostname" = x ]; then
192 printf "finding host hostname, supposely our own FQDN: "
193 adt_host_hostname=`hostname -f`
194 printf "%s\n" "$adt_host_hostname"
197 if [ ! "${adt_readconfig_initscript}" ]; then
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"
211 ipaddr_from_hostname () {
213 if [ x"$adt_'$1'_ipaddr" = x ] && \
214 [ x"$adt_'$1'_hostname" != x ]; then
215 printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
216 adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
217 echo "${adt_'$1'_ipaddr}"
222 ipaddr_from_hostname host
223 if [ ! "${adt_readconfig_initscript}" ]; then
224 ipaddr_from_hostname guest
229 printf "looking for '$2' hook ... "
230 case "$adt_'$1'_hook" in
232 case "$adt_config" in
234 adt_'$1'_hook=${adt_config%_config}_'$3'
235 if test -e "$adt_'$1'_hook"; then
236 echo "default exists: $adt_'$1'_hook"
238 echo "default $adt_'$1'_hook is not a file, so: none"
243 echo "not specified, not computable from config, so: none"
249 if test -e "$adt_'$1'_hook"; then
250 echo "exists: $adt_'$1'_hook"
252 echo "specified as $adt_'$1'_hook, but not a file, so: none"
260 search_hook fw firewall fwhook
261 search_hook setup setup setuphook
265 case "${adt_'$1'}" in
266 y*|Y*|1*|t*) adt_'$1'=true ;;
267 n*|N*|0*|f*) adt_'$1'=false ;;
269 *) fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
275 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
276 : ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub}
277 : ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}}
278 : ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}}
281 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
283 # In-host-file-system playground
284 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
285 : ${adt_xmconfig:=${adt_play}/xmconfig}
286 : ${adt_lock:=${adt_play}/lock}
289 boolean_config lvm_erasebase true
290 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
291 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
292 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
294 : ${adt_fslink_dir:=adt-xenlvm}
295 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
298 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
300 lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
301 lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
303 lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
304 lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
306 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
308 lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name}
309 lvm_fslink_dirpath=/dev/${adt_fslink_dir}
310 lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name}
312 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"