#!/bin/bash

GUEST_BINARY=$1

if [ -z ${GUEST_BINARY} ]
then
    echo "Usage: $0 <path-to-guest-executable-to-be-wrapped>"
    exit 1
fi

TARGET_DIR=`dirname ${GUEST_BINARY}`
if ! [ -d ${TARGET_DIR} ]; then
    echo "Trying to forward binary $GUEST_BINARY guest => host but host dir ${TARGET_DIR} doesn't exist"
    exit 1
fi

if [ -e ${GUEST_BINARY} ]; then
    echo "Trying to forward binary ${GUEST_BINARY} guest => host but the host one already exists."
    exit 1
fi
printf "#!/bin/bash\nexec exagear -- ${GUEST_BINARY} \"\$@\"\n" > ${GUEST_BINARY}
chmod +x ${GUEST_BINARY}



