You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

make-base-vm 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/sh
  2. set -e
  3. SUITE=lucid
  4. ARCH=amd64
  5. MIRROR=http://${MIRROR_HOST:-127.0.0.1}:3142/archive.ubuntu.com/ubuntu
  6. SECURITY_MIRROR=http://${MIRROR_HOST:-127.0.0.1}:3142/security.ubuntu.com/ubuntu
  7. LXC=0
  8. VBOX=0
  9. usage() {
  10. echo "Usage: ${0##*/} [OPTION]..."
  11. echo "Make a base client."
  12. echo
  13. cat << EOF
  14. --help display this help and exit
  15. --suite U build suite U instead of lucid
  16. --arch A build architecture A (e.g. i386) instead of amd64
  17. --lxc use lxc instead of kvm
  18. --vbox use VirtualBox instead of kvm
  19. The MIRROR_HOST environment variable can be used to change the
  20. apt-cacher host. It should be something that both the host and the
  21. target VM can reach. It may be set to 127.0.0.1, in which case it will be
  22. changed to 10.0.2.2 on the guest (or GITIAN_HOST_IP if it is defined)
  23. 10.0.2.2 is the host IP as visible from the guest under qemu networking.
  24. EOF
  25. }
  26. if [ $# != 0 ] ; then
  27. while true ; do
  28. case "$1" in
  29. --help|-h)
  30. usage
  31. exit 0
  32. ;;
  33. --suite|-s)
  34. SUITE="$2"
  35. shift 2
  36. ;;
  37. --arch|-a)
  38. ARCH="$2"
  39. shift 2
  40. ;;
  41. --lxc)
  42. LXC=1
  43. shift 1
  44. ;;
  45. --vbox)
  46. VBOX=1
  47. shift 1
  48. ;;
  49. --*)
  50. echo "unrecognized option $1"
  51. exit 1
  52. ;;
  53. *)
  54. break
  55. ;;
  56. esac
  57. done
  58. fi
  59. mkdir -p var
  60. if [ ! -e var/id_dsa ]; then
  61. ssh-keygen -t dsa -f var/id_dsa -N ""
  62. fi
  63. OUT=base-$SUITE-$ARCH
  64. FLAVOUR=virtual
  65. if [ $ARCH = "amd64" -a $SUITE = "hardy" ]; then
  66. FLAVOUR=server
  67. fi
  68. addpkg=pciutils,build-essential,git-core,subversion,language-pack-en
  69. if [ $LXC = "1" ]; then
  70. addpkg=$addpkg,lxc
  71. else
  72. addpkg=$addpkg,linux-image-generic,grub-pc,openssh-server
  73. fi
  74. # Remove cron to work around vmbuilder issue when umounting /dev on target
  75. removepkg=cron
  76. if [ $VBOX = "1" ]; then
  77. NAME="$SUITE-$ARCH"
  78. if ! vagrant status | grep "$NAME" | grep "not created" > /dev/null; then
  79. echo "Vagrant machine "$NAME" already exists, please remove it first (vagrant destroy "$NAME")"
  80. exit 1
  81. fi
  82. vagrant up "$NAME"
  83. vagrant ssh "$NAME" -c "sudo mkdir -p /root/.ssh && sudo chmod 700 /root/.ssh"
  84. vagrant ssh "$NAME" -c "sudo sh -c 'cat >> /root/.ssh/authorized_keys'" < var/id_dsa.pub
  85. vagrant ssh "$NAME" -c "sudo -u ubuntu mkdir -p /home/ubuntu/.ssh && sudo -u ubuntu chmod 700 /home/ubuntu/.ssh"
  86. vagrant ssh "$NAME" -c "sudo sh -c 'cat >> /home/ubuntu/.ssh/authorized_keys'" < var/id_dsa.pub
  87. VBoxManage snapshot "Gitian-$NAME" take "Gitian-Clean"
  88. vagrant suspend "$NAME"
  89. exit 0
  90. fi
  91. if [ $LXC = "1" ]; then
  92. if [ -e $OUT ]; then
  93. echo $OUT already exists, please remove it first
  94. exit 1
  95. fi
  96. sudo rm -rf $OUT-bootstrap
  97. # Need universe for lxc in lucid
  98. env -i LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 sudo debootstrap --arch=$ARCH --include=$addpkg --exclude=$removepkg --components=main,universe $SUITE $OUT-bootstrap $MIRROR
  99. dd if=/dev/zero of=$OUT-lxc bs=1M count=1 seek=10240
  100. mkfs.ext4 -F $OUT-lxc
  101. t=`mktemp -d gitian.XXXXXXXX`
  102. sudo mount $OUT-lxc $t
  103. sudo cp -a $OUT-bootstrap/* $t
  104. sudo umount $t
  105. rmdir $t
  106. sudo rm -rf $OUT-bootstrap
  107. mv $OUT-lxc $OUT
  108. # bootstrap-fixup is done in libexec/make-clean-vm
  109. else
  110. if [ -e $OUT.qcow2 ]; then
  111. echo $OUT.qcow2 already exists, please remove it first
  112. exit 1
  113. fi
  114. libexec/config-bootstrap-fixup
  115. rm -rf $OUT
  116. env -i LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 sudo vmbuilder kvm ubuntu --rootsize 10240 --arch=$ARCH --suite=$SUITE --addpkg=$addpkg --removepkg=$removepkg --ssh-key=var/id_dsa.pub --ssh-user-key=var/id_dsa.pub --mirror=$MIRROR --security-mirror=$SECURITY_MIRROR --dest=$OUT --flavour=$FLAVOUR --firstboot=`pwd`/target-bin/bootstrap-fixup
  117. mv $OUT/*.qcow2 $OUT.qcow2
  118. rm -rf $OUT
  119. # bootstrap-fixup is done on first boot
  120. fi