chiark / gitweb /
TODO
[autopkgtest.git] / xen / fixups
1 #!/bin/bash
2 set -e
3 . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig
4
5 dest=$adt_play/base
6
7 echo '---fixups:'
8
9 cp ${ADT_XENLVM_SHARE}/fixups-inside $dest/root/
10
11 if test -d "${adt_modules}"; then
12         mkdir -p $dest/lib/modules
13         cp -a "${adt_modules}" $dest/lib/modules/.
14 fi
15
16 echo xennet >>$dest/etc/modules
17
18 if ! test -f "${adt_ssh_pubkey}"; then
19         if [ "x${adt_ssh_pubkey}" != "x${adt_ssh_privkey}.pub" ]; then
20                 fail "cannot generate keypair automatically because adt_ssh_privkey \`$adt_ssh_privkey' and adt_ssh_pubkey \`$adt_ssh_pubkey' do not match up in the way required by ssh-keygen (<pubkey> must be <privkey>.pub>"
21         fi
22         if test -f "${adt_ssh_privkey}"; then
23                 fail "will not overwrite existing private key \`$adt_ssh_privkey' - but where is public key \`$adt_ssh_pubkey' ?"
24         fi
25
26         mkdir -p /root/.ssh
27         ssh-keygen -N '' ${adt_ssh_keygen_args} -f "${adt_ssh_privkey}"
28 fi
29
30 mkdir -m 02700 -p $dest/root/.ssh
31 cp -- "${adt_ssh_pubkey}" $dest/root/.ssh/authorized_keys
32 if [ "x$adt_sshauthkeys_hook" != x ]; then
33         cat -- "$adt_sshauthkeys_hook" >>$dest/root/.ssh/authorized_keys
34 fi
35
36 cat <<END >$dest/etc/init.d/xenethtoolk
37 #!/bin/sh
38 # work around checksum offload bug in Xen network bridge driver
39 case "$1" in
40 start)
41         ethtool -K eth0 tx off
42         ethtool -K eth0 rx off
43         ;;
44 esac
45 END
46 chmod +x $dest/etc/init.d/xenethtoolk
47 ln -s ../init.d/xenethtoolk $dest/etc/rc2.d/S21xenethtoolk
48
49 chroot $dest root/fixups-inside \
50         "$adt_host_hostname" "$adt_guest_hostname" \
51         "$adt_host_ipaddr" "$adt_guest_ipaddr" \
52         "$adt_fs_type" "$adt_normaluser" \
53         "$provideswap"
54
55 kh=/etc/ssh/ssh_known_hosts
56 test ! -f $kh || cp $kh $kh.new
57 exec 3>$kh.new
58 pfx="$adt_guest_hostname,$adt_guest_ipaddr"
59 test ! -f $kh || perl -pe '$_="" if m/^(\S+)\s/ && $1 eq "'$pfx'";' $kh >&3
60 for f in $dest/etc/ssh/ssh_host_*_key.pub; do
61     perl -pe '$_= "'$pfx' ".$_;' $f >&3
62 done
63 exec 3>&-
64 mv $kh.new $kh
65
66 if test -f $dest/etc/udev/rules.d/*-persistent-net-generator.rules; then
67         rules_file="`grep '^RULES_FILE=' $dest/lib/udev/write_net_rules`"
68         rules_file=${rules_file#RULES_FILE=}
69         rules_file=${rules_file#[\'\"]}
70         rules_file=${rules_file%[\'\"]}
71         echo 'SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="'$adt_guest_macaddr'", NAME="eth0"' >"$dest/$rules_file"
72 fi
73
74 echo '
75 === adt xen fixups done.
76 '