1
0
mirror of https://github.com/rancher/os-kernel.git synced 2025-06-22 19:57:03 +00:00
os-kernel/scripts/build-common

120 lines
2.3 KiB
Plaintext
Raw Normal View History

2015-08-05 16:53:05 +00:00
#!/bin/bash
set -e
2015-09-21 18:49:08 +00:00
: ${KERNEL_URL:="https://github.com/rancher/linux/archive/Ubuntu-4.2.0-10.12.tar.gz"}
: ${KERNEL_SHA1:="0711163d97a787d33de7f0cf6c1a6a0934aabd75"}
2015-08-05 16:53:05 +00:00
: ${ARTIFACTS:=$(pwd)/assets}
2015-09-17 07:44:12 +00:00
: ${BUILD:=/usr/src}
2015-08-05 16:53:05 +00:00
: ${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.2}
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
}
2015-09-17 07:44:12 +00:00
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
}