1#!/usr/bin/env bash
2
3die() {
4  cat <<EOF >&2
5Error: $@
6
7Usage: ${0} -c GENIMAGE_CONFIG_FILE
8EOF
9  exit 1
10}
11
12# Parse arguments and put into argument list of the script
13opts="$(getopt -n "${0##*/}" -o c: -- "$@")" || exit $?
14eval set -- "$opts"
15
16GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
17
18while true ; do
19	case "$1" in
20	-c)
21	  GENIMAGE_CFG="${2}";
22	  shift 2 ;;
23	--) # Discard all non-option parameters
24	  shift 1;
25	  break ;;
26	*)
27	  die "unknown option '${1}'" ;;
28	esac
29done
30
31[ -n "${GENIMAGE_CFG}" ] || die "Missing argument"
32
33# Pass an empty rootpath. genimage makes a full copy of the given rootpath to
34# ${GENIMAGE_TMP}/root so passing TARGET_DIR would be a waste of time and disk
35# space. We don't rely on genimage to build the rootfs image, just to insert a
36# pre-built one in the disk image.
37
38trap 'rm -rf "${ROOTPATH_TMP}"' EXIT
39ROOTPATH_TMP="$(mktemp -d)"
40
41rm -rf "${GENIMAGE_TMP}"
42
43genimage \
44	--rootpath "${ROOTPATH_TMP}"     \
45	--tmppath "${GENIMAGE_TMP}"    \
46	--inputpath "${BINARIES_DIR}"  \
47	--outputpath "${BINARIES_DIR}" \
48	--config "${GENIMAGE_CFG}"
49