Skip to content

Commit

Permalink
Merge pull request #8 from zaneb/metal-script
Browse files Browse the repository at this point in the history
Add convenience script for metal platform
  • Loading branch information
openshift-merge-robot authored Dec 10, 2021
2 parents 6894fb4 + 7884fb6 commit bde7141
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 8 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ PXE files respectively to a volume that is bound into the container. Pass the
destination path as an argument. For example:

podman run --rm -v .:/data:bind /bin/copy-iso /data

For the `copy-iso` script, if the `IP_OPTIONS` environment variable is
non-empty then the output ISO will be configured to add the provided option to
the kernel command line.

The script `/bin/copy-metal` calls `copy-iso` and `copy-pxe` to copy the
specific files needed for parts of the baremetal platform, depending on the
first argument: `--all` for all files; `--pxe` for just the PXE files; or
`--image-build` for just the ISO and initrd. In addition, symlinks are created
so that filenames match the ones used in previous versions of the metal
platform.
13 changes: 11 additions & 2 deletions scripts/copy-iso
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ copy_if_needed() {

dest_file="${DEST_DIR}/$(basename "${source}")"

if [ -f "${dest_file}" ] && [ "$(sha256sum "${dest_file}" | cut -d' ' -f1)" = "$(cat "${source}.sha256")" ]; then
if [ -f "${dest_file}" ] && [ "$(cat "${dest_file}.sha256")" = "$(cat "${source}.sha256")" ]; then
echo "${dest_file} is already up to date" >&2
else
cp "${source}" "${DEST_DIR}"
rm -f "${dest_file}.sha256"
echo "Extracting ISO file" >&2
if [ -n "${IP_OPTIONS:-}" ]; then
echo "Adding kernel argument ${IP_OPTIONS}" >&2
coreos-installer iso kargs modify -a "${IP_OPTIONS}" -o "${dest_file}" "${source}"
else
cp "${source}" "${DEST_DIR}"
echo "${dest_file}"
fi
cp "${source}.sha256" "${DEST_DIR}"
fi
}

Expand Down
44 changes: 44 additions & 0 deletions scripts/copy-metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -e

script_dir="$(dirname "$0")"
arch="$(uname -p)"

custom=false
fixed=false
case "$1" in
--image-build)
shift
custom=true
;;
--pxe)
shift
fixed=true
;;
--all)
shift
;&
*)
custom=true
fixed=true
;;
esac

DEST_DIR="$1"

if [ $fixed = true ]; then
"${script_dir}/copy-pxe" "${DEST_DIR}"
ln -f -s "coreos-${arch}-vmlinuz" "${DEST_DIR}/ironic-python-agent.kernel"
ln -f -s "coreos-${arch}-rootfs.img" "${DEST_DIR}/ironic-python-agent.rootfs"
else
"${script_dir}/copy-pxe" --initrd-only "${DEST_DIR}"
rm -f "${DEST_DIR}"/coreos-*-vmlinuz "${DEST_DIR}"/coreos-*-rootfs.img
fi

if [ $custom = true ]; then
ln -f -s "coreos-${arch}-initrd.img" "${DEST_DIR}/ironic-python-agent.initramfs"

"${script_dir}/copy-iso" "${DEST_DIR}"
ln -f -s "coreos-${arch}.iso" "${DEST_DIR}/ironic-python-agent.iso"
fi
25 changes: 19 additions & 6 deletions scripts/copy-pxe
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

if [ "$1" = "--initrd-only" ]; then
INITRD_ONLY=true
shift
fi

ISO_DIR="/coreos"
DEST_DIR="$1"

Expand All @@ -11,14 +16,22 @@ extract_if_needed() {
local dest_base
dest_base="${DEST_DIR}/$(basename --suffix=.iso "${source}")"

# TODO: arguably we should record the checksums of all these files at
# build time, so that we can verify the actual files and not just use the
# checksum file as a signal.
if [ -f "${dest_base}-vmlinuz" ] && [ -f "${dest_base}-initrd.img" ]&& [ -f "${dest_base}-rootfs.img" ] && [ -f "${dest_base}.iso.sha256" ] && [ "$(cat "${dest_base}.iso.sha256")" = "$(cat "${source}.sha256")" ]; then
echo "${dest_base}-[vmlinuz|initrd.img|rootfs.img] are already up to date" >&2
if [ -f "${dest_base}.pxe.sha256" ] && \
[ "$(cat "${dest_base}.pxe.sha256")" = "$(cat "${source}.sha256")" ] && \
[ -f "${dest_base}-initrd.img" ] && \
( [[ "${INITRD_ONLY:-false}" =~ [Tt]rue ]] || \
[ -f "${dest_base}-vmlinuz" -a -f "${dest_base}-rootfs.img" ] ); then
if [ "$2" = "--initrd-only" ]; then
echo "${dest_base}-initrd.img is already up to date" >&2
else
echo "${dest_base}-[vmlinuz|initrd.img|rootfs.img] are already up to date" >&2
fi
else
rm -f "${dest_base}.pxe.sha256"
rm -f "${dest_base}-vmlinuz" "${dest_base}-initrd.img" "${dest_base}-rootfs.img"
echo "extracting PXE files..." >&2
coreos-installer iso extract pxe -o "${DEST_DIR}" "${source}"
cp "${source}.sha256" "${DEST_DIR}"
cp "${source}.sha256" "${dest_base}.pxe.sha256"
fi
}

Expand Down

0 comments on commit bde7141

Please sign in to comment.