Skip to content

Instantly share code, notes, and snippets.

@Maddosaurus
Created May 17, 2023 09:22
Show Gist options
  • Save Maddosaurus/0c31750e220da7878575ff25a546830e to your computer and use it in GitHub Desktop.
Save Maddosaurus/0c31750e220da7878575ff25a546830e to your computer and use it in GitHub Desktop.
RHCOS Minimal FS Automation
#!/usr/bin/env bash
# set -euo pipefail
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "Exactly one argument required: target RHCOS version, e.g. '4.12'. $# provided."
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
TMPDIR=$(mktemp -d)
IMG_FILENAME="rhcos-live-rootfs.x86_64.img"
IMG_PATH="$TMPDIR/$IMG_FILENAME"
function download_fs {
TARGET_IMAGE="https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/"$1"/latest/rhcos-live-rootfs.x86_64.img"
echo "Downloading image from $TARGET_IMAGE"
curl "$TARGET_IMAGE" -o "$IMG_PATH"
}
function unpack_image {
cpio -idv < "$IMG_FILENAME"
unsquashfs -no-xattrs -f -d sqfs root.squashfs
}
function copy_contents {
TARGET="$SCRIPT_DIR/../testdata/NodeScanning/rhcos/$1"
echo "Copying needed filed to $TARGET"
mkdir -p "$TARGET/usr/lib"
mkdir -p "$TARGET/usr/share"
mkdir -p "$TARGET/etc"
cp "$ROOTFS_PATH/usr/lib/system-release" "$TARGET/usr/lib/system-release"
ln -s "../usr/lib/system-release" "$TARGET/etc/system-release"
cp "$ROOTFS_PATH/etc/os-release" "$TARGET/etc/os-release"
cp -R "$ROOTFS_PATH/usr/share/rpm" "$TARGET/usr/share/rpm"
cp -R "$ROOTFS_PATH/usr/share/buildinfo" "$TARGET/usr/share/buildinfo"
}
echo "Script called from $SCRIPT_DIR"
echo "Set workdir to $TMPDIR"
cd $TMPDIR
echo "Downloading live image..."
download_fs "$1"
echo "Unpacking image..."
unpack_image
ROOTFS_PATH=$(find sqfs/ostree/deploy/rhcos/deploy -name run -exec dirname {} \;)
echo "Found base path for RHCOS root fs at $ROOTFS_PATH"
echo "Collecting needed files..."
copy_contents "$1"
echo "Cleaning up tmp folder..."
trap 'rm -rf -- "$TMPDIR"' EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment