1
0
mirror of https://github.com/rancher/os.git synced 2025-05-04 14:16:21 +00:00
os/scripts/run

67 lines
1.8 KiB
Plaintext
Raw Normal View History

2015-02-09 04:38:37 +00:00
#!/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
2015-02-19 18:26:59 +00:00
NO_COMPRESS_INITRD=${INITRD}.none
2015-02-09 04:38:37 +00:00
HD=${BASE}/build/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
2015-02-09 04:38:37 +00:00
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}
2015-02-19 18:26:59 +00:00
if [ -e ${NO_COMPRESS_INITRD} ]; then
cat ${NO_COMPRESS_INITRD} | sudo cpio -idmv
else
xz -dc ${INITRD} | sudo cpio -idmv
fi
2015-02-09 04:38:37 +00:00
rm -f init
popd
fi
if [ ! -e bin/rancheros ]; then
2015-03-01 19:19:38 +00:00
./scripts/build
fi
2015-02-09 04:38:37 +00:00
cp bin/rancheros ${INITRD_TMP}/init
cd ${INITRD_TMP}
if [ "$1" == "--docker" ]; then
docker build -t rancheros-run .
2015-02-14 16:35:46 +00:00
docker run --rm --privileged -it rancheros-run
2015-02-09 04:38:37 +00:00
else
find | cpio -H newc -o > ${INITRD_TEST}
if [ ! -e ${HD} ]; then
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}
2015-02-17 03:49:13 +00:00
2015-02-09 04:38:37 +00:00
fi