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

147 lines
4.0 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)
UNAME=$(uname)
# Linux and Darwin SHA1 sum binary are different, pick which to use
if [ "$UNAME" == "Darwin" ]; then sha1sum=$(which shasum)
elif [ "$UNAME" == "Linux" ]; then sha1sum=$(which sha1sum);
fi
2015-02-09 04:38:37 +00:00
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
HD_GZ=${BASE}/assets/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
2015-07-23 13:53:01 +00:00
# PREREQ: brew install coreutils
path() {
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
2015-07-21 10:55:58 +00:00
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
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
popd
fi
2015-07-29 07:51:49 +00:00
if [ -e ${INITRD_CURRENT} ]; then
rm -f ${INITRD_CURRENT}
fi
ln -sf ${INITRD_TMP} ${INITRD_CURRENT}
2015-07-29 07:51:49 +00:00
mkdir -p ${INITRD_TMP}/usr/{bin,share/ros}
cp bin/rancheros ${INITRD_TMP}/usr/bin/ros
cp -f os-config.yml ${INITRD_TMP}/usr/share/ros
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})
if [ "$UNAME" == "Darwin" ]; then qemu-img create -f raw -o size=10G ${HD}
elif [ "$UNAME" == "Linux" ]; then gzip -dc ${HD_GZ} > ${HD};
fi
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-08-04 21:45:38 +00:00
KERNEL_ARGS="rancher.password=rancher rancher.modules=[9p,9pnet_virtio] console=ttyS0 ${QEMU_APPEND}"
2015-06-19 20:26:56 +00:00
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`
2015-09-01 14:11:02 +00:00
exec sudo -n xhyve -A -H -P -u \
-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} \
-s 4,virtio-blk,${HD} \
2015-06-19 20:26:56 +00:00
-U a01fb25c-3a19-4759-a47a-2e353e51807d \
-f kexec,${KERNEL},${INITRD_TEST},"earlyprintk=serial elevator=noop rancher.state.formatzero=true rancher.state.autoformat=[/dev/sda,/dev/vda] ${KERNEL_ARGS}"
2015-06-19 20:26:56 +00:00
2015-07-27 22:55:45 +00:00
elif [ "$UNAME" == "Linux" ] && [ -x $(which qemu-system-x86_64) ]; then
2015-06-19 20:26:56 +00:00
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 \
2015-07-27 22:55:45 +00:00
-nographic \
2015-06-19 20:26:56 +00:00
${QEMU_ARGS} "${@}"
else
exit 42
2015-07-27 22:55:45 +00:00
fi