#!/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_TEST=${BUILD}/initrd.test USER_DATA=cloud-init/openstack/latest/user_data 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} | sudo cpio -idmv else xz -dc ${INITRD} | sudo cpio -idmv fi rm -f init popd fi if [ ! -e bin/rancheros ]; then ./scripts/build fi cp bin/rancheros ${INITRD_TMP}/init cd ${INITRD_TMP} if [ "$1" == "--docker" ]; then docker build -t rancheros-run . docker run --rm --privileged -it rancheros-run else find | cpio -H newc -o > ${INITRD_TEST} if [ ! -e ${HD} ]; then mkdir -p $(dirname ${HD}) zcat ${HD_GZ} > ${HD} fi mkdir -p $(dirname $USER_DATA) echo "#cloud-config" > ${USER_DATA} echo "ssh_authorized_keys:" >> ${USER_DATA} for i in ${HOME}/.ssh/*.pub; do if [ -e $i ]; then echo " - $(<$i)" >> ${USER_DATA} fi done 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 \ -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 "x rancher.password=rancher $@" \ ${QEMU_ARGS} fi