1
0
mirror of https://github.com/rancher/os-kernel.git synced 2025-06-23 04:07:04 +00:00
os-kernel/scripts/build-common
2015-10-01 23:33:20 +05:00

152 lines
3.0 KiB
Bash

#!/bin/bash
set -e
: ${KERNEL_URL:="https://github.com/rancher/linux/archive/Ubuntu-4.2.0-10.12.tar.gz"}
: ${KERNEL_SHA1:="0711163d97a787d33de7f0cf6c1a6a0934aabd75"}
: ${ARTIFACTS:=$(pwd)/assets}
: ${BUILD:=/usr/src}
: ${CONFIG:=$(pwd)/config}
: ${DIST:=$(pwd)/dist}
DOCKER_FILE=${CONFIG}/.dockerfile
write_base()
{
if [ "${BASE_WRITTEN}" = "true" ]; then
return
fi
mkdir -p $(dirname ${DOCKER_FILE})
cat > ${DOCKER_FILE} << EOF
FROM ${DOCKER_BASE:=ubuntu:14.04.3}
ENV TERM xterm
WORKDIR /source
EOF
BASE_WRITTEN=true
}
run()
{
local content
while [ $# -gt 1 ]; do
case $1 in
--assets)
shift 1
if [ -e "$1" ]; then
content="$content\nCOPY $1 /source/$1"
else
content="$content\nCOPY $1 /source/"
fi
;;
esac
shift 1
done
write_base
if [ -n "$content" ]; then
echo -e "$content" >> ${DOCKER_FILE}
fi
if [ -n "$1" ]; then
echo -e "\nCOPY $1 /source/$1" >> ${DOCKER_FILE}
echo -e "RUN /source/$1" >> ${DOCKER_FILE}
fi
if [ "$RUN_EXEC" = "true" ]; then
$1
fi
}
finish()
{
if [ "$RUN_EXEC" = true ]; then
return 0
fi
local cmd="docker build -t ${DOCKER_IMAGE} -f ${DOCKER_FILE} ."
echo Running $cmd
echo Pwd $(pwd)
cat ${DOCKER_FILE}
$cmd
}
reset_docker_build()
{
BASE_WRITTEN=false
}
check()
{
local hash=$1
local file=$2
if [ ! -e "$file" ]; then
return 1
fi
CURRENT=$(sha1sum $file | awk '{print $1}')
[ "$hash" = "$CURRENT" ]
}
download()
{
mkdir -p ${ARTIFACTS}
local url=$2
local file=${ARTIFACTS}/$(basename $2)
local hash=$1
if ! check $hash $file; then
curl -sL $url > $file
fi
if ! check $hash $file; then
echo "ERROR: $file does not match checksum $hash, got $CURRENT" 1>&2
return 1
fi
}
list_build_files() {
find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl
find $(find ./arch/${SRCARCH} -name include -o -name scripts -type d) ./include ./scripts -type f
find ./arch/${SRCARCH} -name module.lds -o -name Kbuild.platforms -o -name Platform
find . -name Module.symvers -type f
}
create_firmware_tar() {
local list=$1
local temp=firmware-temp
rm -rf $temp
mkdir -p $temp
tar xf linux*.tar -C $temp
if [ ! -e linux-firmware ]; then
git clone git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git
fi
(
cd linux-firmware
git rev-parse HEAD > .git-commit
)
echo .git-commit > files
for i in $(<$list); do
if [ ! -e $temp/lib/firmware/$i ]; then
if [ -e linux-firmware/$i ]; then
echo Found $i
echo $i >> files
else
echo Not found $i
fi
fi
done
tar cf firmware.tar --transform 's,^,lib/firmware/,' -C linux-firmware $(<files)
}