2023-10-14 19:21:23 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Simple wrapper to call kiwi properly for image builds
|
|
|
|
# Author: Neal Gompa <ngompa@fedoraproject.org>
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
kiwibuildsh="$(basename "$0")"
|
|
|
|
|
|
|
|
usage() {
|
2024-08-09 14:49:58 +00:00
|
|
|
echo >&2 "usage: $kiwibuildsh [--kiwi-description-dir=DIR] [--kiwi-file=FILE] [--isolated] --output-dir=DIR --image-type=TYPE --image-profile=PROFILE [--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 --debug"
|
2024-05-31 11:30:42 +00:00
|
|
|
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"
|
2023-10-14 19:21:23 +00:00
|
|
|
exit 255
|
|
|
|
}
|
|
|
|
|
2024-08-09 14:49:58 +00:00
|
|
|
optTemp=$(getopt --options '+k:,f:,i,o:,t:,p:,d,h' --longoptions 'kiwi-description-dir:,kiwi-file:,isolated,output-dir:,image-type:,image-profile:,debug,help' --name "$kiwibuildsh" -- "$@")
|
2023-10-14 19:21:23 +00:00
|
|
|
eval set -- "$optTemp"
|
|
|
|
unset optTemp
|
|
|
|
|
|
|
|
output_dir=
|
|
|
|
image_type=
|
|
|
|
image_profile=
|
|
|
|
debug=
|
2024-08-09 14:49:58 +00:00
|
|
|
kiwi_isolated=
|
|
|
|
# For compatibility with older scripts where these did not exist
|
|
|
|
kiwi_description_dir="./"
|
|
|
|
kiwi_file="Fedora.kiwi"
|
2023-10-14 19:21:23 +00:00
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2024-05-31 11:30:42 +00:00
|
|
|
-i|--isolated) kiwi_isolated=1; shift ;;
|
2023-12-18 23:59:25 +00:00
|
|
|
-k|--kiwi-description-dir) kiwi_description_dir="$2" ; shift 2 ;;
|
2024-08-09 14:49:58 +00:00
|
|
|
-f|--kiwi-file) kiwi_file="$2" ; shift 2 ;;
|
2023-10-14 19:21:23 +00:00
|
|
|
-o|--output-dir) output_dir="$2" ; shift 2 ;;
|
|
|
|
-t|--image-type) image_type="$2" ; shift 2 ;;
|
|
|
|
-p|--image-profile) image_profile="$2" ; shift 2 ;;
|
|
|
|
-d|--debug) debug="--debug" ; shift ;;
|
|
|
|
-h|--help) usage ;;
|
|
|
|
--) shift ; break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-08-09 14:49:58 +00:00
|
|
|
if [ -z "$output_dir" ] || [ -z "$image_type" ] || [ -z "$image_profile" ] || [ -z "$kiwi_file" ]; then
|
2023-10-14 19:21:23 +00:00
|
|
|
echo "Options not set!"
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2024-05-31 11:30:42 +00:00
|
|
|
if [ ! ${kiwi_isolated} ] && [ -e "/sys/fs/selinux/enforce" ]; then
|
2023-10-14 19:21:23 +00:00
|
|
|
# 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
|
|
|
|
|
2023-12-18 23:59:25 +00:00
|
|
|
set +e
|
2024-05-31 11:30:42 +00:00
|
|
|
if [ ! ${kiwi_isolated} ]; then
|
2024-08-09 14:49:58 +00:00
|
|
|
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}"
|
2024-05-31 11:30:42 +00:00
|
|
|
else
|
2024-08-09 14:49:58 +00:00
|
|
|
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}"
|
2024-05-31 11:30:42 +00:00
|
|
|
fi
|
2023-12-18 23:59:25 +00:00
|
|
|
kiwi_status=$?
|
|
|
|
set -e
|
2023-10-14 19:21:23 +00:00
|
|
|
|
2024-05-31 11:30:42 +00:00
|
|
|
if [ ! ${kiwi_isolated} ] && [ -e "/sys/fs/selinux/enforce" ]; then
|
2023-10-14 19:21:23 +00:00
|
|
|
# Re-enable SELinux enforcement now that image build is done
|
|
|
|
if [ "$selinux_enforcing" = "1" ]; then
|
|
|
|
setenforce 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $kiwi_status
|