aboutsummaryrefslogtreecommitdiff
path: root/kiwi-build
blob: 04d1ca9ddf77884c70c0282746ea1cfc046513d9 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash

# Simple wrapper to call kiwi properly for image builds
# Author: Neal Gompa <ngompa@fedoraproject.org>

set -eu -o pipefail

kiwibuildsh="$(basename "$0")"
kiwibuild_scriptdir="$(dirname "$0")"

usage() {
	echo >&2 "usage: $kiwibuildsh [--kiwi-description-dir=DIR] [--kiwi-file=FILE] [--isolated] --output-dir=DIR --image-type=TYPE --image-profile=PROFILE [--image-release=RELEASEID] [--debug]"
	echo >&2 "   eg: $kiwibuildsh --kiwi-description-dir=/var/tmp/desc --kiwi-file=config.kiwi --output-dir=/var/tmp/work --image-type=oem --image-profile=Cloud-Base-Generic --image-release=0 --debug"
	echo >&2 "   eg: $kiwibuildsh --output-dir=/var/tmp/work --image-type=oem --image-profile=Cloud-Base-Generic"
	echo >&2 "   eg: $kiwibuildsh --isolated --output-dir=/var/tmp/work --image-type=oem --image-profile=Cloud-Base-Generic"
	exit 255
}

optTemp=$(getopt --options '+k:,f:,i,o:,t:,p:,r:,d,h' --longoptions 'kiwi-description-dir:,kiwi-file:,isolated,output-dir:,image-type:,image-profile:,image-release:,debug,help' --name "$kiwibuildsh" -- "$@")
eval set -- "$optTemp"
unset optTemp

output_dir=
image_type=
image_profile=
image_release=
debug=
kiwi_isolated=
# For compatibility with older scripts where these did not exist
kiwi_description_dir="./"
kiwi_file="Fedora.kiwi"
kiwibuild_extra_args=

while true; do
	case "$1" in
		-i|--isolated) kiwi_isolated=1; shift ;;
		-k|--kiwi-description-dir) kiwi_description_dir="$2" ; shift 2 ;;
		-f|--kiwi-file) kiwi_file="$2" ; shift 2 ;;
		-o|--output-dir) output_dir="$2" ; shift 2 ;;
		-t|--image-type) image_type="$2" ; shift 2 ;;
		-p|--image-profile) image_profile="$2" ; shift 2 ;;
		-r|--image-release) image_release="$2" ; shift 2 ;;
		-d|--debug) debug="--debug" ; shift ;;
		-h|--help) usage ;;
		--) shift ; break ;;
	esac
done

if [ -z "$output_dir" ] || [ -z "$image_type" ] || [ -z "$image_profile" ] || [ -z "$kiwi_file" ]; then
	echo "Options not set!"
	usage
fi

# Set the bundle format after we know the profile
kiwi_bundle_format=$("${kiwibuild_scriptdir}/scripts/fedora-kiwi-bundle-format-generator" "${kiwi_file}" "${image_profile}")

if [ "$image_type" = "iso" ]; then
	# Add parameters for embedded ISO IDs
	kiwibuild_extra_args=$("${kiwibuild_scriptdir}/scripts/fedora-live-iso-label-generator" "${kiwi_file}" "${image_profile}" --output-kiwi-args)
fi

if [ "$image_type" = "oci" ]; then
	# Extend for OCI images
	kiwi_bundle_format="${kiwi_bundle_format}.%T"
fi

if [ ! ${kiwi_isolated} ] && [ -e "/sys/fs/selinux/enforce" ]; then
	# Disable SELinux enforcement during the image build if it's enforcing
	selinux_enforcing="$(cat /sys/fs/selinux/enforce)"
	if [ "$selinux_enforcing" = "1" ]; then
		setenforce 0
	fi
fi

set +e
if [ ! ${kiwi_isolated} ]; then
kiwi-ng ${debug} --type="${image_type}" --profile="${image_profile}" --kiwi-file="${kiwi_file}" --color-output system build --description "${kiwi_description_dir}" --target-dir "${output_dir}-build" ${kiwibuild_extra_args}
else
kiwi-ng ${debug} --type="${image_type}" --profile="${image_profile}" --kiwi-file="${kiwi_file}" --color-output system boxbuild --box universal --sshfs-sharing -- --description "${kiwi_description_dir}" --target-dir "${output_dir}-build" ${kiwibuild_extra_args}
fi
kiwi_status=$?
set -e

if [ ! ${kiwi_isolated} ] && [ -e "/sys/fs/selinux/enforce" ]; then
	# Re-enable SELinux enforcement now that image build is done
	if [ "$selinux_enforcing" = "1" ]; then
		setenforce 1
	fi
fi

if [ "${kiwi_status}" = "0" ] && [ -n "$image_release" ]; then
	kiwi-ng ${debug} result bundle --bundle-format="${kiwi_bundle_format}" --target-dir "${output_dir}-build" --bundle-dir "${output_dir}" --id="${image_release}"
fi
exit $kiwi_status