build-baseimage 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/bash
  2. echo "Building base image"
  3. DIR=$(dirname `readlink -f $0`)
  4. . $DIR/../testing.conf
  5. . $DIR/function.sh
  6. [ `id -u` -eq 0 ] || die "You must be root to run $0"
  7. running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
  8. check_commands debootstrap mkfs.ext3 partprobe qemu-img qemu-nbd sfdisk
  9. # package includes/excludes
  10. INC=automake,autoconf,libtool,bison,flex,gperf,pkg-config,gettext,less,locales
  11. INC=$INC,build-essential,libgmp-dev,libldap2-dev,libcurl4-openssl-dev,ethtool
  12. INC=$INC,libxml2-dev,libtspi-dev,libsqlite3-dev,openssh-server,tcpdump,psmisc
  13. INC=$INC,openssl,vim,sqlite3,conntrack,gdb,cmake,libltdl-dev,liblog4cxx10-dev
  14. INC=$INC,libboost-thread-dev,libboost-system-dev,git-core,iperf,htop
  15. INC=$INC,gnat,gprbuild,acpid,acpi-support-base,libldns-dev,libunbound-dev
  16. INC=$INC,dnsutils,libsoup2.4-dev,ca-certificates,unzip,libsystemd-dev
  17. INC=$INC,python,python-setuptools,python-dev,python-pip,apt-transport-https
  18. INC=$INC,libjson-c-dev,libxslt1-dev,libapache2-mod-wsgi,iptables-dev
  19. INC=$INC,libxerces-c-dev,libgcrypt20-dev,traceroute
  20. case "$BASEIMGSUITE" in
  21. jessie)
  22. INC=$INC,libahven4-dev,libxmlada5-dev,libgmpada5-dev
  23. INC=$INC,libalog1-dev
  24. ;;
  25. stretch)
  26. INC=$INC,libahven5-dev,libxmlada-schema6-dev,libgmpada6-dev
  27. INC=$INC,libalog2-dev
  28. ;;
  29. *)
  30. echo_warn "Package list for '$BASEIMGSUITE' might has to be updated"
  31. esac
  32. SERVICES="apache2 dbus isc-dhcp-server slapd bind9 freeradius"
  33. INC=$INC,${SERVICES// /,}
  34. # packages to install via APT, for SWIMA tests
  35. APT="tmux"
  36. # additional services to disable
  37. SERVICES="$SERVICES systemd-timesyncd.service"
  38. CACHEDIR=$BUILDDIR/cache
  39. APTCACHE=$LOOPDIR/var/cache/apt/archives
  40. mkdir -p $LOOPDIR
  41. mkdir -p $CACHEDIR
  42. mkdir -p $IMGDIR
  43. rm -f $BASEIMG
  44. echo "`date`, building $BASEIMG" >>$LOGFILE
  45. load_qemu_nbd
  46. log_action "Creating base image $BASEIMG"
  47. execute "qemu-img create -f $IMGEXT $BASEIMG ${BASEIMGSIZE}M"
  48. log_action "Connecting image to NBD device $NBDEV"
  49. execute "qemu-nbd -c $NBDEV $BASEIMG"
  50. do_on_exit qemu-nbd -d $NBDEV
  51. log_action "Partitioning disk"
  52. sfdisk /dev/nbd0 >>$LOGFILE 2>&1 << EOF
  53. ;
  54. EOF
  55. if [ $? != 0 ]
  56. then
  57. log_status 1
  58. exit 1
  59. else
  60. log_status 0
  61. fi
  62. partprobe $NBDEV
  63. log_action "Creating ext3 filesystem"
  64. execute "mkfs.ext3 $NBDPARTITION"
  65. log_action "Mounting $NBDPARTITION to $LOOPDIR"
  66. execute "mount $NBDPARTITION $LOOPDIR"
  67. do_on_exit graceful_umount $LOOPDIR
  68. log_action "Using $CACHEDIR as archive for apt"
  69. mkdir -p $APTCACHE
  70. execute "mount -o bind $CACHEDIR $APTCACHE"
  71. do_on_exit graceful_umount $APTCACHE
  72. log_action "Running debootstrap ($BASEIMGSUITE, $BASEIMGARCH)"
  73. execute "debootstrap --arch=$BASEIMGARCH --include=$INC $BASEIMGSUITE $LOOPDIR $BASEIMGMIRROR"
  74. execute "mount -t proc none $LOOPDIR/proc" 0
  75. do_on_exit graceful_umount $LOOPDIR/proc
  76. log_action "Generating locales"
  77. cat > $LOOPDIR/etc/locale.gen << EOF
  78. de_CH.UTF-8 UTF-8
  79. en_US.UTF-8 UTF-8
  80. EOF
  81. execute_chroot "locale-gen"
  82. log_action "Downloading signing key for custom apt repo"
  83. execute_chroot "wget -q $BASEIMGEXTKEY -O /tmp/key"
  84. log_action "Installing signing key for custom apt repo"
  85. execute_chroot "apt-key add /tmp/key"
  86. log_action "Enabling custom apt repo"
  87. cat > $LOOPDIR/etc/apt/sources.list.d/strongswan.list << EOF
  88. deb $BASEIMGEXTREPO $BASEIMGSUITE main
  89. EOF
  90. log_status $?
  91. log_action "Prioritize custom apt repo"
  92. cat > $LOOPDIR/etc/apt/preferences.d/strongswan.pref << EOF
  93. Package: *
  94. Pin: origin "$BASEIMGEXTREPOHOST"
  95. Pin-Priority: 1001
  96. EOF
  97. log_status $?
  98. log_action "Update package sources"
  99. execute_chroot "apt-get update"
  100. log_action "Install packages via APT"
  101. execute_chroot "apt-get -y install $APT"
  102. log_action "Install packages from custom repo"
  103. execute_chroot "apt-get -y upgrade"
  104. for service in $SERVICES
  105. do
  106. log_action "Disabling service $service"
  107. execute_chroot "systemctl disable $service"
  108. done
  109. log_action "Disabling root password"
  110. execute_chroot "passwd -d root"