1 # This bash script is sourced by the various tools to set the
2 # adt_... variables and some other useful ones.
6 #---------- useful general functions ----------
9 echo >&2 "xenlvm: ${0##*/}: error: $*"
13 x () { echo "x $*"; "$@"; }
15 case "$BASH_VERSION" in
16 '') fail 'scripts using adtxenlvm readconfig must be bash scripts' ;;
20 #---------- default values for simple settings ----------
28 adt_playbase=/var/lib/autopkgtest/xenlvm
31 adt_vm_reduce_retries=10
34 adt_debootstrap_components='*'
35 adt_debootstrap_include=libc6-xen,openssh-server,ed
36 adt_debootstrap_includemore=
37 adt_debootstrap_mirrors=''
38 adt_debootstrap_script=''
40 adt_fw_localmirrors=''
41 adt_fw_prohibnets='192.168.0.0/24 172.16.0.0/12 10.0.0.0/8'
42 adt_fw_allowglobalports='80'
44 adt_guest_macaddr=00:16:3e:7c:aa:7f
45 adt_net_vifscript=/etc/xen/scripts/vif-route-adt
47 #---------- arguments and config file ----------
50 while [ $# -gt 0 ]; do
59 *-*) var="$(printf "%s" "$var" | tr -- - _)" ;;
65 *) fail "unknown configuration variable \`$var'" ;;
68 eval "$var=\"\$value\""
72 -*) fail "unknown option \`$arg'" ;;
80 : "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
81 test ! -e "${adt_config}" || . "${adt_config}"
84 #---------- calculated defaults for complex settings ----------
88 printf "searching for default volume group ... "
89 vgdisplay_out=`vgdisplay -c 10>&-`
90 case "$vgdisplay_out" in
91 "") fail 'no volume groups found';;
93 "*) fail 'several volume groups, config must specify which';;
95 adt_lvm_vg=${vgdisplay_out%%:*}
97 *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
99 adt_lvm_vg=${adt_lvm_vg##* }
100 echo "using system's only volume group: $adt_lvm_vg"
104 case "$adt_kernel" in
106 printf "searching for kernel ... "
107 for f in /boot/xen*"`uname -r`"; do
108 test -e "$f" || continue
109 test "x$adt_kernel" = x || \
110 fail 'several kernels, config must specify which'
113 echo "using currently booted kernel: $adt_kernel"
117 case "$adt_ramdisk" in
118 none) echo "ramdisk \`none' specified, using static kernel"
120 '') adt_ramdisk="$adt_kernel.initrd.img"
121 echo "using default ramdisk <kernel>.initrd.img: $adt_ramdisk" ;;
125 case "$adt_modules" in
126 '') adt_modules="/lib/modules/`uname -r`" ;;
130 case "$adt_distro" in
132 printf "considering which distro to use ... "
133 test -e /etc/lsb-release || \
134 fail 'no /etc/lsb-version, config must specify adt_distro'
136 adt_distro=$DISTRIB_CODENAME
137 echo "using same distro as host: $adt_distro"
141 hostname_from_ipaddr () {
143 if [ x"$adt_'$1'_hostname" = x ] && \
144 [ x"$adt_'$1'_ipaddr" != x ]; then
145 printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
146 adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
147 printf "%s\n" "${adt_'$1'_hostname}"
152 hostname_from_ipaddr guest
153 hostname_from_ipaddr host
155 if [ x"$adt_host_hostname" = x ]; then
156 printf "finding host hostname, supposely our own FQDN: "
157 adt_host_hostname=`hostname -f`
158 printf "%s\n" "$adt_host_hostname"
161 if [ x"$adt_guest_hostname" = x ]; then
162 case "$adt_guests_domain" in
163 '') printf "guessing guest hostname from host hostname: "
164 adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;;
165 .*) printf "setting guest hostname using distro and nominum: "
166 adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;;
167 *) printf "setting guest hostname using distro and domain: "
168 adt_guest_hostname=$adt_distro.$adt_guests_domain ;;
170 printf "%s\n" "$adt_guest_hostname"
173 ipaddr_from_hostname () {
175 if [ x"$adt_'$1'_ipaddr" = x ] && \
176 [ x"$adt_'$1'_hostname" != x ]; then
177 printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
178 adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
179 echo "${adt_'$1'_ipaddr}"
184 ipaddr_from_hostname guest
185 ipaddr_from_hostname host
187 printf "looking for firewall hook ... "
188 case "$adt_fw_hook" in
190 case "$adt_config" in
192 adt_fw_hook=${adt_config%_config}_fwhook
193 if test -e "$adt_fw_hook"; then
194 echo "default exists: $adt_fw_hook"
196 echo "default $adt_fw_hook is not a file, so: none"
201 echo "not specified, not computable from config, so: none"
207 if test -e "$adt_fw_hook"; then
208 echo "exists: $adt_fw_hook"
210 echo "specified as $adt_fw_hook, but not a file, so: none"
218 case "${adt_'$1'}" in
219 y*|Y*|1*|t*) adt_'$1'=true ;;
220 n*|N*|0*|f*) adt_'$1'=false ;;
222 *) fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
228 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
229 : ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub}
230 : ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}}
231 : ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}}
234 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
236 # In-host-file-system playground
237 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
238 : ${adt_xmconfig:=${adt_play}/xmconfig}
239 : ${adt_lock:=${adt_play}/lock}
242 boolean_config lvm_erasebase true
243 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
244 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
245 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
247 : ${adt_fslink_dir:=adt-xenlvm}
248 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
251 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
253 lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
254 lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
256 lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
257 lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
259 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
261 lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name}
262 lvm_fslink_dirpath=/dev/${adt_fslink_dir}
263 lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name}
265 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"