-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·73 lines (51 loc) · 1.29 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
BASEDIR=`dirname -- "$0"` || exit $?
BASEDIR=`realpath -- "${BASEDIR}"` || exit $?
. "${BASEDIR}/lib.subr"
main()
{
if [ $# -lt 1 ]; then
usage
exit ${EX_USAGE}
fi
local vm_bhyve_dir
vm_bhyve_dir=`sysrc -ni vm_dir`
if [ -z "${vm_bhyve_dir}" ]; then
err "Could not get vm(1) directory!"
exit ${EX_NOINPUT}
fi
local next_id
next_id=1
local vm_name=
while :; do
if [ ${next_id} -ge 999 ]; then
err "The maximum allocation has been made."
exit ${EX_NOPERM}
fi
local next_name
next_name=`printf "vm%003d" "${next_id}"`
if [ ! -d "${vm_bhyve_dir}/${next_name}" ]; then
vm_name="${next_name}"
break
fi
next_id=$((next_id+1))
done
local profile
profile="$1"
shift
if [ ! -d "${BASEDIR}/dirty" ]; then
mkdir -p "${BASEDIR}/dirty" || exit $?
fi
touch "${BASEDIR}/dirty/${vm_name}" || exit $?
"${BASEDIR}/profiles/${profile}.sh" \
"${vm_name}" "$@" || exit $?
info "Starting VM '${vm_name}'"
vm start "${vm_name}" || exit $?
rm -f "${BASEDIR}/dirty/${vm_name}" || exit $?
return ${EX_OK}
}
usage()
{
echo "deploy.sh <profile-name> [<args> ...]"
}
main "$@"