123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #!/bin/bash
- set -e
- set -x
- cd $(dirname $0)/..
- source scripts/build-common
- BASE=$(pwd)
- KERNEL=${BASE}/dist/artifacts/vmlinuz
- INITRD=${BASE}/dist/artifacts/initrd
- NO_COMPRESS_INITRD=${INITRD}.none
- HD=${BASE}/state/empty-hd.img
- HD_GZ=${ARTIFACTS}/empty-hd.img.gz
- INITRD_TMP=${BUILD}/$(sha1sum ${INITRD} | awk '{print $1}')
- INITRD_CURRENT=${BUILD}/initrd-current
- INITRD_TEST=${BUILD}/initrd.test
- USER_DATA=cloud-init/openstack/latest/user_data
- # PREREQ: brew install coreutils
- path() {
- local UNAME=$(uname)
- if [ "$UNAME" == "Darwin" ]; then greadlink -f "$1"
- elif [ "$UNAME" == "Linux" ]; then readlink -f "$1";
- fi
- }
- while [ "$#" -gt 0 ]; do
- case $1 in
- --append)
- shift 1
- QEMU_APPEND="${QEMU_APPEND} $1"
- ;;
- --cloud-config)
- shift 1
- CLOUD_CONFIG=$(path "$1") || :
- if [ ! -f ${CLOUD_CONFIG} ]; then
- echo No such file: "'"${CLOUD_CONFIG}"'" 1>&2
- exit 1
- fi
- ;;
- *)
- break
- ;;
- esac
- shift 1
- done
- if [[ ! -e ${KERNEL} || ! -e ${INITRD} ]]; then
- echo "Failed to find ${KERNEL} or ${INITRD}" 1>&2
- exit 1
- fi
- if [ ! -d ${INITRD_TMP} ]; then
- mkdir -p ${INITRD_TMP}
- pushd ${INITRD_TMP}
- if [ -e ${NO_COMPRESS_INITRD} ]; then
- cat ${NO_COMPRESS_INITRD} | cpio -idmv
- else
- xz -dc ${INITRD} | cpio -idmv
- fi
- rm -f init
- popd
- fi
- ln -sf ${INITRD_TMP} ${INITRD_CURRENT}
- cp bin/rancheros ${INITRD_TMP}/init
- cp -f os-config.yml ${INITRD_TMP}/
- cd ${INITRD_TMP}
- find . | cpio -H newc -o > ${INITRD_TEST}
- if [ ! -e ${HD} ]; then
- mkdir -p $(dirname ${HD})
- gzip -dc ${HD_GZ} > ${HD}
- fi
- mkdir -p $(dirname $USER_DATA)
- if [ -n "$CLOUD_CONFIG" ]; then
- cat ${CLOUD_CONFIG} > ${USER_DATA}
- else
- echo "#cloud-config" > ${USER_DATA}
- echo "ssh_authorized_keys:" >> ${USER_DATA}
- echo " - $(<${BASE}/assets/rancher.key.pub)" >> ${USER_DATA}
- for i in ${HOME}/.ssh/*.pub; do
- if [ -e $i ]; then
- echo " - $(<$i)" >> ${USER_DATA}
- fi
- done
- fi
- UNAME=$(uname)
- KERNEL_ARGS="quiet rancher.password=rancher console=ttyS0 ${QEMU_APPEND}"
- if [ "$UNAME" == "Darwin" ] && [ -x $(which xhyve) ]; then
- CLOUD_CONFIG_ISO="$(pwd)/cloud-config.iso"
- rm -rf ${CLOUD_CONFIG_ISO}
- # PREREQ: brew install cdrtools
- mkisofs -R -V config-2 -o "${CLOUD_CONFIG_ISO}" "$(pwd)/cloud-init"
- echo PWD=`pwd`
- exec sudo xhyve -H -P \
- -m 4G \
- -s 0:0,hostbridge -s 31,lpc \
- -l com1,stdio \
- -s 2:0,virtio-net \
- -s 3,ahci-cd,${CLOUD_CONFIG_ISO} \
- -U a01fb25c-3a19-4759-a47a-2e353e51807d \
- -f kexec,${KERNEL},${INITRD_TEST},"earlyprintk=serial acpi=off elevator=noop ${KERNEL_ARGS}"
- elif ["$UNAME" == "Linux"] && [ -x $(which qemu-system-x86_64) ]; then
- exec qemu-system-x86_64 -serial stdio \
- -kernel ${KERNEL} \
- -initrd ${INITRD_TEST} \
- -m 1024 \
- -net nic,vlan=0,model=virtio \
- -net user,vlan=0,hostfwd=tcp::2222-:22,hostname=rancher-dev \
- -drive if=virtio,file=${HD} \
- -machine accel=kvm \
- -cpu host \
- -smp 4 \
- -fsdev local,id=conf,security_model=none,readonly,path=$(pwd)/cloud-init \
- -device virtio-9p-pci,fsdev=conf,mount_tag=config-2 \
- -append "${KERNEL_ARGS}" \
- -serial mon:telnet:localhost:4444,server,nowait \
- ${QEMU_ARGS} "${@}"
- else
- exit 42
- fi
|