#!/bin/sh
# Copyright (C) 2014-2015 Jurriaan Bremer.
# This file is part of VMCloak - http://www.vmcloak.org/.
# See the file 'docs/LICENSE.txt' for copying permission.

if [ "$1" = "-h" ]; then
    echo "Usage: $0 <ipaddr>"
    echo "    $0 192.168.57.1"
    echo
    echo "Defaults to:"
    echo "    $0 192.168.56.1"
    exit
fi

# Only create a new hostonly interface if it does not already exist.
if [ -z "$(VBoxManage list hostonlyifs)" ]; then
    VBoxManage hostonlyif create
fi

if [ "$#" -ne 0 ]; then
    IPADDR="$1"
else
    IPADDR="192.168.56.1"
fi

# Configure the hostonly interface and automatically enable it (also in
# case it already existed but was disabled).
VBoxManage hostonlyif ipconfig vboxnet0 --ip "$IPADDR"
