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 $*"; "$@"; }
15 xl () { echo "xl $*"; 3>&- "$@"; }
17 case "$BASH_VERSION" in
18 '') fail 'scripts using adtxenlvm readconfig must be bash scripts' ;;
22 #---------- default values for simple settings ----------
25 : ${adt_testbed_ram:=256}
26 : ${adt_freeze_ram:=32}
27 : ${adt_fs_size:=3072M}
28 : ${adt_fs_snapsize:=2560M}
29 : ${adt_fs_cowchunk:=8}
30 : ${adt_playbase:=/var/lib/autopkgtest/xenlvm}
31 : ${adt_fs_type:=ext3}
32 : ${adt_fs_mkfs_args:=}
33 : ${adt_vm_reduce_retries:=10}
34 : ${adt_ssh_keytype:=dsa}
36 : ${adt_debootstrap_components:='*'}
37 : ${adt_debootstrap_include:=openssh-server,ed}
38 : ${adt_debootstrap_includemore:=}
39 : ${adt_debootstrap_mirrors:=}
40 : ${adt_debootstrap_script:=}
42 : ${adt_fw_localmirrors:=}
43 : ${adt_fw_prohibnets:=192.168.0.0/24 172.16.0.0/12 10.0.0.0/8}
44 : ${adt_fw_allowglobalports:=80}
46 : ${adt_guest_macaddr:=00:16:3e:7c:aa:7f}
47 : ${adt_net_vifscript:=/etc/xen/scripts/vif-route-adt}
48 : ${adt_normaluser:=adtxenu}
50 #---------- arguments and config file ----------
53 while [ $# -gt 0 ]; do
62 *-*) var="$(printf "%s" "$var" | tr -- - _)" ;;
68 *) fail "unknown configuration variable \`$var'" ;;
71 eval "adt_$var=\"\$value\"; export adt_$var"
75 -*) fail "unknown option \`$arg'" ;;
83 : "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
84 test ! -e "${adt_config}" || . "${adt_config}"
87 #---------- settings needed for locking ----------
89 # In-host-file-system playground
90 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
91 : ${adt_xmconfig:=${adt_play}/xmconfig}
92 : ${adt_lock:=${adt_play}.lock}
94 if [ ! "${adt_readconfig_initscript}" ]; then
97 printf "considering which distro to use ... "
98 test -e /etc/lsb-release || \
99 fail 'no /etc/lsb-version, config must specify adt_distro'
101 adt_distro=$DISTRIB_CODENAME
102 echo "using same distro as host: $adt_distro"
107 if [ "${adt_readconfig_needlock}" ] &&
108 [ "x${adt_lock}" != xnone ] && \
109 [ "x${ADT_LOCKED}" != "x$adt_lock" ]; then
110 if [ "${adt_whenlock_replumb81}" ]; then
113 ADT_LOCKED="$adt_lock" exec with-lock-ex -w "$adt_lock" "$0" "$@"
116 #---------- calculated defaults for complex settings ----------
118 if [ ! "${adt_readconfig_initscript}" ]; then
119 case "$adt_lvm_vg" in
121 printf "searching for default volume group ... "
122 vgdisplay_out=`vgdisplay -c 3>&- 8>&-`
123 case "$vgdisplay_out" in
124 "") fail 'no volume groups found';;
126 "*) fail 'several volume groups, config must specify which';;
128 adt_lvm_vg=${vgdisplay_out%%:*}
129 case "$adt_lvm_vg" in
130 *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
132 adt_lvm_vg=${adt_lvm_vg##* }
133 echo "using system's only volume group: $adt_lvm_vg"
138 if [ "$adt_readconfig_needkernel" ]; then
139 case "$adt_kernel" in
141 printf "searching for kernel ... "
142 for f in /boot/*"`uname -r`"*; do
143 test -e "$f" || continue
145 output="$(file -- "$f")"
147 *"gzip compressed data"*) ;;
148 *) printf "!gzip) "; continue ;;
150 trap 'rm -f -- "$tf"; exit 127' 0
153 output="$(file -- "$tf")"
155 *"ELF "*" executable,"*) ;;
156 *) printf "!ELF) "; continue;;
158 output="$(objdump -j __xen_guest -s -- "$tf")"
159 rm -f "$tf"; trap '' 0
161 *" __xen_guest:"*) ;;
162 *) printf "!Xen) "; continue
165 test "x$adt_kernel" = x || \
166 fail 'several kernels, config must specify which'
169 [ "x$adt_kernel" != x ] || \
170 fail 'could not find currently booted Xen kernel'
171 echo "using currently booted kernel: $adt_kernel"
175 case "$adt_ramdisk" in
176 none) echo "ramdisk \`none' specified, using static kernel"
178 '') adt_ramdisk="${adt_kernel/\/vmlinuz-//initrd.img-}"
179 test -e "$adt_ramdisk" || \
180 fail "calculated default ramdisk initrd.img \`$adt_ramdisk' does not exist"
181 echo "using calculated default ramdisk initrd.img: $adt_ramdisk" ;;
186 case "$adt_modules" in
187 '') adt_modules="/lib/modules/`uname -r`" ;;
191 hostname_from_ipaddr () {
193 if [ x"$adt_'$1'_hostname" = x ] && \
194 [ x"$adt_'$1'_ipaddr" != x ]; then
195 printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
196 adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
197 printf "%s\n" "${adt_'$1'_hostname}"
202 hostname_from_ipaddr host
204 if [ ! "${adt_readconfig_initscript}" ]; then
205 hostname_from_ipaddr guest
208 if [ x"$adt_host_hostname" = x ]; then
209 printf "finding host hostname, supposely our own FQDN: "
210 adt_host_hostname=`hostname -f`
211 printf "%s\n" "$adt_host_hostname"
214 if [ ! "${adt_readconfig_initscript}" ]; then
215 if [ x"$adt_guest_hostname" = x ]; then
216 case "$adt_guests_domain" in
217 '') printf "guessing guest hostname from host hostname: "
218 adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;;
219 .*) printf "setting guest hostname using distro and nominum: "
220 adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;;
221 *) printf "setting guest hostname using distro and domain: "
222 adt_guest_hostname=$adt_distro.$adt_guests_domain ;;
224 printf "%s\n" "$adt_guest_hostname"
228 ipaddr_from_hostname () {
230 if [ x"$adt_'$1'_ipaddr" = x ] && \
231 [ x"$adt_'$1'_hostname" != x ]; then
232 printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
233 adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
234 echo "${adt_'$1'_ipaddr}"
239 ipaddr_from_hostname host
240 if [ ! "${adt_readconfig_initscript}" ]; then
241 ipaddr_from_hostname guest
246 printf "looking for '$2' hook ... "
247 case "$adt_'$1'_hook" in
249 case "$adt_config" in
251 adt_'$1'_hook=${adt_config%_config}_'$3'
252 if test -e "$adt_'$1'_hook"; then
253 echo "default exists: $adt_'$1'_hook"
255 echo "default $adt_'$1'_hook is not a file, so: none"
260 echo "not specified, not computable from config, so: none"
266 if test -e "$adt_'$1'_hook"; then
267 echo "exists: $adt_'$1'_hook"
269 echo "specified as $adt_'$1'_hook, but not a file, so: none"
277 search_hook fw firewall fwhook
278 search_hook setup setup setuphook
279 search_hook sshauthkeys "ssh auth keys" sshauthkeys
283 case "${adt_'$1'}" in
284 y*|Y*|1*|t*) adt_'$1'=true ;;
285 n*|N*|0*|f*) adt_'$1'=false ;;
287 *) fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
293 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
294 : ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub}
295 : ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}}
296 : ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}}
299 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
302 boolean_config lvm_erasebase true
303 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
304 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
305 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
307 : ${adt_fslink_dir:=adt-xenlvm}
308 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
311 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
313 lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
314 lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
316 lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
317 lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
319 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
321 lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name}
322 lvm_fslink_dirpath=/dev/${adt_fslink_dir}
323 lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name}
325 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"