run 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. set -e
  3. set -x
  4. cd $(dirname $0)/..
  5. source scripts/build-common
  6. BASE=$(pwd)
  7. KERNEL=${BASE}/dist/artifacts/vmlinuz
  8. INITRD=${BASE}/dist/artifacts/initrd
  9. NO_COMPRESS_INITRD=${INITRD}.none
  10. HD=${BASE}/state/empty-hd.img
  11. HD_GZ=${ARTIFACTS}/empty-hd.img.gz
  12. INITRD_TMP=${BUILD}/$(sha1sum ${INITRD} | awk '{print $1}')
  13. INITRD_CURRENT=${BUILD}/initrd-current
  14. INITRD_TEST=${BUILD}/initrd.test
  15. USER_DATA=cloud-init/openstack/latest/user_data
  16. # PREREQ: brew install coreutils
  17. path() {
  18. local UNAME=$(uname)
  19. if [ "$UNAME" == "Darwin" ]; then greadlink -f "$1"
  20. elif [ "$UNAME" == "Linux" ]; then readlink -f "$1";
  21. fi
  22. }
  23. while [ "$#" -gt 0 ]; do
  24. case $1 in
  25. --append)
  26. shift 1
  27. QEMU_APPEND="${QEMU_APPEND} $1"
  28. ;;
  29. --cloud-config)
  30. shift 1
  31. CLOUD_CONFIG=$(path "$1") || :
  32. if [ ! -f ${CLOUD_CONFIG} ]; then
  33. echo No such file: "'"${CLOUD_CONFIG}"'" 1>&2
  34. exit 1
  35. fi
  36. ;;
  37. *)
  38. break
  39. ;;
  40. esac
  41. shift 1
  42. done
  43. if [[ ! -e ${KERNEL} || ! -e ${INITRD} ]]; then
  44. echo "Failed to find ${KERNEL} or ${INITRD}" 1>&2
  45. exit 1
  46. fi
  47. if [ ! -d ${INITRD_TMP} ]; then
  48. mkdir -p ${INITRD_TMP}
  49. pushd ${INITRD_TMP}
  50. if [ -e ${NO_COMPRESS_INITRD} ]; then
  51. cat ${NO_COMPRESS_INITRD} | cpio -idmv
  52. else
  53. xz -dc ${INITRD} | cpio -idmv
  54. fi
  55. rm -f init
  56. popd
  57. fi
  58. ln -sf ${INITRD_TMP} ${INITRD_CURRENT}
  59. cp bin/rancheros ${INITRD_TMP}/init
  60. cp -f os-config.yml ${INITRD_TMP}/
  61. cd ${INITRD_TMP}
  62. find . | cpio -H newc -o > ${INITRD_TEST}
  63. if [ ! -e ${HD} ]; then
  64. mkdir -p $(dirname ${HD})
  65. gzip -dc ${HD_GZ} > ${HD}
  66. fi
  67. mkdir -p $(dirname $USER_DATA)
  68. if [ -n "$CLOUD_CONFIG" ]; then
  69. cat ${CLOUD_CONFIG} > ${USER_DATA}
  70. else
  71. echo "#cloud-config" > ${USER_DATA}
  72. echo "ssh_authorized_keys:" >> ${USER_DATA}
  73. echo " - $(<${BASE}/assets/rancher.key.pub)" >> ${USER_DATA}
  74. for i in ${HOME}/.ssh/*.pub; do
  75. if [ -e $i ]; then
  76. echo " - $(<$i)" >> ${USER_DATA}
  77. fi
  78. done
  79. fi
  80. UNAME=$(uname)
  81. KERNEL_ARGS="quiet rancher.password=rancher console=ttyS0 ${QEMU_APPEND}"
  82. if [ "$UNAME" == "Darwin" ] && [ -x $(which xhyve) ]; then
  83. CLOUD_CONFIG_ISO="$(pwd)/cloud-config.iso"
  84. rm -rf ${CLOUD_CONFIG_ISO}
  85. # PREREQ: brew install cdrtools
  86. mkisofs -R -V config-2 -o "${CLOUD_CONFIG_ISO}" "$(pwd)/cloud-init"
  87. echo PWD=`pwd`
  88. exec sudo xhyve -H -P \
  89. -m 4G \
  90. -s 0:0,hostbridge -s 31,lpc \
  91. -l com1,stdio \
  92. -s 2:0,virtio-net \
  93. -s 3,ahci-cd,${CLOUD_CONFIG_ISO} \
  94. -U a01fb25c-3a19-4759-a47a-2e353e51807d \
  95. -f kexec,${KERNEL},${INITRD_TEST},"earlyprintk=serial acpi=off elevator=noop ${KERNEL_ARGS}"
  96. elif ["$UNAME" == "Linux"] && [ -x $(which qemu-system-x86_64) ]; then
  97. exec qemu-system-x86_64 -serial stdio \
  98. -kernel ${KERNEL} \
  99. -initrd ${INITRD_TEST} \
  100. -m 1024 \
  101. -net nic,vlan=0,model=virtio \
  102. -net user,vlan=0,hostfwd=tcp::2222-:22,hostname=rancher-dev \
  103. -drive if=virtio,file=${HD} \
  104. -machine accel=kvm \
  105. -cpu host \
  106. -smp 4 \
  107. -fsdev local,id=conf,security_model=none,readonly,path=$(pwd)/cloud-init \
  108. -device virtio-9p-pci,fsdev=conf,mount_tag=config-2 \
  109. -append "${KERNEL_ARGS}" \
  110. -serial mon:telnet:localhost:4444,server,nowait \
  111. ${QEMU_ARGS} "${@}"
  112. else
  113. exit 42
  114. fi