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 ----------
29 adt_playbase=/var/lib/autopkgtest/xenlvm
32 adt_vm_reduce_retries=10
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\""
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 ----------
90 printf "searching for default volume group ... "
91 vgdisplay_out=`vgdisplay -c 10>&-`
92 case "$vgdisplay_out" in
93 "") fail 'no volume groups found';;
95 "*) fail 'several volume groups, config must specify which';;
97 adt_lvm_vg=${vgdisplay_out%%:*}
99 *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
101 adt_lvm_vg=${adt_lvm_vg##* }
102 echo "using system's only volume group: $adt_lvm_vg"
106 if [ "$adt_readconfig_needkernel" ]; then
107 case "$adt_kernel" in
109 printf "searching for kernel ... "
110 for f in /boot/*"`uname -r`"*; do
111 test -e "$f" || continue
113 output="$(file -- "$f")"
115 *"gzip compressed data"*) ;;
116 *) printf "!gzip) "; continue ;;
118 trap 'rm -f -- "$tf"; exit 127' 0
121 output="$(file -- "$tf")"
123 *"ELF "*" executable,"*) ;;
124 *) printf "!ELF) "; continue;;
126 output="$(objdump -j __xen_guest -s -- "$tf")"
127 rm -f "$tf"; trap '' 0
129 *" __xen_guest:"*) ;;
130 *) printf "!Xen) "; continue
133 test "x$adt_kernel" = x || \
134 fail 'several kernels, config must specify which'
137 [ "x$adt_kernel" != x ] || \
138 fail 'could not find currently booted Xen kernel'
139 echo "using currently booted kernel: $adt_kernel"
143 case "$adt_ramdisk" in
144 none) echo "ramdisk \`none' specified, using static kernel"
146 '') adt_ramdisk="${adt_kernel/\/vmlinuz-//initrd.img-}"
147 test -e "$adt_ramdisk" || \
148 fail "calculated default ramdisk initrd.img \`$adt_ramdisk' does not exist"
149 echo "using calculated default ramdisk initrd.img: $adt_ramdisk" ;;
154 case "$adt_modules" in
155 '') adt_modules="/lib/modules/`uname -r`" ;;
159 case "$adt_distro" in
161 printf "considering which distro to use ... "
162 test -e /etc/lsb-release || \
163 fail 'no /etc/lsb-version, config must specify adt_distro'
165 adt_distro=$DISTRIB_CODENAME
166 echo "using same distro as host: $adt_distro"
170 hostname_from_ipaddr () {
172 if [ x"$adt_'$1'_hostname" = x ] && \
173 [ x"$adt_'$1'_ipaddr" != x ]; then
174 printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
175 adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
176 printf "%s\n" "${adt_'$1'_hostname}"
181 hostname_from_ipaddr guest
182 hostname_from_ipaddr host
184 if [ x"$adt_host_hostname" = x ]; then
185 printf "finding host hostname, supposely our own FQDN: "
186 adt_host_hostname=`hostname -f`
187 printf "%s\n" "$adt_host_hostname"
190 if [ x"$adt_guest_hostname" = x ]; then
191 case "$adt_guests_domain" in
192 '') printf "guessing guest hostname from host hostname: "
193 adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;;
194 .*) printf "setting guest hostname using distro and nominum: "
195 adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;;
196 *) printf "setting guest hostname using distro and domain: "
197 adt_guest_hostname=$adt_distro.$adt_guests_domain ;;
199 printf "%s\n" "$adt_guest_hostname"
202 ipaddr_from_hostname () {
204 if [ x"$adt_'$1'_ipaddr" = x ] && \
205 [ x"$adt_'$1'_hostname" != x ]; then
206 printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
207 adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
208 echo "${adt_'$1'_ipaddr}"
213 ipaddr_from_hostname guest
214 ipaddr_from_hostname host
218 printf "looking for '$2' hook ... "
219 case "$adt_'$1'_hook" in
221 case "$adt_config" in
223 adt_'$1'_hook=${adt_config%_config}_'$3'
224 if test -e "$adt_'$1'_hook"; then
225 echo "default exists: $adt_'$1'_hook"
227 echo "default $adt_'$1'_hook is not a file, so: none"
232 echo "not specified, not computable from config, so: none"
238 if test -e "$adt_'$1'_hook"; then
239 echo "exists: $adt_'$1'_hook"
241 echo "specified as $adt_'$1'_hook, but not a file, so: none"
249 search_hook fw firewall fwhook
250 search_hook setup setup setuphook
254 case "${adt_'$1'}" in
255 y*|Y*|1*|t*) adt_'$1'=true ;;
256 n*|N*|0*|f*) adt_'$1'=false ;;
258 *) fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
264 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
265 : ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub}
266 : ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}}
267 : ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}}
270 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
272 # In-host-file-system playground
273 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
274 : ${adt_xmconfig:=${adt_play}/xmconfig}
275 : ${adt_lock:=${adt_play}/lock}
278 boolean_config lvm_erasebase true
279 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
280 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
281 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
283 : ${adt_fslink_dir:=adt-xenlvm}
284 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
287 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
289 lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
290 lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
292 lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
293 lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
295 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
297 lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name}
298 lvm_fslink_dirpath=/dev/${adt_fslink_dir}
299 lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name}
301 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"