Skip to content

Commit

Permalink
Merge pull request #67 from dalehamel/generic-header-install
Browse files Browse the repository at this point in the history
feat(init): support installing headers on generic linux distributions
  • Loading branch information
fntlnz committed Mar 17, 2019
2 parents e3df37d + f24c7bb commit 95d5374
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions init/fetch-linux-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ generate_headers()
zcat /proc/config.gz > .config
make ARCH=x86 oldconfig > /dev/null
make ARCH=x86 prepare > /dev/null

# Clean up abundant non-header files to speed-up copying
find ${BUILD_DIR} -regex '.*\.c\|.*\.txt\|.*Makefile\|.*Build\|.*Kconfig' -type f -delete
}

fetch_cos_linux_sources()
Expand All @@ -23,6 +26,16 @@ fetch_cos_linux_sources()
curl -s "https://storage.googleapis.com/cos-tools/${BUILD_ID}/kernel-src.tar.gz" | tar -xzf - -C ${BUILD_DIR}
}

fetch_generic_linux_sources()
{
kernel_version=$(uname -r | tr -d '+')
major_version=$(echo ${kernel_version} | cut -d . -f 1)
echo "Fetching upstream kernel sources for ${kernel_version}."
mkdir -p ${BUILD_DIR}
curl -sL https://www.kernel.org/pub/linux/kernel/v${major_version}.x/linux-$kernel_version.tar.gz | tar --strip-components=1 -xzf - -C ${BUILD_DIR}

}

install_cos_linux_headers()
{
if grep -q CHROMEOS_RELEASE_VERSION ${LSB_FILE};then
Expand All @@ -31,15 +44,29 @@ install_cos_linux_headers()
SOURCES_DIR="${TARGET_DIR}/linux-lakitu-${BUILD_ID}"

if [ ! -e "${SOURCES_DIR}/.installed" ];then
echo "Installing kernel headers for for COS build ${BUILD_ID}"
fetch_cos_linux_sources
generate_headers
mv ${BUILD_DIR} ${TARGET_DIR}
echo "Installing kernel headers for COS build ${BUILD_ID}"
time fetch_cos_linux_sources
time generate_headers
time mv ${BUILD_DIR} ${TARGET_DIR}
touch "${SOURCES_DIR}/.installed"
fi
fi
}

install_generic_linux_headers()
{
BUILD_DIR="/linux-generic-$(uname -r)"
SOURCES_DIR="${TARGET_DIR}/linux-generic-$(uname -r)"

if [ ! -e "${SOURCES_DIR}/.installed" ];then
echo "Installing kernel headers for generic kernel"
time fetch_generic_linux_sources
time generate_headers
time mv ${BUILD_DIR} ${TARGET_DIR}
touch "${SOURCES_DIR}/.installed"
fi
}

install_headers()
{
distro=$(grep ^NAME ${OS_RELEASE_FILE} | cut -d = -f 2)
Expand All @@ -50,7 +77,10 @@ install_headers()
HEADERS_TARGET=${SOURCES_DIR}
;;
*)
echo "WARNING: ${distro} is not a supported distro, cannot install headers, ensure they are installed to /lib/modules"
echo "WARNING: Cannot find distro-specific headers for ${distro}. Fetching generic headers."
install_generic_linux_headers
HEADERS_TARGET=${SOURCES_DIR}
;;
esac
}

Expand Down

0 comments on commit 95d5374

Please sign in to comment.