chiark / gitweb /
* xenlvm command-line settings properly override config file
[autopkgtest.git] / xen / readconfig.in
1 # This bash script is sourced by the various tools to set the
2 # adt_... variables and some other useful ones.
3
4 set -e${ADT_SHELLX}
5 set -o pipefail
6
7 #---------- useful general functions ----------
8
9 fail () {
10         echo >&2 "xenlvm: ${0##*/}: error: $*"
11         exit 16
12 }
13
14 x () { echo "x $*"; "$@"; }
15 xl () { echo "x $*"; 3>&- 4>&- "$@"; }
16
17 case "$BASH_VERSION" in
18 '')     fail 'scripts using adtxenlvm readconfig must be bash scripts' ;;
19 *)      ;;
20 esac
21
22 #---------- default values for simple settings ----------
23
24 : ${adt_nominum:=adt}
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}
35
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:=}
42
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}
46
47 : ${adt_guest_macaddr:=00:16:3e:7c:aa:7f}
48 : ${adt_net_vifscript:=/etc/xen/scripts/vif-route-adt}
49 : ${adt_normaluser:=adtxenu}
50
51 #---------- arguments and config file ----------
52
53 cmdline_args () {
54         while [ $# -gt 0 ]; do
55                 arg="$1"
56                 case "$arg" in
57                 --*=*)
58                         value="${arg#*=}"
59
60                         var=${arg%%=*}
61                         var=${var#--}
62                         case "$var" in
63                         *-*)    var="$(printf "%s" "$var" | tr -- - _)" ;;
64                         esac
65                         var=${var#adt_}
66
67                         case $var in
68                         *) ;; # @@varlist@@
69                         *) fail "unknown configuration variable \`$var'" ;;
70                         esac
71
72                         eval "adt_$var=\"\$value\"; export adt_$var"
73                         shift ;;
74
75                 --)     shift; break ;;
76                 -*)     fail "unknown option \`$arg'" ;;
77                 *)      break ;;
78                 esac
79         done
80         nonoptargs=$#
81 }
82
83 cmdline_args "$@"
84 : "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
85 test ! -e "${adt_config}" || . "${adt_config}"
86 cmdline_args "$@"
87
88 #---------- settings needed for locking ----------
89
90 if [ ! "${adt_readconfig_initscript}" ]; then
91  case "$adt_distro" in
92  '')
93         printf "considering which distro to use ... "
94         test -e /etc/lsb-release || \
95                 fail 'no /etc/lsb-version, config must specify adt_distro'
96         . /etc/lsb-release
97         adt_distro=$DISTRIB_CODENAME
98         echo "using same distro as host: $adt_distro"
99         ;;
100  esac
101 fi
102
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}
107
108 if [ "${adt_readconfig_needlock}" ] &&
109    [ "x${adt_lock}" != xnone ] && \
110    [ "x${ADT_LOCKED}" != "x$adt_lock" ]; then
111  if [ "${adt_whenlock_replumb81}" ]; then
112    exec >&8 8>&-
113  fi
114  ADT_LOCKED="$adt_lock" exec with-lock-ex -w "$adt_lock" "$0" "$@"
115 fi
116
117 #---------- calculated defaults for complex settings ----------
118
119 if [ ! "${adt_readconfig_initscript}" ]; then
120  case "$adt_lvm_vg" in
121  '')
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';;
126         *"
127  "*)            fail 'several volume groups, config must specify which';;
128         esac
129         adt_lvm_vg=${vgdisplay_out%%:*}
130         case "$adt_lvm_vg" in
131         *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
132         esac
133         adt_lvm_vg=${adt_lvm_vg##* }
134         echo "using system's only volume group: $adt_lvm_vg"
135         ;;
136  esac
137 fi
138
139 if [ "$adt_readconfig_needkernel" ]; then
140  case "$adt_kernel" in
141  '')
142         printf "searching for kernel ... "
143         for f in /boot/*"`uname -r`"*; do
144                 test -e "$f" || continue
145                 printf "(%s:" "$f"
146                 output="$(file -- "$f")"
147                 case "$output" in
148                 *"gzip compressed data"*) ;;
149                 *) printf "!gzip) "; continue ;;
150                 esac
151                 trap 'rm -f -- "$tf"; exit 127' 0
152                 tf=`mktemp -t`
153                 zcat -- "$f" >"$tf"
154                 output="$(file -- "$tf")"
155                 case "$output" in
156                 *"ELF "*" executable,"*) ;;
157                 *) printf "!ELF) "; continue;;
158                 esac
159                 output="$(objdump -j __xen_guest -s -- "$tf")"
160                 rm -f "$tf"; trap '' 0
161                 case "$output" in
162                 *" __xen_guest:"*) ;;
163                 *) printf "!Xen) "; continue
164                 esac
165                 printf "y) "
166                 test "x$adt_kernel" = x || \
167                         fail 'several kernels, config must specify which'
168                 adt_kernel="$f"
169         done
170         [ "x$adt_kernel" != x ] || \
171                 fail 'could not find currently booted Xen kernel'
172         echo "using currently booted kernel: $adt_kernel"
173         ;;
174  esac
175
176  case "$adt_ramdisk" in
177  none)  echo "ramdisk \`none' specified, using static kernel"
178         adt_ramdisk='' ;;
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" ;;
183  *)     ;;
184  esac
185 fi
186
187 case "$adt_modules" in
188 '')     adt_modules="/lib/modules/`uname -r`" ;;
189 *)      ;;
190 esac
191
192 hostname_from_ipaddr () {
193  eval '
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}"
199   fi
200  '
201 }
202
203 hostname_from_ipaddr host
204
205 if [ ! "${adt_readconfig_initscript}" ]; then
206  hostname_from_ipaddr guest
207 fi
208
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"
213 fi
214
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 ;;
224         esac
225         printf "%s\n" "$adt_guest_hostname"
226  fi
227 fi
228
229 ipaddr_from_hostname () {
230  eval '
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}"
236   fi
237  '
238 }
239
240 ipaddr_from_hostname host
241 if [ ! "${adt_readconfig_initscript}" ]; then
242  ipaddr_from_hostname guest
243 fi
244
245 search_hook () {
246  eval '
247   printf "looking for '$2' hook ... "
248   case "$adt_'$1'_hook" in
249   "")
250     case "$adt_config" in
251     *_config)
252       adt_'$1'_hook=${adt_config%_config}_'$3'
253       if test -e "$adt_'$1'_hook"; then
254               echo "default exists: $adt_'$1'_hook"
255       else
256               echo "default $adt_'$1'_hook is not a file, so: none"
257               adt_'$1'_hook=""
258       fi
259       ;;
260     *)
261       echo "not specified, not computable from config, so: none"
262       adt_'$1'_hook=""
263       ;;
264     esac
265     ;;
266   *)
267     if test -e "$adt_'$1'_hook"; then
268       echo "exists: $adt_'$1'_hook"
269     else
270       echo "specified as $adt_'$1'_hook, but not a file, so: none"
271       adt_'$1'_hook=""
272     fi
273     ;;
274   esac
275  '
276 }
277
278 search_hook fw firewall fwhook
279 search_hook setup setup setuphook
280 search_hook sshauthkeys "ssh auth keys" sshauthkeys
281
282 boolean_config () {
283   eval '
284     case "${adt_'$1'}" in
285     y*|Y*|1*|t*)        adt_'$1'=true ;;
286     n*|N*|0*|f*)        adt_'$1'=false ;;
287     "")                 adt_'$1'=$2 ;;
288     *)                  fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
289     esac
290   '
291 }
292
293 # SSH
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}}
298
299 # Xen
300 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
301
302 # LVM
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}
307
308 : ${adt_fslink_dir:=adt-xenlvm}
309 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
310
311 # Firewall
312 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
313
314 lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
315 lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
316
317 lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
318 lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
319
320 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
321
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}
325
326 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"