build-guestimages 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # create specific guest images
  3. #
  4. # Copyright (C) 2004 Eric Marchionni, Patrik Rayo
  5. # Zuercher Hochschule Winterthur
  6. #
  7. # This program is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by the
  9. # Free Software Foundation; either version 2 of the License, or (at your
  10. # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. # for more details.
  16. echo "Creating guest images"
  17. DIR=$(dirname `readlink -f $0`)
  18. . $DIR/../testing.conf
  19. . $DIR/function.sh
  20. HOSTSDIR=$DIR/../hosts
  21. [ `id -u` -eq 0 ] || die "You must be root to run $0"
  22. [ -f $ROOTIMG ] || die "Root image $ROOTIMG not found"
  23. [ -f $HOSTDIR ] || die "Hosts directory $HOSTSDIR not found"
  24. running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
  25. check_commands partprobe qemu-img qemu-nbd
  26. load_qemu_nbd
  27. mkdir -p $IMGDIR
  28. mkdir -p $LOOPDIR
  29. # just to be sure
  30. do_on_exit qemu-nbd -d $NBDEV
  31. do_on_exit umount $LOOPDIR
  32. for host in $STRONGSWANHOSTS
  33. do
  34. log_action "Creating guest image for $host"
  35. execute "qemu-img create -b $ROOTIMG -f $IMGEXT $IMGDIR/$host.$IMGEXT" 0
  36. execute "qemu-nbd -c $NBDEV $IMGDIR/$host.$IMGEXT" 0
  37. partprobe $NBDEV
  38. execute "mount $NBDPARTITION $LOOPDIR" 0
  39. execute "cp -rf $HOSTSDIR/${host}/etc $LOOPDIR" 0
  40. execute "cp -rf $HOSTSDIR/default/* $LOOPDIR" 0
  41. execute_chroot "ldconfig" 0
  42. execute "mkdir $LOOPDIR/etc/pts" 0
  43. if [ "$host" = "alice" ]
  44. then
  45. execute "mkdir $LOOPDIR/var/log/apache2/tnc" 0
  46. execute_chroot "chgrp www-data /etc/pts" 0
  47. execute_chroot "chmod g+w /etc/pts" 0
  48. fi
  49. if [ "$host" = "winnetou" ]
  50. then
  51. execute "mkdir $LOOPDIR/var/log/apache2/ocsp" 0
  52. execute "cp -rf $DIR/../images $LOOPDIR/var/www/" 0
  53. execute "mkdir $LOOPDIR/var/www/testresults" 0
  54. echo "echo /testresults ... >> $LOOPDIR/etc/fstab" >>$LOGFILE 2>&1
  55. echo "/testresults /var/www/testresults 9p trans=virtio,version=9p2000.L 0 0" >> $LOOPDIR/etc/fstab
  56. execute_chroot "a2enmod -q cgid" 0
  57. execute_chroot "a2enmod -q rewrite" 0
  58. execute_chroot "mkdir /var/www/certs" 0
  59. execute_chroot "mkdir /var/www/certs/research /var/www/certs/sales" 0
  60. execute_chroot "/etc/ca/generate-crl" 0
  61. execute_chroot "rm -rf /var/lib/ldap/*" 0
  62. execute_chroot "slapadd -l /etc/ldap/ldif.txt -f /etc/ldap/slapd.conf" 0
  63. execute_chroot "chown -R openldap:openldap /var/lib/ldap" 0
  64. execute_chroot "dnssec-signzone -K /etc/bind -o strongswan.org. /etc/bind/db.strongswan.org" 0
  65. execute_chroot "dnssec-signzone -K /etc/bind -o org. /etc/bind/db.org" 0
  66. execute_chroot "dnssec-signzone -K /etc/bind -o . /etc/bind/db.root" 0
  67. for service in "apache2 slapd bind9"
  68. do
  69. execute_chroot "systemctl enable $service" 0
  70. done
  71. fi
  72. sync
  73. execute "umount -l $LOOPDIR" 0
  74. execute "qemu-nbd -d $NBDEV" 0
  75. log_status 0
  76. done