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

127 lines
3.2 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-03-15 01:23:31 +00:00
HD=${BASE}/state/empty-hd.img
2015-02-09 04:38:37 +00:00
HD_GZ=${ARTIFACTS}/empty-hd.img.gz
INITRD_TMP=${BUILD}/$(sha1sum ${INITRD} | awk '{print $1}')
2015-03-29 10:07:24 +00:00
INITRD_CURRENT=${BUILD}/initrd-current
2015-02-09 04:38:37 +00:00
INITRD_TEST=${BUILD}/initrd.test
USER_DATA=cloud-init/openstack/latest/user_data
while [ "$#" -gt 0 ]; do
case $1 in
--append)
shift 1
QEMU_APPEND="${QEMU_APPEND} $1"
;;
--cloud-config)
shift 1
CLOUD_CONFIG=$(readlink -f "$1") || :
if [ ! -f ${CLOUD_CONFIG} ]; then
echo No such file: "'"${CLOUD_CONFIG}"'" 1>&2
exit 1
fi
;;
*)
break
;;
esac
shift 1
done
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} | cpio -idmv
2015-02-19 18:26:59 +00:00
else
xz -dc ${INITRD} | cpio -idmv
2015-02-19 18:26:59 +00:00
fi
2015-02-09 04:38:37 +00:00
rm -f init
popd
fi
ln -sf ${INITRD_TMP} ${INITRD_CURRENT}
cp bin/rancheros ${INITRD_TMP}/init
cp -f os-config.yml ${INITRD_TMP}/
2015-02-09 04:38:37 +00:00
cd ${INITRD_TMP}
2015-06-19 20:26:56 +00:00
find . | cpio -H newc -o > ${INITRD_TEST}
2015-02-09 04:38:37 +00:00
if [ ! -e ${HD} ]; then
mkdir -p $(dirname ${HD})
2015-06-29 18:32:36 +00:00
gzip -dc ${HD_GZ} > ${HD}
fi
2015-02-09 04:38:37 +00:00
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
2015-06-19 20:26:56 +00:00
UNAME=$(uname)
KERNEL_ARGS="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"
2015-06-19 20:26:56 +00:00
echo PWD=`pwd`
exec sudo xhyve -H -P \
-m 4G \
2015-06-19 20:26:56 +00:00
-s 0:0,hostbridge -s 31,lpc \
-l com1,stdio \
-s 2:0,virtio-net \
-s 3,ahci-cd,${CLOUD_CONFIG_ISO} \
2015-06-19 20:26:56 +00:00
-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