2015-06-24 09:37:22 +01:00
|
|
|
#!/bin/sh
|
2015-06-29 11:14:42 +01:00
|
|
|
#-------------------------------------------------------------------------+
|
|
|
|
|
# Copyright (C) 2015 Matt Churchyard (churchers@gmail.com)
|
|
|
|
|
# All rights reserved
|
|
|
|
|
#
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted providing that the following conditions
|
|
|
|
|
# are met:
|
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
|
#
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
|
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
|
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
2015-11-11 15:22:56 +00:00
|
|
|
VERSION=0.9.13
|
2015-10-15 10:32:21 +01:00
|
|
|
PATH=${PATH}:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
|
2015-10-19 10:11:20 +01:00
|
|
|
BSD_VERSION=$(uname -K)
|
2015-06-24 09:37:22 +01:00
|
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
load_rc_config "vm"
|
|
|
|
|
|
2015-06-29 11:14:42 +01:00
|
|
|
# get libs
|
2015-10-18 10:56:57 +01:00
|
|
|
if [ -e "./lib/vm-core" ]; then
|
2015-06-30 10:21:30 +01:00
|
|
|
LIB="./lib"
|
2015-10-18 10:43:35 +01:00
|
|
|
elif [ -e "/usr/local/lib/vm-bhyve" ]; then
|
|
|
|
|
LIB="/usr/local/lib/vm-bhyve"
|
2015-06-29 11:14:42 +01:00
|
|
|
else
|
2015-08-07 10:05:14 +01:00
|
|
|
echo "unable to locate vm-bhyve libriaries"
|
|
|
|
|
exit 1
|
2015-06-29 11:14:42 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# load libs
|
2015-10-18 11:27:32 +01:00
|
|
|
. "${LIB}/vm-cmd"
|
2015-06-29 11:14:42 +01:00
|
|
|
. "${LIB}/vm-common"
|
2015-10-14 11:11:59 +01:00
|
|
|
. "${LIB}/vm-config"
|
2015-06-29 11:14:42 +01:00
|
|
|
. "${LIB}/vm-core"
|
2015-11-11 15:22:56 +00:00
|
|
|
. "${LIB}/vm-info"
|
2015-08-08 12:21:01 +01:00
|
|
|
. "${LIB}/vm-guest"
|
2015-10-18 11:27:32 +01:00
|
|
|
. "${LIB}/vm-run"
|
|
|
|
|
. "${LIB}/vm-switch"
|
|
|
|
|
. "${LIB}/vm-sysrc"
|
2015-08-06 19:31:08 +01:00
|
|
|
. "${LIB}/vm-zfs"
|
2015-06-29 11:14:42 +01:00
|
|
|
|
2015-08-06 16:23:32 +01:00
|
|
|
# check environment
|
|
|
|
|
[ `id -u` -ne 0 ] && __err "virtual machines can only be managed by root"
|
2015-10-19 10:11:20 +01:00
|
|
|
[ ${BSD_VERSION} -lt 1000000 ] && __err "please upgrade to FreeBSD 10 or newer for bhyve support"
|
2015-08-06 16:23:32 +01:00
|
|
|
|
|
|
|
|
# we should be enabled in rc.conf
|
|
|
|
|
if ! checkyesno vm_enable; then
|
2015-08-08 12:21:01 +01:00
|
|
|
__err "\$vm_enable is not enabled in /etc/rc.conf!"
|
2015-08-06 16:23:32 +01:00
|
|
|
fi
|
|
|
|
|
|
2015-08-06 19:31:08 +01:00
|
|
|
# init for zfs
|
|
|
|
|
__zfs_init
|
|
|
|
|
|
2015-08-06 16:23:32 +01:00
|
|
|
# create directories as needed
|
|
|
|
|
[ ! -d "${vm_dir}" ] && __err "\$vm_dir has not been configured or is not a valid directory"
|
|
|
|
|
[ ! -d "${vm_dir}/.config" ] && mkdir "${vm_dir}/.config"
|
2015-10-08 14:57:43 +01:00
|
|
|
[ ! -e "${vm_dir}/.config/null.iso" ] && touch "${vm_dir}/.config/null.iso"
|
2015-08-06 16:23:32 +01:00
|
|
|
[ ! -d "${vm_dir}/.templates" ] && mkdir "${vm_dir}/.templates"
|
|
|
|
|
[ ! -d "${vm_dir}/.iso" ] && mkdir "${vm_dir}/.iso"
|
|
|
|
|
|
2015-06-30 10:21:30 +01:00
|
|
|
__parse_cmd "$@"
|