chiark / gitweb /
* Truncate files when writing them (copyup, copydown, etc) (!)
[autopkgtest.git] / xen / readconfig.in
index 19598d3c2954993712805de45b17d385fc7b5cb3..cbd3e85be4a6a6c02a9493e18667a3413dfac9b8 100644 (file)
@@ -1,6 +1,9 @@
 # This bash script is sourced by the various tools to set the
 # adt_... variables and some other useful ones.
 
+set -e${ADT_SHELLX}
+set -o pipefail
+
 #---------- useful general functions ----------
 
 fail () {
@@ -8,13 +11,20 @@ fail () {
        exit 16
 }
 
+x () { echo "x $*"; "$@"; }
+
+case "$BASH_VERSION" in
+'')    fail 'scripts using adtxenlvm readconfig must be bash scripts' ;;
+*)     ;;
+esac
+
 #---------- default values for simple settings ----------
 
 adt_nominum=adt
 adt_testbed_ram=256
 adt_freeze_ram=32
-adt_fs_size=1G
-adt_fs_snapsize=100M
+adt_fs_size=3072M
+adt_fs_snapsize=2560M
 adt_fs_cowchunk=8
 adt_playbase=/var/lib/autopkgtest/xenlvm
 adt_fs_type=ext3
@@ -22,12 +32,19 @@ adt_fs_mkfs_args=''
 adt_vm_reduce_retries=10
 adt_ssh_keytype=dsa
 
+adt_debootstrap_components='*'
+adt_debootstrap_include=libc6-xen,openssh-server,ed
+adt_debootstrap_includemore=
+adt_debootstrap_mirrors=''
+adt_debootstrap_script=''
+
 adt_fw_localmirrors=''
 adt_fw_prohibnets='192.168.0.0/24 172.16.0.0/12 10.0.0.0/8'
 adt_fw_allowglobalports='80'
 
 adt_guest_macaddr=00:16:3e:7c:aa:7f
 adt_net_vifscript=/etc/xen/scripts/vif-route-adt
+adt_normaluser=adtxenu
 
 #---------- arguments and config file ----------
 
@@ -50,70 +67,103 @@ cmdline_args () {
                        *) fail "unknown configuration variable \`$var'" ;;
                        esac
 
-                       eval "$var=\"\$value\""
+                       eval "adt_$var=\"\$value\""
                        shift ;;
 
-               --)     break ;;
+               --)     shift; break ;;
                -*)     fail "unknown option \`$arg'" ;;
-               *)      shift; break ;;
+               *)      break ;;
                esac
        done
-       test $# = 0 || fail "non-option arguments not allowed"
+       nonoptargs=$#
 }
 
-cmdline_args
-. ${adt_config}
-cmdline_args
+cmdline_args "$@"
+: "${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}"
+test ! -e "${adt_config}" || . "${adt_config}"
+cmdline_args "$@"
 
 #---------- calculated defaults for complex settings ----------
 
 case "$adt_lvm_vg" in
 '')
-       echo "searching for default volume group ..."
-       vgdisplay_out=`vgdisplay -c`
+       printf "searching for default volume group ... "
+       vgdisplay_out=`vgdisplay -c 10>&-`
        case "$vgdisplay_out" in
        "")     fail 'no volume groups found';;
        *"
 "*)            fail 'several volume groups, config must specify which';;
        esac
-       $adt_lvm_vg=${vgdisplay_out%%:*}
-       echo "system has one volume group, $adt_vg, using that."
+       adt_lvm_vg=${vgdisplay_out%%:*}
+       case "$adt_lvm_vg" in
+       *[^\ ]\ *) fail "volume group name \`$adt_lvm_vg' has spaces!";;
+       esac
+       adt_lvm_vg=${adt_lvm_vg##* }
+       echo "using system's only volume group: $adt_lvm_vg"
        ;;
 esac
 
-case "$adt_kernel" in
-'')
-       echo "searching for kernel ..."
-       for f in /boot/xen*"`uname -r`"; do
-               test -f "$f" || continue
+if [ "$adt_readconfig_needkernel" ]; then
+ case "$adt_kernel" in
+ '')
+       printf "searching for kernel ... "
+       for f in /boot/*"`uname -r`"*; do
+               test -e "$f" || continue
+               printf "(%s:" "$f"
+               output="$(file -- "$f")"
+               case "$output" in
+               *"gzip compressed data"*) ;;
+               *) printf "!gzip) "; continue ;;
+               esac
+               trap 'rm -f -- "$tf"; exit 127' 0
+               tf=`mktemp -t`
+               zcat -- "$f" >"$tf"
+               output="$(file -- "$tf")"
+               case "$output" in
+               *"ELF "*" executable,"*) ;;
+               *) printf "!ELF) "; continue;;
+               esac
+               output="$(objdump -j __xen_guest -s -- "$tf")"
+               rm -f "$tf"; trap '' 0
+               case "$output" in
+               *" __xen_guest:"*) ;;
+               *) printf "!Xen) "; continue
+               esac
+               printf "y) "
                test "x$adt_kernel" = x || \
                        fail 'several kernels, config must specify which'
                adt_kernel="$f"
        done
-       echo "... using currently booted kernel $adt_kernel"
+       [ "x$adt_kernel" != x ] || \
+               fail 'could not find currently booted Xen kernel'
+       echo "using currently booted kernel: $adt_kernel"
        ;;
-esac
+ esac
 
-case "$adt_ramdisk" in
-none)  echo "ramdisk \`none' specified, using static kernel"
+ case "$adt_ramdisk" in
+ none) echo "ramdisk \`none' specified, using static kernel"
        adt_ramdisk='' ;;
-'')    adt_ramdisk="$adt_kernel.initrd.img"
-       echo "using default ramdisk <kernel>.initrd.img, $adt_ramdisk" ;;
-*)     ;;
-esac
+ '')   adt_ramdisk="${adt_kernel/\/vmlinuz-//initrd.img-}"
+       test -e "$adt_ramdisk" || \
+ fail "calculated default ramdisk initrd.img \`$adt_ramdisk' does not exist"
+       echo "using calculated default ramdisk initrd.img: $adt_ramdisk" ;;
+ *)    ;;
+ esac
+fi
 
 case "$adt_modules" in
-'')    /lib/modules/`uname -r` ;;
+'')    adt_modules="/lib/modules/`uname -r`" ;;
 *)     ;;
 esac
 
 case "$adt_distro" in
 '')
-       echo "considering which distro to use ..."
-       test -f /etc/lsb-release || \
+       printf "considering which distro to use ... "
+       test -e /etc/lsb-release || \
                fail 'no /etc/lsb-version, config must specify adt_distro'
        . /etc/lsb-release
-       $adt_distro=$DISTRIB_CODENAME
+       adt_distro=$DISTRIB_CODENAME
+       echo "using same distro as host: $adt_distro"
        ;;
 esac
 
@@ -121,8 +171,9 @@ hostname_from_ipaddr () {
  eval '
   if [ x"$adt_'$1'_hostname" = x ] && \
      [ x"$adt_'$1'_ipaddr" != x ]; then
-   echo "finding '$1' hostname from IP address $adt_'$1'_ipaddr"
+   printf "%s" "finding '$1' hostname from IP address $adt_'$1'_ipaddr: "
    adt_'$1'_hostname=`adnshost -t ptr +Do +Dt +Dc -i $adt_'$1'_ipaddr`
+   printf "%s\n" "${adt_'$1'_hostname}"
   fi
  '
 }
@@ -131,27 +182,30 @@ hostname_from_ipaddr guest
 hostname_from_ipaddr host
 
 if [ x"$adt_host_hostname" = x ]; then
-       echo "finding host hostname, supposely our own FQDN ..."
+       printf "finding host hostname, supposely our own FQDN: "
        adt_host_hostname=`hostname -f`
+       printf "%s\n" "$adt_host_hostname"
 fi
 
 if [ x"$adt_guest_hostname" = x ]; then
        case "$adt_guests_domain" in
-       '')     echo "guessing guest hostname from host hostname ..."
+       '')     printf "guessing guest hostname from host hostname: "
  adt_guest_hostname=$adt_distro.$adt_nominum.${adt_host_hostname#*.} ;;
-       .*)     echo "setting guest hostname using distro and nominum ..."
+       .*)     printf "setting guest hostname using distro and nominum: "
  adt_guest_hostname=$adt_distro.$adt_nominum$adt_guests_domain ;;
-       *)      echo "setting guest hostname using distro and domain ..."
+       *)      printf "setting guest hostname using distro and domain: "
  adt_guest_hostname=$adt_distro.$adt_guests_domain ;;
        esac
+       printf "%s\n" "$adt_guest_hostname"
 fi
 
 ipaddr_from_hostname () {
  eval '
   if [ x"$adt_'$1'_ipaddr" = x ] && \
      [ x"$adt_'$1'_hostname" != x ]; then
-   echo "finding '$1' IP address from hostname $adt_'$1'_hostname"
-   adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc -i - "$adt_'$1'_hostname"`
+   printf "%s" "finding '$1' IP address from hostname $adt_'$1'_hostname: "
+   adt_'$1'_ipaddr=`adnshost -t a +Do +Dt +Dc - "$adt_'$1'_hostname"`
+   echo "${adt_'$1'_ipaddr}"
   fi
  '
 }
@@ -159,7 +213,52 @@ ipaddr_from_hostname () {
 ipaddr_from_hostname guest
 ipaddr_from_hostname host
 
-: ${adt_config:=/etc/autopkgtest/xenlvm_${adt_nominum}_config}
+search_hook () {
+ eval '
+  printf "looking for '$2' hook ... "
+  case "$adt_'$1'_hook" in
+  "")
+    case "$adt_config" in
+    *_config)
+      adt_'$1'_hook=${adt_config%_config}_'$3'
+      if test -e "$adt_'$1'_hook"; then
+             echo "default exists: $adt_'$1'_hook"
+      else
+             echo "default $adt_'$1'_hook is not a file, so: none"
+             adt_'$1'_hook=""
+      fi
+      ;;
+    *)
+      echo "not specified, not computable from config, so: none"
+      adt_'$1'_hook=""
+      ;;
+    esac
+    ;;
+  *)
+    if test -e "$adt_'$1'_hook"; then
+      echo "exists: $adt_'$1'_hook"
+    else
+      echo "specified as $adt_'$1'_hook, but not a file, so: none"
+      adt_'$1'_hook=""
+    fi
+    ;;
+  esac
+ '
+}
+
+search_hook fw firewall fwhook
+search_hook setup setup setuphook
+
+boolean_config () {
+  eval '
+    case "${adt_'$1'}" in
+    y*|Y*|1*|t*)       adt_'$1'=true ;;
+    n*|N*|0*|f*)       adt_'$1'=false ;;
+    "")                        adt_'$1'=$2 ;;
+    *)                 fail "unknown boolean value \`$1'\'' for adt_'$1'" ;;
+    esac
+  '
+}
 
 # SSH
 : ${adt_ssh_privkey:=/root/.ssh/id_${adt_ssh_keytype}_${adt_nominum}}
@@ -173,8 +272,10 @@ ipaddr_from_hostname host
 # In-host-file-system playground
 : ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}}
 : ${adt_xmconfig:=${adt_play}/xmconfig}
+: ${adt_lock:=${adt_play}/lock}
 
 # LVM
+boolean_config lvm_erasebase true
 : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base}
 : ${adt_lvm_cowdatalv:=${adt_nominum}_${adt_distro}_cowdata}
 : ${adt_devmapper_cowdev:=${adt_nominum}_${adt_distro}_snap}
@@ -185,14 +286,16 @@ ipaddr_from_hostname host
 # Firewall
 : ${adt_fw_testbedclients:=${adt_host_ipaddr}}
 
-lvm_baselv_namerhs=${adt_vg}/${adt_lvm_baselv}
-lvm_baselv_namepath=/dev/${adt_lvbaserhs}
+lvm_baselv_namerhs=${adt_lvm_vg}/${adt_lvm_baselv}
+lvm_baselv_namepath=/dev/${lvm_baselv_namerhs}
 
-lvm_cowdata_namerhs:=${adt_vg}/${adt_lvm_cowdatalv}
-lvm_cowdata_namepath:=/dev/${lvm_cowdata_namerhs}
+lvm_cowdata_namerhs=${adt_lvm_vg}/${adt_lvm_cowdatalv}
+lvm_cowdata_namepath=/dev/${lvm_cowdata_namerhs}
 
 lvm_snapdev=/dev/mapper/${adt_devmapper_cowdev}
 
 lvm_fslink_ptrrhs=${adt_fslink_dir}/${adt_fslink_name}
 lvm_fslink_dirpath=/dev/${adt_fslink_dir}
-lvm_fslink_ptr=/dev/${lvm_fslink_dir}/${adt_fslink_name}
+lvm_fslink_ptr=/dev/${adt_fslink_dir}/${adt_fslink_name}
+
+echo "adtxenlvm: configuration for read for nominum=${adt_nominum}"