github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/go/run/scripts/run_kvm.sh (about)

     1  #!/bin/bash
     2  
     3  if [ "$#" != "3" ]; then
     4  	echo "Must supply a CoreOS image, an SSH auth keys file, and a domain path."
     5  	exit 1
     6  fi
     7  
     8  set -o nounset
     9  set -o errexit
    10  
    11  gowhich() {
    12  	WHICH=$(which which)
    13  	echo -n "$(PATH="${GOPATH//://bin:}/bin" $WHICH "$1")"
    14  }
    15  
    16  IMG="$1"
    17  KEYS="$2"
    18  DOMAIN="$3"
    19  LINUXHOST="$(gowhich linux_host).img.tgz"
    20  if [ -e "$DOMAIN/aikblob" ]; then
    21    TYPE="TPM"
    22  else
    23    TYPE="Soft"
    24  fi
    25  
    26  # Make sure we have sudo privileges before running anything.
    27  sudo test true
    28  
    29  # Start linux_host in KVM mode.
    30  if [[ "$TYPE" == "TPM" ]]; then
    31    sudo "$(gowhich linux_host)" -hosted_program_type kvm_coreos \
    32  	  -kvm_coreos_img $IMG -kvm_coreos_ssh_auth_keys $KEYS \
    33  	  -config_path ${DOMAIN}/tao.config -host_type stacked \
    34  	  -host_channel_type tpm -pass BogusPass &
    35    HOSTPID=$!
    36  elif [[ "$TYPE" == "Soft" ]]; then
    37    sudo "$(gowhich linux_host)" -hosted_program_type kvm_coreos \
    38  	  -kvm_coreos_img $IMG -kvm_coreos_ssh_auth_keys $KEYS \
    39  	  -config_path ${DOMAIN}/tao.config -pass BogusPass &
    40    HOSTPID=$!
    41  else
    42    echo "Invalid host type '$TYPE'"
    43    exit 1
    44  fi
    45  
    46  echo "Waiting for the hypervisor Linux Host to start"
    47  sleep 2
    48  
    49  echo "About to start a virtual machine as a hosted program"
    50  # Start the VM with linux_host.
    51  LHTEMP=$(mktemp -d /tmp/kvm_linux_host.XXXXXXXX)
    52  SSHPORT=2222
    53  "$(gowhich tao_launch)" -sock ${DOMAIN}/linux_tao_host/admin_socket \
    54  	${LINUXHOST} ${LHTEMP} ${SSHPORT}
    55  
    56  echo "Waiting for the virtual machine to start"
    57  sleep 10
    58  # Move the binaries to the temporary directory, which is mounted using Plan9P on
    59  # the virtual machine.
    60  cp "$(gowhich demo_server)" "$(gowhich demo_client)" "$(gowhich tao_launch)" ${LHTEMP}
    61  
    62  # Ensure docker / CoreOS user, e.g. id=500(core), can access these binaries.
    63  # TODO(kwalsh) Mounting host directories seems to be discouraged... use scp?
    64  chmod a+rx ${LHTEMP}/{demo_server,demo_client,tao_launch}
    65  
    66  # Run tao_launch twice across SSH to start the demo programs. For the ssh
    67  # command to work, this session must have an ssh agent with the keys from
    68  # ${KEYS}.
    69  ssh -x -l core -p ${SSHPORT} localhost /media/tao/tao_launch \
    70  	-sock /media/tao/linux_tao_host/admin_socket /media/tao/demo_server \
    71  	-config /media/tao/tao.config &
    72  echo Waiting for the server to start
    73  sleep 2
    74  
    75  ssh -x -l core -p ${SSHPORT} localhost /media/tao/tao_launch \
    76  	-sock /media/tao/linux_tao_host/admin_socket /media/tao/demo_client \
    77  	-config /media/tao/tao.config -host 127.0.0.1 &
    78  echo Waiting for the client to run
    79  sleep 4
    80  
    81  scp -P ${SSHPORT} core@localhost:/tmp/demo_client.INFO /tmp/demo_client.INFO
    82  scp -P ${SSHPORT} core@localhost:/tmp/demo_server.INFO /tmp/demo_server.INFO
    83  echo -e "\n\nClient output:"
    84  cat /tmp/demo_client.INFO
    85  
    86  echo -e "\n\nServer output:"
    87  cat /tmp/demo_server.INFO
    88  
    89  echo -e "\n\nCleaning up"
    90  ssh -x -l core -p ${SSHPORT} localhost sudo shutdown -h now
    91  sudo kill $HOSTPID
    92  sudo rm -fr $LHTEMP /tmp/demo_server.INFO /tmp/demo_client.INFO
    93  sudo rm -f ${DOMAIN}/linux_tao_host/admin_socket