1
0
mirror of https://github.com/rancher/os-kernel.git synced 2025-04-29 02:53:19 +00:00
os-kernel/scripts/build-common

115 lines
2.0 KiB
Plaintext
Raw Normal View History

2015-08-05 16:53:05 +00:00
#!/bin/bash
set -e
: ${KERNEL_URL:="https://github.com/rancher/linux/archive/Ubuntu-3.19.0-27.29.tar.gz"}
: ${KERNEL_SHA1:="84b9bc53bbb4dd465b97ea54a71a9805e27ae4f2"}
2015-08-05 16:53:05 +00:00
: ${ARTIFACTS:=$(pwd)/assets}
: ${BUILD:=$(pwd)/build}
: ${CONFIG:=$(pwd)/config}
: ${DIST:=$(pwd)/dist}
DOCKER_FILE=${CONFIG}/.dockerfile
mkdir -p ${BUILD} ${DIST}
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
}