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 "x $*"; 3>&- 4>&- "$@"; }
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:=6144M}
28 : ${adt_fs_snapsize:=5120M}
29 : ${adt_fs_cowchunk:=8}
30 : ${adt_swap_size:=5120M}
31 : ${adt_playbase:=/var/lib/autopkgtest/xenlvm}
32 : ${adt_fs_type:=ext3}
33 : ${adt_fs_mkfs_args:=}
34 : ${adt_vm_reduce_retries:=10}
35 : ${adt_ssh_keytype:=dsa}
37 : ${adt_debootstrap_opts:=}
38 : ${adt_debootstrap_components:='*'}
39 : ${adt_debootstrap_include:=openssh-server,ed}
40 : ${adt_debootstrap_includemore:=}
41 : ${adt_debootstrap_mirrors:=}
42 : ${adt_debootstrap_script:=}
44 : ${adt_fw_localmirrors:=}
45 : ${adt_fw_prohibnets:=192.168.0.0/24 172.16.0.0/12 10.0.0.0/8}
46 : ${adt_fw_allowglobalports:=80}
48 : ${adt_guest_macaddr:=00:16:3e:7c:aa:7f}
49 : ${adt_net_vifscript:=/etc/xen/scripts/vif-route-adt}
50 : ${adt_normaluser:=adtxenu}
52 #---------- arguments and config file ----------
55 while [ $# -gt 0 ]; do
64 *-*) var="$(printf "%s" "$var" | tr -- - _)" ;;
70 *) fail "unknown configuration variable \`$var'" ;;
73 eval "adt_$var=\"\$value\"; export adt_$var"
77 -*) fail "unknown option \`$arg'" ;;
85 : "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
86 test ! -e "${adt_config}" || . "${adt_config}"
89 #---------- settings needed for locking ----------
91 if [ ! "${adt_readconfig_initscript}" ]; then
94 printf "considering which distro to use ... "
95 test -e /etc/lsb-release || \
96 fail 'no /etc/lsb-version, config must specify adt_distro'
98 adt_distro=$DISTRIB_CODENAME
99 echo "using same distro as host: $adt_distro"
104 # In-host-file-system playground
105 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
106 : ${adt_xmconfig:=${adt_play}/xmconfig}
107 : ${adt_lock:=${adt_play}.lock}
109 if [ "${adt_readconfig_needlock}" ] &&
110 [ "x${adt_lock}" != xnone ] && \
111 [ "x${ADT_LOCKED}" != "x$adt_lock" ]; then
112 if [ "${adt_whenlock_replumb81}" ]; then
115 ADT_LOCKED="$adt_lock" exec with-lock-ex -w "$adt_lock" "$0" "$@"
118 #---------- calculated defaults for complex settings ----------
120 if [ ! "${adt_readconfig_initscript}" ]; then
121 case "$adt_lvm_vg" in
123 printf "searching for default volume group ... "
124 vgdisplay_out=`vgdisplay -c 3>&- 8>&-`
125 case "$vgdisplay_out" in
126 "") fail 'no volume groups found';;
128 "*) fail 'several volume groups, config must specify which';;
130 adt_lvm_vg=${vgdisplay_out%%:*}
131 case "$adt_lvm_vg" in
132 *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
134 adt_lvm_vg=${adt_lvm_vg##* }
135 echo "using system's only volume group: $adt_lvm_vg"
140 if [ "$adt_readconfig_needkernel" ]; then
141 case "$adt_kernel" in
143 printf "searching for kernel ... "
144 for f in /boot/*"`uname -r`"*; do
145 test -e "$f" || continue
147 output="$(file -- "$f")"
149 *"gzip compressed data"*) ;;
150 *) printf "!gzip) "; continue ;;
152 trap 'rm -f -- "$tf"; exit 127' 0
155 output="$(file -- "$tf")"
157 *"ELF "*" executable,"*) ;;
158 *) printf "!ELF) "; continue;;
160 output="$(objdump -j __xen_guest -s -- "$tf")"
161 rm -f "$tf"; trap '' 0
163 *" __xen_guest:"*) ;;
164 *) printf "!Xen) "; continue
167 test "x$adt_kernel" = x || \
168 fail 'several kernels, config must specify which'
171 [ "x$adt_kernel" != x ] || \
172 fail 'could not find currently booted Xen kernel'
173 echo "using currently booted kernel: $adt_kernel"
177 case "$adt_ramdisk" in
178 none) echo "ramdisk \`none' specified, using static kernel"
180 '') adt_ramdisk="${adt_kernel/\/vmlinuz-//initrd.img-}"
181 test -e "$adt_ramdisk" || \
182 fail "calculated default ramdisk initrd.img \`$adt_ramdisk' does not exist"
183 echo "using calculated default ramdisk initrd.img: $adt_ramdisk" ;;
188 case "$adt_modules" in
189 '') adt_modules="/lib/modules/`uname -r`" ;;
193 hostname_from_ipaddr () {
195 if [ x"$adt_'$1'_hostname" = x ] && \
196 [ x"$adt_'$1'_ipaddr" != x ]; then
197 printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
198 adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
199 printf "%s\n" "${adt_'$1'_hostname}"
204 hostname_from_ipaddr host
206 if [ ! "${adt_readconfig_initscript}" ]; then
207 hostname_from_ipaddr guest
210 if [ x"$adt_host_hostname" = x ]; then
211 printf "finding host hostname, supposely our own FQDN: "
212 adt_host_hostname=`hostname -f`
213 printf "%s\n" "$adt_host_hostname"
216 if [ ! "${adt_readconfig_initscript}" ]; then
217 if [ x"$adt_guest_hostname" = x ]; then
218 case "$adt_guests_domain" in
219 '') printf "guessing guest hostname from host hostname: "
220 adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;;
221 .*) printf "setting guest hostname using distro and nominum: "
222 adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;;
223 *) printf "setting guest hostname using distro and domain: "
224 adt_guest_hostname=$adt_distro.$adt_guests_domain ;;
226 printf "%s\n" "$adt_guest_hostname"
230 ipaddr_from_hostname () {
232 if [ x"$adt_'$1'_ipaddr" = x ] && \
233 [ x"$adt_'$1'_hostname" != x ]; then
234 printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
235 adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
236 echo "${adt_'$1'_ipaddr}"
241 ipaddr_from_hostname host
242 if [ ! "${adt_readconfig_initscript}" ]; then
243 ipaddr_from_hostname guest
248 printf "looking for '$2' hook ... "
249 case "$adt_'$1'_hook" in
251 case "$adt_config" in
253 adt_'$1'_hook=${adt_config%_config}_'$3'
254 if test -e "$adt_'$1'_hook"; then
255 echo "default exists: $adt_'$1'_hook"
257 echo "default $adt_'$1'_hook is not a file, so: none"
262 echo "not specified, not computable from config, so: none"
268 if test -e "$adt_'$1'_hook"; then
269 echo "exists: $adt_'$1'_hook"
271 echo "specified as $adt_'$1'_hook, but not a file, so: none"
279 search_hook fw firewall fwhook
280 search_hook setup setup setuphook
281 search_hook sshauthkeys "ssh auth keys" sshauthkeys
285 case "${adt_'$1'}" in
286 y*|Y*|1*|t*) adt_'$1'=true ;;
287 n*|N*|0*|f*) adt_'$1'=false ;;
289 *) fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
295 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
296 : ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub}
297 : ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}}
298 : ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}}
301 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
304 boolean_config lvm_erasebase true
306 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
307 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
308 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
310 : ${adt_fslink_dir:=adt-xenlvm}
311 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
314 : ${adt_lvm_eraseswap:=$adt_lvm_erasebase}
316 : ${adt_lvm_swapbaselv:=${adt_nominum}_${adt_distro}_swapbase}
317 : ${adt_lvm_swapcowdatalv:=${adt_nominum}_${adt_distro}_swapcowdata}
318 : ${adt_devmapper_swapcowdev:=${adt_nominum}_${adt_distro}_swapsnap}
320 : ${adt_swaplink_dir:=adt-xenlvm}
321 : ${adt_swaplink_name:=${adt_nominum}_${adt_distro}_swap}
323 : ${adt_lvm_swapvg:=$adt_lvm_vg}
325 : ${adt_swap_snapsize:=$adt_swap_size}
326 : ${adt_swap_cowchunk:=$adt_fs_cowchunk}
328 case "$adt_swap_size" in
329 *[!0A-Za-z]*) provide_swap=true ;;
330 *) provide_swap=false ;;
334 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
336 for fs in fs swap; do swap=${fs#fs}; eval "
337 lvm_baselv_${swap}namerhs=\${adt_lvm_${swap}vg}/\${adt_lvm_${swap}baselv}
338 lvm_baselv_${swap}namepath=/dev/\${lvm_baselv_${swap}namerhs}
340 lvm_cowdata_${swap}namerhs=\${adt_lvm_${swap}vg}/\${adt_lvm_${swap}cowdatalv}
341 lvm_cowdata_${swap}namepath=/dev/\${lvm_cowdata_${swap}namerhs}
343 lvm_${swap}snapdev=/dev/mapper/\${adt_devmapper_${swap}cowdev}
345 lvm_${fs}link_ptrrhs=\${adt_${fs}link_dir}/\${adt_${fs}link_name}
346 lvm_${fs}link_dirpath=/dev/\${adt_${fs}link_dir}
347 lvm_${fs}link_ptr=/dev/\${adt_${fs}link_dir}/\${adt_${fs}link_name}
351 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"