Skip to content

Instantly share code, notes, and snippets.

@treydock
Created October 24, 2012 15:39
Show Gist options
  • Save treydock/3946825 to your computer and use it in GitHub Desktop.
Save treydock/3946825 to your computer and use it in GitHub Desktop.
Find current kernel version in mock environment
#!/bin/bash
ARCH=$(uname -m)
[ "$ARCH" == "x86_64" ] && INV_ARCH="i686" || INV_ARCH="x86_64"
KERNEL=$(uname -r)
echo $KERNEL | grep -q $ARCH
[ $? -ne 0 ] && echo ${KERNEL//$INV_ARCH/$ARCH} || echo $KERNEL
@treydock
Copy link
Author

Problem

When building RPMs within a mock chroot, uname returns the kernel of running system not the chroot. This is problematic if a Makefile uses uname -r to find the kernel source when the mock environment is i686 and build system is x86_64.

Example Usage

rpm.spec

%define kernel_v %(ARCH=$(uname -m)
[ "$ARCH" == "x86_64" ] && INV_ARCH="i686" || INV_ARCH="x86_64"
KERNEL=$(uname -r)

uname -r | grep -q $ARCH

[ $? -ne 0 ] && echo ${KERNEL//$INV_ARCH/$ARCH} || echo $KERNEL)

...

export KERNELSRC="/usr/src/kernels/%{kernel_v}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment