#!/usr/bin/env bash export QEMU_AUDIO_DRV=alsa export GIT_PROJECT=kameleon export ROOT_PROJECT=$(dirname $(readlink -f ${BASH_SOURCE[0]})) export KAMELEON_LOG=${KAMELEON_LOG:-"info"} # enable kameleon autocompletion source $ROOT_PROJECT/completion/kameleon.bash QEMU_MONITOR_PORT=11023 function kameleon { sudo -E BUNDLE_GEMFILE=$ROOT_PROJECT/Gemfile bundle exec kameleon $@ } function runtest { sudo -E BUNDLE_GEMFILE=$ROOT_PROJECT/Gemfile bundle exec rake $@ } function devrun_chroot_clean() { mount \ | grep rootfs | grep kameleon \ | py "s='rootfs'" "l=x.split(' ')[2].split(s)[0]" "print(l)" \ | uniq \ | xargs -I {} sudo bash "$ROOT_PROJECT"/contrib/scripts/umount-chroot.sh -p -f -a -k -y -c "{}" } function devrun_clear() { KAMELEON_WORKDIR=${KAMELEON_WORKDIR:-"/tmp/kameleon/"} RECIPE_DEV_NAME=${RECIPE_DEV_NAME:-"mymachine"} devrun_chroot_clean cd $KAMELEON_WORKDIR kameleon clear $RECIPE_DEV_NAME.yaml if [ -d "$KAMELEON_WORKDIR/build" ]; then sudo rm "$KAMELEON_WORKDIR/build" -fr 2> /dev/null fi } function devrun_qemu_stop() { if nc -w 0 -z localhost $QEMU_MONITOR_PORT 2>/dev/null then echo "Shutting down qemu virtual machine" echo "system_reset" | nc localhost $QEMU_MONITOR_PORT echo "" fi while nc -w 0 -z localhost $QEMU_MONITOR_PORT do sleep 0.5 echo -n "." done echo " ~> OK" } function devrun_qemu() { KAMELEON_WORKDIR=${KAMELEON_WORKDIR:-"/tmp/kameleon/"} RECIPE_DEV_NAME=${RECIPE_DEV_NAME:-"mymachine"} DRIVE="$KAMELEON_WORKDIR/build/$RECIPE_DEV_NAME/${RECIPE_DEV_NAME}.qcow2" RAM_COUNT=2048 SPICE_PORT=5900 CPU_COUNT=2 sudo qemu-system-x86_64 \ -name "$VM_NAME" \ -machine pc-1.2,accel=kvm,usb=off -m 2048 -realtime mlock=off \ -smp $CPU_COUNT \ -drive file="$DRIVE",cache=none,media=disk,if=virtio,id=drive0 \ -m $RAM_COUNT \ -no-reboot \ -rtc base=utc \ -soundhw ac97 \ -net nic,model=virtio -net user \ -usb \ -usbdevice tablet \ -vga qxl \ -spice port=$SPICE_PORT,addr=127.0.0.1,disable-ticketing,image-compression=auto_lz \ -device virtio-serial-pci \ -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ -chardev spicevmc,id=spicechannel0,name=vdagent \ -monitor tcp::$QEMU_MONITOR_PORT,server,nowait \ -daemonize spicec -h 127.0.0.1 -p $SPICE_PORT --title "$VM_NAME" || : devrun_qemu_stop } function devrun_build() { KAMELEON_WORKDIR=${KAMELEON_WORKDIR:-"/tmp/kameleon/"} RECIPE_DEV_NAME=${RECIPE_DEV_NAME:-"mymachine"} TEMPLATE=${1:-"debian7"} mkdir -p $KAMELEON_WORKDIR && cd $KAMELEON_WORKDIR cmd="kameleon new $RECIPE_DEV_NAME $TEMPLATE \ && kameleon build $RECIPE_DEV_NAME.yaml" eval "$cmd" if [ -d "$KAMELEON_WORKDIR/build/$RECIPE_DEV_NAME" ]; then cd "$KAMELEON_WORKDIR/build/$RECIPE_DEV_NAME" fi }