chiark / gitweb /
more sensible snap size; purge really purges; update and install gdebi in fixup
[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
16 case "$BASH_VERSION" in
17 '')     fail 'scripts using adtxenlvm readconfig must be bash scripts' ;;
18 *)      ;;
19 esac
20
21 #---------- default values for simple settings ----------
22
23 adt_nominum=adt
24 adt_testbed_ram=256
25 adt_freeze_ram=32
26 adt_fs_size=3072M
27 adt_fs_snapsize=2560M
28 adt_fs_cowchunk=8
29 adt_playbase=/var/lib/autopkgtest/xenlvm
30 adt_fs_type=ext3
31 adt_fs_mkfs_args=''
32 adt_vm_reduce_retries=10
33 adt_ssh_keytype=dsa
34
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=''
40
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'
44
45 adt_guest_macaddr=00:16:3e:7c:aa:7f
46 adt_net_vifscript=/etc/xen/scripts/vif-route-adt
47 adt_normaluser=adtxenlvm
48
49 #---------- arguments and config file ----------
50
51 cmdline_args () {
52         while [ $# -gt 0 ]; do
53                 arg="$1"
54                 case "$arg" in
55                 --*=*)
56                         value="${arg#*=}"
57
58                         var=${arg%%=*}
59                         var=${var#--}
60                         case "$var" in
61                         *-*)    var="$(printf "%s" "$var" | tr -- - _)" ;;
62                         esac
63                         var=${var#adt_}
64
65                         case $var in
66                         *) ;; # @@varlist@@
67                         *) fail "unknown configuration variable \`$var'" ;;
68                         esac
69
70                         eval "$var=\"\$value\""
71                         shift ;;
72
73                 --)     shift; break ;;
74                 -*)     fail "unknown option \`$arg'" ;;
75                 *)      break ;;
76                 esac
77         done
78         nonoptargs=$#
79 }
80
81 cmdline_args "$@"
82 : "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
83 test ! -e "${adt_config}" || . "${adt_config}"
84 cmdline_args "$@"
85
86 #---------- calculated defaults for complex settings ----------
87
88 case "$adt_lvm_vg" in
89 '')
90         printf "searching for default volume group ... "
91         vgdisplay_out=`vgdisplay -c 10>&-`
92         case "$vgdisplay_out" in
93         "")     fail 'no volume groups found';;
94         *"
95 "*)             fail 'several volume groups, config must specify which';;
96         esac
97         adt_lvm_vg=${vgdisplay_out%%:*}
98         case "$adt_lvm_vg" in
99         *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
100         esac
101         adt_lvm_vg=${adt_lvm_vg##* }
102         echo "using system's only volume group: $adt_lvm_vg"
103         ;;
104 esac
105
106 case "$adt_kernel" in
107 '')
108         printf "searching for kernel ... "
109         for f in /boot/xen*"`uname -r`"; do
110                 test -e "$f" || continue
111                 test "x$adt_kernel" = x || \
112                         fail 'several kernels, config must specify which'
113                 adt_kernel="$f"
114         done
115         echo "using currently booted kernel: $adt_kernel"
116         ;;
117 esac
118
119 case "$adt_ramdisk" in
120 none)   echo "ramdisk \`none' specified, using static kernel"
121         adt_ramdisk='' ;;
122 '')     adt_ramdisk="$adt_kernel.initrd.img"
123         echo "using default ramdisk <kernel>.initrd.img: $adt_ramdisk" ;;
124 *)      ;;
125 esac
126
127 case "$adt_modules" in
128 '')     adt_modules="/lib/modules/`uname -r`" ;;
129 *)      ;;
130 esac
131
132 case "$adt_distro" in
133 '')
134         printf "considering which distro to use ... "
135         test -e /etc/lsb-release || \
136                 fail 'no /etc/lsb-version, config must specify adt_distro'
137         . /etc/lsb-release
138         adt_distro=$DISTRIB_CODENAME
139         echo "using same distro as host: $adt_distro"
140         ;;
141 esac
142
143 hostname_from_ipaddr () {
144  eval '
145   if [ x"$adt_'$1'_hostname" = x ] && \
146      [ x"$adt_'$1'_ipaddr" != x ]; then
147    printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
148    adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
149    printf "%s\n" "${adt_'$1'_hostname}"
150   fi
151  '
152 }
153
154 hostname_from_ipaddr guest
155 hostname_from_ipaddr host
156
157 if [ x"$adt_host_hostname" = x ]; then
158         printf "finding host hostname, supposely our own FQDN: "
159         adt_host_hostname=`hostname -f`
160         printf "%s\n" "$adt_host_hostname"
161 fi
162
163 if [ x"$adt_guest_hostname" = x ]; then
164         case "$adt_guests_domain" in
165         '')     printf "guessing guest hostname from host hostname: "
166  adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;;
167         .*)     printf "setting guest hostname using distro and nominum: "
168  adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;;
169         *)      printf "setting guest hostname using distro and domain: "
170  adt_guest_hostname=$adt_distro.$adt_guests_domain ;;
171         esac
172         printf "%s\n" "$adt_guest_hostname"
173 fi
174
175 ipaddr_from_hostname () {
176  eval '
177   if [ x"$adt_'$1'_ipaddr" = x ] && \
178      [ x"$adt_'$1'_hostname" != x ]; then
179    printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
180    adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
181    echo "${adt_'$1'_ipaddr}"
182   fi
183  '
184 }
185
186 ipaddr_from_hostname guest
187 ipaddr_from_hostname host
188
189 search_hook () {
190  eval '
191   printf "looking for '$2' hook ... "
192   case "$adt_'$1'_hook" in
193   "")
194     case "$adt_config" in
195     *_config)
196       adt_'$1'_hook=${adt_config%_config}_'$3'
197       if test -e "$adt_'$1'_hook"; then
198               echo "default exists: $adt_'$1'_hook"
199       else
200               echo "default $adt_'$1'_hook is not a file, so: none"
201               adt_'$1'_hook=""
202       fi
203       ;;
204     *)
205       echo "not specified, not computable from config, so: none"
206       adt_'$1'_hook=""
207       ;;
208     esac
209     ;;
210   *)
211     if test -e "$adt_'$1'_hook"; then
212       echo "exists: $adt_'$1'_hook"
213     else
214       echo "specified as $adt_'$1'_hook, but not a file, so: none"
215       adt_'$1'_hook=""
216     fi
217     ;;
218   esac
219  '
220 }
221
222 search_hook fw firewall fwhook
223 search_hook setup setup setuphook
224
225 boolean_config () {
226   eval '
227     case "${adt_'$1'}" in
228     y*|Y*|1*|t*)        adt_'$1'=true ;;
229     n*|N*|0*|f*)        adt_'$1'=false ;;
230     "")                 adt_'$1'=$2 ;;
231     *)                  fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
232     esac
233   '
234 }
235
236 # SSH
237 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
238 : ${adt_ssh_pubkey:=${adt_ssh_privkey}.pub}
239 : ${adt_ssh_keyident_args:=-i ${adt_ssh_privkey}}
240 : ${adt_ssh_keygen_args:=-t ${adt_ssh_keytype}}
241
242 # Xen
243 : ${adt_xmname:=${adt_nominum}_${adt_distro}}
244
245 # In-host-file-system playground
246 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
247 : ${adt_xmconfig:=${adt_play}/xmconfig}
248 : ${adt_lock:=${adt_play}/lock}
249
250 # LVM
251 boolean_config lvm_erasebase true
252 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
253 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
254 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
255
256 : ${adt_fslink_dir:=adt-xenlvm}
257 : ${adt_fslink_name:=${adt_nominum}_${adt_distro}_fs}
258
259 # Firewall
260 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
261
262 lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
263 lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
264
265 lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
266 lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
267
268 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
269
270 lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name}
271 lvm_fslink_dirpath=/dev/${adt_fslink_dir}
272 lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name}
273
274 echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"