@@ -8,14 +8,20 @@ set -eux -o pipefail
88# Invocation of the script would look something like this:
99#
1010# sudo ./custom-coreos-disk-images.sh \
11- # /path/to/coreos.ociarchive qemu
11+ # --ociarchive /path/to/coreos.ociarchive --platforms qemu
1212#
1313# And it will create the output file in the current directory:
14- # coreos.ociarchive.x86_64.qemu.qcow2
14+ # - coreos.ociarchive.x86_64.qemu.qcow2
15+ #
16+ # Passing multple platforms will yield multiple disk images:
17+ #
18+ # sudo ./custom-coreos-disk-images.sh \
19+ # --ociarchive /path/to/coreos.ociarchive --platforms qemu,metal
20+ #
21+ # - coreos.ociarchive.x86_64.qemu.qcow2
22+ # - coreos.ociarchive.x86_64.metal.qcow2
1523
1624ARCH=$( arch)
17- OCIARCHIVE=$1
18- PLATFORM=$2
1925
2026check_rpm () {
2127 req=$1
@@ -34,6 +40,44 @@ check_rpms() {
3440
3541main () {
3642
43+ # Call getopt to validate the provided input.
44+ options=$( getopt --options - --longoptions ' imgref:,ociarchive:,osname:,platforms:' -- " $@ " )
45+ if [ $? -ne 0 ]; then
46+ echo " Incorrect options provided"
47+ exit 1
48+ fi
49+ eval set -- " $options "
50+ while true ; do
51+ case " $1 " in
52+ --imgref)
53+ shift # The arg is next in position args
54+ IMGREF=$1
55+ ;;
56+ --ociarchive)
57+ shift ; # The arg is next in position args
58+ OCIARCHIVE=$1
59+ ;;
60+ --osname)
61+ shift # The arg is next in position args
62+ OSNAME=$1
63+ if [ $OSNAME ! ~ rhcos| fedora-coreos ]; then
64+ echo " --osname must be rhcos or fedora-coreos" >&2
65+ exit 1
66+ fi
67+ ;;
68+ --platforms)
69+ shift # The arg is next in position args
70+ # Split the comma separated string of platforms into an array
71+ IFS=, read -ra PLATFORMS <<< " $1"
72+ ;;
73+ --)
74+ shift
75+ break
76+ ;;
77+ esac
78+ shift
79+ done
80+
3781 # Make sure RPMs are installed
3882 check_rpms
3983 # Make sure SELinux is permissive
@@ -54,6 +98,21 @@ main() {
5498 # Convert it to an absolute path
5599 OCIARCHIVE=$( readlink -f $OCIARCHIVE )
56100
101+ # Let's set the imgref. If no --imgref was provided then for cosmetic
102+ # purposes let's set a sane looking one.
103+ imgref=" ${IMGREF:- ostree-image-signed: oci-archive:/ $(basename " ${OCIARCHIVE} " )} "
104+
105+ # Let's default to `rhcos` for the OS Name for backwards compat
106+ osname=" ${OSNAME:- rhcos} "
107+
108+ # FCOS/RHCOS have different default disk image sizes
109+ # In the future should pull this from the container image
110+ # (/usr/share/coreos-assembler/image.json)
111+ image_size=10240 # FCOS
112+ if [ $osname == ' rhcos' ]; then
113+ image_size=16384 # RHCOS
114+ fi
115+
57116 # Make a local tmpdir
58117 mkdir -p tmp; rm -f tmp/*
59118
@@ -69,12 +128,8 @@ main() {
69128 done
70129 popd
71130
72- platforms=($PLATFORM )
73-
74- # It's mostly cosmetic, but let's set a sane looking container-imgref
75- imgref=" ostree-image-signed:oci-archive:/$( basename " ${OCIARCHIVE} " ) "
76131
77- for platform in " ${platforms [@]} " ; do
132+ for platform in " ${PLATFORMS [@]} " ; do
78133
79134 suffix=
80135 case $platform in
@@ -101,13 +156,13 @@ main() {
101156 # in the future. https://github.com/openshift/os/blob/master/image.yaml
102157 cat > tmp/diskvars.json << EOF
103158{
104- "osname": "rhcos ",
159+ "osname": "${osname} ",
105160 "deploy-via-container": "true",
106161 "ostree-container": "${OCIARCHIVE} ",
107162 "image-type": "${platform} ",
108163 "container-imgref": "${imgref} ",
109164 "metal-image-size": "3072",
110- "cloud-image-size": "16384 ",
165+ "cloud-image-size": "${image_size} ",
111166 "rootfs-size": "0",
112167 "extra-kargs-string": ""
113168}
0 commit comments