build-strongswan 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. DIR=$(dirname `readlink -f $0`)
  3. . $DIR/../testing.conf
  4. . $DIR/function.sh
  5. SWANDIR=${1:+$(readlink -f $1)}
  6. : ${SWANDIR:=$(readlink -f $DIR/../..)}
  7. [ `id -u` -eq 0 ] || die "You must be root to run $0"
  8. [ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"
  9. [ -f "$ROOTIMG" ] || die "Root image $ROOTIMG not found"
  10. running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
  11. [ -f $SWANDIR/src/libstrongswan/asn1/oid.txt ] || die "strongSwan not found in $SWANDIR"
  12. SRCUID=${SUDO_UID:-$(id -u)}
  13. SRCGID=${SUDO_GID:-$(id -g)}
  14. check_commands partprobe qemu-img qemu-nbd bindfs
  15. load_qemu_nbd
  16. mkdir -p $LOOPDIR
  17. mkdir -p $IMGDIR
  18. case "$2" in
  19. "")
  20. log_action "Connecting root image to NBD device $NBDEV"
  21. execute "qemu-nbd -c $NBDEV $ROOTIMG"
  22. ;;
  23. *)
  24. echo $STRONGSWANHOSTS | grep -q "\b$2\b" || die "Guest $2 not found"
  25. GUESTIMG="$IMGDIR/$2.$IMGEXT"
  26. [ -f "$GUESTIMG" ] || die "Guest image $GUESTIMG not found"
  27. log_action "Connecting guest image to NBD device $NBDEV"
  28. execute "qemu-nbd -c $NBDEV $GUESTIMG"
  29. ;;
  30. esac
  31. do_on_exit qemu-nbd -d $NBDEV
  32. partprobe $NBDEV
  33. log_action "Mounting $NBDPARTITION to $LOOPDIR"
  34. execute "mount $NBDPARTITION $LOOPDIR"
  35. do_on_exit umount $LOOPDIR
  36. log_action "Mounting proc filesystem to $LOOPDIR/proc"
  37. execute "mount -t proc none $LOOPDIR/proc"
  38. do_on_exit umount $LOOPDIR/proc
  39. mkdir -p $LOOPDIR/root/shared
  40. log_action "Mounting $SHAREDDIR as /root/shared"
  41. execute "mount -o bind $SHAREDDIR $LOOPDIR/root/shared"
  42. do_on_exit umount $LOOPDIR/root/shared
  43. mkdir -p $LOOPDIR/root/strongswan
  44. log_action "Mounting $SWANDIR as /root/strongswan"
  45. execute "bindfs -u $SRCUID -g $SRCGID --create-for-user=$SRCUID --create-for-group=$SRCGID $SWANDIR $LOOPDIR/root/strongswan"
  46. do_on_exit umount $LOOPDIR/root/strongswan
  47. log_action "Copy /etc/resolv.conf"
  48. execute "cp /etc/resolv.conf $LOOPDIR/etc/resolv.conf"
  49. do_on_exit rm $LOOPDIR/etc/resolv.conf
  50. log_action "Remove SWID tags of previous versions"
  51. execute_chroot "find /usr/local/share -path '*strongswan*' -name *.swidtag -delete"
  52. echo "Building and installing strongSwan"
  53. log_action "Determine strongSwan version"
  54. desc=`git -C $SWANDIR describe --dirty`
  55. if [ $? -eq 0 ]; then
  56. SWANVERSION="$desc (`git -C $SWANDIR rev-parse --abbrev-ref HEAD`)"
  57. else
  58. SWANVERSION="`cat $SWANDIR/configure.ac | sed -n '/^AC_INIT/{ s/.*,\[\(.*\)\])$/\1/p }'`"
  59. fi
  60. echo "$SWANVERSION" > $SHAREDDIR/.strongswan-version
  61. log_status 0
  62. log_action "Preparing source tree"
  63. execute_chroot 'autoreconf -i /root/strongswan'
  64. RECPDIR=$DIR/recipes
  65. RECIPE=`ls $RECPDIR/*strongswan.mk | xargs -n1 basename`
  66. mkdir -p $SHAREDDIR/build-strongswan
  67. cp $RECPDIR/$RECIPE $SHAREDDIR/build-strongswan
  68. log_action "Installing from recipe $RECIPE"
  69. execute_chroot "make SRCDIR=/root/strongswan BUILDDIR=/root/shared/build-strongswan -f /root/shared/build-strongswan/$RECIPE"
  70. # rebuild the guest images after we modified the root image
  71. if [ -z "$2" ]; then
  72. # cleanup before mounting guest images
  73. on_exit
  74. # building the guest images without certificates fails on winnetou
  75. if [ ! -f "$DIR/../hosts/winnetou/etc/ca/strongswanCert.pem" ]; then
  76. # this also re-builds the guest images
  77. $DIR/build-certs
  78. else
  79. $DIR/build-guestimages
  80. fi
  81. fi