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:=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_opts:=}
37 : ${adt_debootstrap_components:='*'}
38 : ${adt_debootstrap_include:=openssh-server,ed}
39 : ${adt_debootstrap_includemore:=}
40 : ${adt_debootstrap_mirrors:=}
41 : ${adt_debootstrap_script:=}
43 : ${adt_fw_localmirrors:=}
44 : ${adt_fw_prohibnets:=192.168.0.0/24 172.16.0.0/12 10.0.0.0/8}
45 : ${adt_fw_allowglobalports:=80}
47 : ${adt_guest_macaddr:=00:16:3e:7c:aa:7f}
48 : ${adt_net_vifscript:=/etc/xen/scripts/vif-route-adt}
49 : ${adt_normaluser:=adtxenu}
51 #---------- arguments and config file ----------
54 while [ $# -gt 0 ]; do
63 *-*) var="$(printf "%s" "$var" | tr -- - _)" ;;
69 *) fail "unknown configuration variable \`$var'" ;;
72 eval "adt_$var=\"\$value\"; export adt_$var"
76 -*) fail "unknown option \`$arg'" ;;
84 : "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
85 test ! -e "${adt_config}" || . "${adt_config}"
88 #---------- settings needed for locking ----------
90 if [ ! "${adt_readconfig_initscript}" ]; then
93 printf "considering which distro to use ... "
94 test -e /etc/lsb-release || \
95 fail 'no /etc/lsb-version, config must specify adt_distro'
97 adt_distro=$DISTRIB_CODENAME
98 echo "using same distro as host: $adt_distro"
103 # In-host-file-system playground
104 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
105 : ${adt_xmconfig:=${adt_play}/xmconfig}
106 : ${adt_lock:=${adt_play}.lock}
108 if [ "${adt_readconfig_needlock}" ] &&
109 [ "x${adt_lock}" != xnone ] && \
110 [ "x${ADT_LOCKED}" != "x$adt_lock" ]; then
111 if [ "${adt_whenlock_replumb81}" ]; then
114 ADT_LOCKED="$adt_lock" exec with-lock-ex -w "$adt_lock" "$0" "$@"
117 #---------- calculated defaults for complex settings ----------
119 if [ ! "${adt_readconfig_initscript}" ]; then
120 case "$adt_lvm_vg" in
122 printf "searching for default volume group ... "
123 vgdisplay_out=`vgdisplay -c 3>&- 8>&-`
124 case "$vgdisplay_out" in
125 "") fail 'no volume groups found';;
127 "*) fail 'several volume groups, config must specify which';;
129 adt_lvm_vg=${vgdisplay_out%%:*}
130 case "$adt_lvm_vg" in
131 *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
133 adt_lvm_vg=${adt_lvm_vg##* }
134 echo "using system's only volume group: $adt_lvm_vg"
139 if [ "$adt_readconfig_needkernel" ]; then
140 case "$adt_kernel" in
142 printf "searching for kernel ... "
143 for f in /boot/*"`uname -r`"*; do
144 test -e "$f" || continue
146 output="$(file -- "$f")"
148 *"gzip compressed data"*) ;;
149 *) printf "!gzip) "; continue ;;
151 trap 'rm -f -- "$tf"; exit 127' 0
154 output="$(file -- "$tf")"
156 *"ELF "*" executable,"*) ;;
157 *) printf "!ELF) "; continue;;
159 output="$(objdump -j __xen_guest -s -- "$tf")"
160 rm -f "$tf"; trap '' 0
162 *" __xen_guest:"*) ;;
163 *) printf "!Xen) "; continue
166 test "x$adt_kernel" = x || \
167 fail 'several kernels, config must specify which'
170 [ "x$adt_kernel" != x ] || \
171 fail 'could not find currently booted Xen kernel'
172 echo "using currently booted kernel: $adt_kernel"
176 case "$adt_ramdisk" in
177 none) echo "ramdisk \`none' specified, using static kernel"
179 '') adt_ramdisk="${adt_kernel/\/vmlinuz-//initrd.img-}"
180 test -e "$adt_ramdisk" || \
181 fail "calculated default ramdisk initrd.img \`$adt_ramdisk' does not exist"
182 echo "using calculated default ramdisk initrd.img: $adt_ramdisk" ;;
187 case "$adt_modules" in
188 '') adt_modules="/lib/modules/`uname -r`" ;;
192 hostname_from_ipaddr () {
194 if [ x"$adt_'$1'_hostname" = x ] && \
195 [ x"$adt_'$1'_ipaddr" != x ]; then
196 printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
197 adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
198 printf "%s\n" "${adt_'$1'_hostname}"
203 hostname_from_ipaddr host
205 if [ ! "${adt_readconfig_initscript}" ]; then
206 hostname_from_ipaddr guest
209 if [ x"$adt_host_hostname" = x ]; then
210 printf "finding host hostname, supposely our own FQDN: "
211 adt_host_hostname=`hostname -f`
212 printf "%s\n" "$adt_host_hostname"
215 if [ ! "${adt_readconfig_initscript}" ]; then
216 if [ x"$adt_guest_hostname" = x ]; then
217 case "$adt_guests_domain" in
218 '') printf "guessing guest hostname from host hostname: "
219 adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;;
220 .*) printf "setting guest hostname using distro and nominum: "
221 adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;;
222 *) printf "setting guest hostname using distro and domain: "
223 adt_guest_hostname=$adt_distro.$adt_guests_domain ;;
225 printf "%s\n" "$adt_guest_hostname"
229 ipaddr_from_hostname () {
231 if [ x"$adt_'$1'_ipaddr" = x ] && \
232 [ x"$adt_'$1'_hostname" != x ]; then
233 printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
234 adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
235 echo "${adt_'$1'_ipaddr}"
240 ipaddr_from_hostname host
241 if [ ! "${adt_readconfig_initscript}" ]; then
242 ipaddr_from_hostname guest
247 printf "looking for '$2' hook ... "
248 case "$adt_'$1'_hook" in
250 case "$adt_config" in
252 adt_'$1'_hook=${adt_config%_config}_'$3'
253 if test -e "$adt_'$1'_hook"; then
254 echo "default exists: $adt_'$1'_hook"
256 echo "default $adt_'$1'_hook is not a file, so: none"
261 echo "not specified, not computable from config, so: none"
267 if test -e "$adt_'$1'_hook"; then
268 echo "exists: $adt_'$1'_hook"
270 echo "specified as $adt_'$1'_hook, but not a file, so: none"
278 search_hook fw firewall fwhook
279 search_hook setup setup setuphook
280 search_hook sshauthkeys "ssh auth keys" sshauthkeys
284 case "${adt_'$1'}" in
285 y*|Y*|1*|t*) adt_'$1'=true ;;
286 n*|N*|0*|f*) adt_'$1'=false ;;
288 *) fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
294 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
295 : ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub}
296 : ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}}
297 : ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}}
300 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
303 boolean_config lvm_erasebase true
304 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
305 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
306 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
308 : ${adt_fslink_dir:=adt-xenlvm}
309 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
312 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
314 lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
315 lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
317 lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
318 lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
320 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
322 lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name}
323 lvm_fslink_dirpath=/dev/${adt_fslink_dir}
324 lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name}
326 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"