Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

make-base-vm 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/sh
  2. set -e
  3. DISTRO=ubuntu
  4. SUITE=lucid
  5. ARCH=amd64
  6. MIRROR_BASE=http://${MIRROR_HOST:-127.0.0.1}:3142
  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. --distro D build distro D (e.g. debian) instead of ubuntu
  16. --suite U build suite U instead of lucid
  17. --arch A build architecture A (e.g. i386) instead of amd64
  18. --lxc use lxc instead of kvm
  19. --vbox use VirtualBox instead of kvm
  20. The MIRROR_HOST environment variable can be used to change the
  21. apt-cacher host. It should be something that both the host and the
  22. target VM can reach. It may be set to 127.0.0.1, in which case it will be
  23. changed to 10.0.2.2 on the guest (or GITIAN_HOST_IP if it is defined)
  24. 10.0.2.2 is the host IP as visible from the guest under qemu networking.
  25. EOF
  26. }
  27. if [ $# != 0 ] ; then
  28. while true ; do
  29. case "$1" in
  30. --help|-h)
  31. usage
  32. exit 0
  33. ;;
  34. --distro|-d)
  35. DISTRO="$2"
  36. shift 2
  37. ;;
  38. --suite|-s)
  39. SUITE="$2"
  40. shift 2
  41. ;;
  42. --arch|-a)
  43. ARCH="$2"
  44. shift 2
  45. ;;
  46. --lxc)
  47. LXC=1
  48. shift 1
  49. ;;
  50. --vbox)
  51. VBOX=1
  52. shift 1
  53. ;;
  54. --*)
  55. echo "unrecognized option $1"
  56. exit 1
  57. ;;
  58. *)
  59. break
  60. ;;
  61. esac
  62. done
  63. fi
  64. if [ $DISTRO = "debian" -a $LXC = "1" ]; then
  65. echo "There is no support for Debian guests using LXC currently. Please use KVM or another distro for now."
  66. exit 1
  67. fi
  68. if [ $DISTRO = "ubuntu" ]; then
  69. MIRROR=$MIRROR_BASE/archive.ubuntu.com/ubuntu
  70. SECURITY_MIRROR=$MIRROR_BASE/security.ubuntu.com/ubuntu
  71. elif [ $DISTRO = "debian" ]; then
  72. MIRROR=$MIRROR_BASE/ftp.debian.org/debian
  73. SECURITY_MIRROR=$MIRROR_BASE/security.debian.org/
  74. fi
  75. mkdir -p var
  76. if [ ! -e var/id_dsa ]; then
  77. ssh-keygen -t dsa -f var/id_dsa -N ""
  78. fi
  79. OUT=base-$SUITE-$ARCH
  80. FLAVOUR=virtual
  81. if [ $ARCH = "amd64" -a $SUITE = "hardy" ]; then
  82. FLAVOUR=server
  83. fi
  84. if [ $DISTRO = "debian" -a $ARCH = "amd64" ]; then
  85. FLAVOUR=amd64
  86. elif [ $DISTRO = "debian" -a $ARCH = "i386" -a \($SUITE = "wheezy" -o $SUITE = "jessie" -o $SUITE = "stretch" -o $SUITE = "sid"\) ]; then
  87. FLAVOUR=686-pae
  88. elif [ $DISTRO = "debian" ]; then
  89. FLAVOUR=686
  90. fi
  91. LOCALE_PKG=language-pack-en
  92. if [ $DISTRO = "debian" ]; then
  93. LOCALE_PKG=locales
  94. fi
  95. addpkg=pciutils,build-essential,git-core,subversion,$LOCALE_PKG,wget,lsb-release
  96. KERNEL_PKG=linux-image-generic
  97. if [ $DISTRO = "debian" ]; then
  98. KERNEL_PKG=
  99. fi
  100. if [ $LXC = "1" ]; then
  101. addpkg=$addpkg,lxc
  102. else
  103. addpkg=$addpkg,$KERNEL_PKG,grub-pc,openssh-server
  104. fi
  105. # Remove cron to work around vmbuilder issue when umounting /dev on target
  106. removepkg=cron
  107. if [ $VBOX = "1" ]; then
  108. NAME="$SUITE-$ARCH"
  109. if ! vagrant status | grep "$NAME" | grep "not created" > /dev/null; then
  110. echo "Vagrant machine "$NAME" already exists, please remove it first (vagrant destroy "$NAME")"
  111. exit 1
  112. fi
  113. vagrant up "$NAME"
  114. vagrant ssh "$NAME" -c "sudo mkdir -p /root/.ssh && sudo chmod 700 /root/.ssh"
  115. vagrant ssh "$NAME" -c "sudo sh -c 'cat >> /root/.ssh/authorized_keys'" < var/id_dsa.pub
  116. vagrant ssh "$NAME" -c "sudo -u $DISTRO mkdir -p /home/$DISTRO/.ssh && sudo -u $DISTRO chmod 700 /home/$DISTRO/.ssh"
  117. vagrant ssh "$NAME" -c "sudo sh -c 'cat >> /home/$DISTRO/.ssh/authorized_keys'" < var/id_dsa.pub
  118. VBoxManage snapshot "Gitian-$NAME" take "Gitian-Clean"
  119. vagrant suspend "$NAME"
  120. exit 0
  121. fi
  122. if [ $LXC = "1" ]; then
  123. if [ -e $OUT ]; then
  124. echo $OUT already exists, please remove it first
  125. exit 1
  126. fi
  127. sudo rm -rf $OUT-bootstrap
  128. # Need universe for lxc in lucid
  129. 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
  130. dd if=/dev/zero of=$OUT-lxc bs=1M count=1 seek=10240
  131. /sbin/mkfs.ext4 -F $OUT-lxc
  132. t=`mktemp -d gitian.XXXXXXXX`
  133. sudo mount $OUT-lxc $t
  134. sudo cp -a $OUT-bootstrap/* $t
  135. sudo umount $t
  136. rmdir $t
  137. sudo rm -rf $OUT-bootstrap
  138. mv $OUT-lxc $OUT
  139. # bootstrap-fixup is done in libexec/make-clean-vm
  140. else
  141. if [ -e $OUT.qcow2 ]; then
  142. echo $OUT.qcow2 already exists, please remove it first
  143. exit 1
  144. fi
  145. libexec/config-bootstrap-fixup
  146. rm -rf $OUT
  147. env -i LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 sudo vmbuilder kvm $DISTRO --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
  148. mv $OUT/*.qcow2 $OUT.qcow2
  149. rm -rf $OUT
  150. # bootstrap-fixup is done on first boot
  151. fi