mk-vmimage.sh revision 274134
1272234Sgjb#!/bin/sh
2272234Sgjb#-
3272234Sgjb# Copyright (c) 2014 The FreeBSD Foundation
4272234Sgjb# All rights reserved.
5272234Sgjb#
6272234Sgjb# This software was developed by Glen Barber under sponsorship
7272234Sgjb# from the FreeBSD Foundation.
8272234Sgjb#
9272234Sgjb# Redistribution and use in source and binary forms, with or without
10272234Sgjb# modification, are permitted provided that the following conditions
11272234Sgjb# are met:
12272234Sgjb# 1. Redistributions of source code must retain the above copyright
13272234Sgjb#    notice, this list of conditions and the following disclaimer.
14272234Sgjb# 2. Redistributions in binary form must reproduce the above copyright
15272234Sgjb#    notice, this list of conditions and the following disclaimer in the
16272234Sgjb#    documentation and/or other materials provided with the distribution.
17272234Sgjb#
18272234Sgjb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19272234Sgjb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20272234Sgjb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21272234Sgjb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22272234Sgjb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23272234Sgjb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24272234Sgjb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25272234Sgjb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26272234Sgjb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27272234Sgjb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28272234Sgjb# SUCH DAMAGE.
29272234Sgjb#
30272234Sgjb# mk-vmimage.sh: Create virtual machine disk images in various formats.
31272234Sgjb#
32272234Sgjb# $FreeBSD: projects/release-vmimage/release/scripts/mk-vmimage.sh 274134 2014-11-05 13:22:19Z gjb $
33272234Sgjb#
34272234Sgjb
35274134Sgjbmain() {
36274134Sgjb	local arg
37274134Sgjb	while getopts "C:c:d:f:i:o:s:S:" arg; do
38274134Sgjb		case "${arg}" in
39274134Sgjb			C)
40274134Sgjb				VMBUILDCONF="${OPTARG}"
41274134Sgjb				;;
42274134Sgjb			c)
43274134Sgjb				VMCONFIG="${OPTARG}"
44274134Sgjb				;;
45274134Sgjb			d)
46274134Sgjb				DESTDIR="${OPTARG}"
47274134Sgjb				;;
48274134Sgjb			f)
49274134Sgjb				VMFORMAT="${OPTARG}"
50274134Sgjb				;;
51274134Sgjb			i)
52274134Sgjb				VMBASE="${VMBASE}"
53274134Sgjb				;;
54274134Sgjb			o)
55274134Sgjb				VMIMAGE="${OPTARG}"
56274134Sgjb				;;
57274134Sgjb			s)
58274134Sgjb				VMSIZE="${OPTARG}"
59274134Sgjb				;;
60274134Sgjb			S)
61274134Sgjb				WORLDDIR="${OPTARG}"
62274134Sgjb				;;
63274134Sgjb			*)
64274134Sgjb				;;
65274134Sgjb		esac
66272234Sgjb	done
67274134Sgjb	shift $(( ${OPTIND} - 1))
68272234Sgjb
69274134Sgjb	if [ -z "${VMBASE}" -o \
70274134Sgjb		-z "${WORLDDIR}" -o \
71274134Sgjb		-z "${DESTDIR}" -o \
72274134Sgjb		-z "${VMSIZE}" -o \
73274134Sgjb		-z "${VMIMAGE}" -o \
74274134Sgjb		-z "${VMCONFIG}" ];
75274134Sgjb	then
76272380Sgjb		usage
77272380Sgjb	fi
78272380Sgjb
79274134Sgjb	if [ -z "${VMBUILDCONF}" ] || [ ! -e "${VMBUILDCONF}" ]; then
80274134Sgjb		echo "Must provide the path to vmimage.subr."
81274134Sgjb		return 1
82272234Sgjb	fi
83272234Sgjb
84274134Sgjb	. "${VMBUILDCONF}"
85274134Sgjb
86274134Sgjb	if [ ! -z "${VMCONFIG}" ] && [ -e "${VMCONFIG}" ]; then
87274134Sgjb		. "${VMCONFIG}"
88272234Sgjb	fi
89272234Sgjb
90274134Sgjb	vm_install_base
91274134Sgjb	vm_extra_install_base
92274134Sgjb	vm_extra_install_packages
93274134Sgjb	vm_extra_install_ports
94274134Sgjb	vm_extra_enable_services
95274134Sgjb	vm_extra_pre_umount
96274134Sgjb	vm_create_disk
97274134Sgjb	vm_extra_create_disk
98272234Sgjb
99272234Sgjb	return 0
100272234Sgjb}
101272234Sgjb
102272234Sgjbmain "$@"
103